Returns the relative path from sourceDir to configDir, or an error if it cannot be determined.
(sourceDir, configDir string)
| 177 | |
| 178 | // Returns the relative path from sourceDir to configDir, or an error if it cannot be determined. |
| 179 | func getRelativePathToConfig(sourceDir, configDir string) (string, error) { |
| 180 | absConfigDir, err := filepath.Abs(configDir) |
| 181 | if err != nil { |
| 182 | return "", fmt.Errorf("failed to get absolute path for config dir: %w", err) |
| 183 | } |
| 184 | |
| 185 | absSourceDir, err := filepath.Abs(sourceDir) |
| 186 | if err != nil { |
| 187 | return "", fmt.Errorf("failed to get absolute path for source dir: %w", err) |
| 188 | } |
| 189 | |
| 190 | // We don't want the path if the config dir is a parent of the envrc dir. This way |
| 191 | // the config will be found when it recursively searches for it through the parent tree. |
| 192 | if strings.HasPrefix(absSourceDir, absConfigDir) { |
| 193 | return "", nil |
| 194 | } |
| 195 | |
| 196 | relPath, err := filepath.Rel(absSourceDir, absConfigDir) |
| 197 | if err != nil { |
| 198 | // If a relative path cannot be computed, return the absolute path of configDir |
| 199 | return absConfigDir, err |
| 200 | } |
| 201 | |
| 202 | return relPath, nil |
| 203 | } |
| 204 | |
| 205 | func (g *Options) getDevcontainerContent() *devcontainerObject { |
| 206 | // object that gets written in devcontainer.json |