Skip to content

Commit bf7c274

Browse files
authored
[direnv] ensure shellenv --init-hooks also runs plugin hooks (#914)
## Summary We want the `--init-hooks` flag to run both shell init hooks and plugin hooks of packages ## How was it tested? Need to check with @Lagoja for a good repro case. Did a sanity test that the local `devbox` repo works fine. re-generated the `examples/cloud_development/temporal` .envrc. Upon entering the directory it sourced the python virtualenv without errors.
1 parent f9472a6 commit bf7c274

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

devbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Devbox interface {
3030
GenerateEnvrc(force bool, source string) error
3131
Info(pkg string, markdown bool) error
3232
ListScripts() []string
33-
PrintEnv(ctx context.Context, useCache bool) (string, error)
33+
PrintEnv(ctx context.Context, useCache bool, includeHooks bool) (string, error)
3434
PrintGlobalList() error
3535
PullGlobal(path string) error
3636
// Remove removes Nix packages from the config so that it no longer exists in

internal/boxcli/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func runShellCmd(cmd *cobra.Command, flags shellCmdFlags) error {
4848
}
4949

5050
if flags.PrintEnv {
51-
script, err := box.PrintEnv(cmd.Context(), false /*useCachedPrintDevEnv*/)
51+
script, err := box.PrintEnv(cmd.Context(), false /*useCachedPrintDevEnv*/, true /*includeHooks*/)
5252
if err != nil {
5353
return err
5454
}

internal/boxcli/shellenv.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,10 @@ func shellEnvFunc(cmd *cobra.Command, flags shellEnvCmdFlags) (string, error) {
5454
return "", err
5555
}
5656

57-
envStr, err := box.PrintEnv(cmd.Context(), flags.useCachedPrintDevEnv)
57+
envStr, err := box.PrintEnv(cmd.Context(), flags.useCachedPrintDevEnv, flags.runInitHook)
5858
if err != nil {
5959
return "", err
6060
}
6161

62-
if flags.runInitHook {
63-
initHookStr := box.Config().Shell.InitHook.String()
64-
return fmt.Sprintf("%s\n%s", envStr, initHookStr), nil
65-
}
66-
6762
return envStr, nil
6863
}

internal/impl/devbox.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (d *Devbox) ListScripts() []string {
259259
return keys
260260
}
261261

262-
func (d *Devbox) PrintEnv(ctx context.Context, useCache bool) (string, error) {
262+
func (d *Devbox) PrintEnv(ctx context.Context, useCache bool, includeHooks bool) (string, error) {
263263
ctx, task := trace.NewTask(ctx, "devboxPrintEnv")
264264
defer task.End()
265265

@@ -281,7 +281,14 @@ func (d *Devbox) PrintEnv(ctx context.Context, useCache bool) (string, error) {
281281
return "", err
282282
}
283283

284-
return exportify(envs), nil
284+
envStr := exportify(envs)
285+
286+
if includeHooks {
287+
hooksStr := ". " + d.scriptPath(hooksFilename)
288+
envStr = fmt.Sprintf("%s\n%s", envStr, hooksStr)
289+
}
290+
291+
return envStr, nil
285292
}
286293

287294
func (d *Devbox) ShellEnvHash(ctx context.Context) (string, error) {

0 commit comments

Comments
 (0)