@@ -157,13 +157,14 @@ func direnvCmd() *cobra.Command {
157157 // --envrc-dir allows users to specify a directory where the .envrc file should be generated
158158 // separately from the devbox config directory. Without this flag, the .envrc file
159159 // will be generated in the same directory as the devbox config file (i.e., either the current
160- // directory or the directory specified by --config). This is useful for users who want to keep
161- // their .envrc and devbox config files in different locations.
160+ // directory or the directory specified by --config). This flag is useful for users who want to
161+ // keep their .envrc and devbox config files in different locations.
162162 command .Flags ().StringVar (
163163 & flags .envrcDir , "envrc-dir" , "" ,
164- "path to directory where the .envrc file should be generated. " +
165- "If not specified, the .envrc file will be generated in " +
166- "the current working directory." )
164+ "path to directory where the .envrc file should be generated.\n " +
165+ "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." )
167168
168169 flags .config .register (command )
169170 return command
@@ -288,6 +289,11 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
288289 "Use --envrc-dir to specify the directory where the .envrc file should be generated." )
289290 }
290291
292+ if flags .printEnvrcContent {
293+ return devbox .PrintEnvrcContent (
294+ cmd .OutOrStdout (), devopt .EnvFlags (flags .envFlag ), flags .config .path )
295+ }
296+
291297 // Determine the directories for .envrc and config
292298 configDir , envrcDir , err := determineDirenvDirs (flags .config .path , flags .envrcDir )
293299 if err != nil {
@@ -300,10 +306,6 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
300306 EnvFlags : devopt .EnvFlags (flags .envFlag ),
301307 }
302308
303- if flags .printEnvrcContent {
304- return devbox .PrintEnvrcContent (cmd .OutOrStdout (), generateOpts )
305- }
306-
307309 box , err := devbox .Open (& devopt.Opts {
308310 Dir : filepath .Join (envrcDir , configDir ),
309311 Environment : flags .config .environment ,
@@ -317,7 +319,7 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
317319 cmd .Context (), flags .force , generateOpts )
318320}
319321
320- // Returns cononical paths for configDir and envrcDir. Both locations are relative to the current
322+ // Returns canonical paths for configDir and envrcDir. Both locations are relative to the current
321323// working directory when provided to this function. However, since the config file will ultimately
322324// be relative to the .envrc file, we need to determine the relative path from envrcDir to configDir.
323325func determineDirenvDirs (configDir , envrcDir string ) (string , string , error ) {
0 commit comments