@@ -157,13 +157,14 @@ func direnvCmd() *cobra.Command {
157
157
// --envrc-dir allows users to specify a directory where the .envrc file should be generated
158
158
// separately from the devbox config directory. Without this flag, the .envrc file
159
159
// 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.
162
162
command .Flags ().StringVar (
163
163
& 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." )
167
168
168
169
flags .config .register (command )
169
170
return command
@@ -288,6 +289,11 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
288
289
"Use --envrc-dir to specify the directory where the .envrc file should be generated." )
289
290
}
290
291
292
+ if flags .printEnvrcContent {
293
+ return devbox .PrintEnvrcContent (
294
+ cmd .OutOrStdout (), devopt .EnvFlags (flags .envFlag ), flags .config .path )
295
+ }
296
+
291
297
// Determine the directories for .envrc and config
292
298
configDir , envrcDir , err := determineDirenvDirs (flags .config .path , flags .envrcDir )
293
299
if err != nil {
@@ -300,10 +306,6 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
300
306
EnvFlags : devopt .EnvFlags (flags .envFlag ),
301
307
}
302
308
303
- if flags .printEnvrcContent {
304
- return devbox .PrintEnvrcContent (cmd .OutOrStdout (), generateOpts )
305
- }
306
-
307
309
box , err := devbox .Open (& devopt.Opts {
308
310
Dir : filepath .Join (envrcDir , configDir ),
309
311
Environment : flags .config .environment ,
@@ -317,7 +319,7 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
317
319
cmd .Context (), flags .force , generateOpts )
318
320
}
319
321
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
321
323
// working directory when provided to this function. However, since the config file will ultimately
322
324
// be relative to the .envrc file, we need to determine the relative path from envrcDir to configDir.
323
325
func determineDirenvDirs (configDir , envrcDir string ) (string , string , error ) {
0 commit comments