@@ -6,7 +6,6 @@ package boxcli
66import (
77 "cmp"
88 "fmt"
9- "path/filepath"
109 "regexp"
1110
1211 "github.com/pkg/errors"
@@ -163,8 +162,7 @@ func direnvCmd() *cobra.Command {
163162 & flags .envrcDir , "envrc-dir" , "" ,
164163 "path to directory where the .envrc file should be generated.\n " +
165164 "If not specified, the .envrc file will be generated in the same directory as\n " +
166- "the devbox.json config file. Also, when specified along with --config, the config file\n " +
167- "location will be relative to the .envrc file location." )
165+ "the devbox.json." )
168166
169167 flags .config .register (command )
170168 return command
@@ -294,59 +292,21 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
294292 cmd .OutOrStdout (), devopt .EnvFlags (flags .envFlag ), flags .config .path )
295293 }
296294
297- // Determine the directories for .envrc and config
298- configDir , envrcDir , err := determineDirenvDirs (flags .config .path , flags .envrcDir )
299- if err != nil {
300- return errors .WithStack (err )
301- }
302-
303- generateOpts := devopt.EnvrcOpts {
304- EnvrcDir : envrcDir ,
305- ConfigDir : configDir ,
306- EnvFlags : devopt .EnvFlags (flags .envFlag ),
307- }
308-
309295 box , err := devbox .Open (& devopt.Opts {
310- Dir : filepath . Join ( envrcDir , configDir ) ,
296+ Dir : flags . config . path ,
311297 Environment : flags .config .environment ,
312298 Stderr : cmd .ErrOrStderr (),
313299 })
314300 if err != nil {
315301 return errors .WithStack (err )
316302 }
317303
318- return box .GenerateEnvrcFile (
319- cmd .Context (), flags .force , generateOpts )
320- }
321-
322- // Returns canonical paths for configDir and envrcDir. Both locations are relative to the current
323- // working directory when provided to this function. However, since the config file will ultimately
324- // be relative to the .envrc file, we need to determine the relative path from envrcDir to configDir.
325- func determineDirenvDirs (configDir , envrcDir string ) (string , string , error ) {
326- // If envrcDir is not specified, we will use the configDir as the location for .envrc. This is
327- // for backward compatibility (prior to the --envrc-dir flag being introduced).
328- if envrcDir == "" {
329- return "" , configDir , nil
330- }
331-
332- // If no configDir is specified, it will be assumed to be in the same directory as the .envrc file
333- // which means we can just return an empty configDir.
334- if configDir == "" {
335- return "" , envrcDir , nil
336- }
337-
338- relativeConfigDir , err := filepath .Rel (envrcDir , configDir )
339- if err != nil {
340- return "" , "" , errors .Wrapf (err , "failed to determine relative path from %s to %s" , envrcDir , configDir )
341- }
342-
343- // If the relative path is ".", it means configDir is the same as envrcDir. Leaving it as "."
344- // will result in the .envrc containing "--config .", which is fine, but unnecessary and also
345- // a change from the previous behavior. So we will return an empty string for relativeConfigDir
346- // which will result in the .envrc file not containing the "--config" flag at all.
347- if relativeConfigDir == "." {
348- relativeConfigDir = ""
304+ generateEnvrcOpts := devopt.EnvrcOpts {
305+ EnvFlags : devopt .EnvFlags (flags .envFlag ),
306+ Force : flags .force ,
307+ EnvrcDir : flags .envrcDir ,
308+ ConfigDir : flags .config .path ,
349309 }
350310
351- return relativeConfigDir , envrcDir , nil
311+ return box . GenerateEnvrcFile ( cmd . Context (), generateEnvrcOpts )
352312}
0 commit comments