Skip to content

Commit fdc03f5

Browse files
committed
addressed feedback requests
1 parent b9616c9 commit fdc03f5

File tree

5 files changed

+47
-44
lines changed

5 files changed

+47
-44
lines changed

internal/boxcli/run.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,18 @@ func runScriptCmd(cmd *cobra.Command, args []string, flags runCmdFlags) error {
123123
return redact.Errorf("error reading devbox.json: %w", err)
124124
}
125125

126-
onStaleState := func() {
127-
ux.FHidableWarning(
128-
ctx,
129-
cmd.ErrOrStderr(),
130-
devbox.StateOutOfDateMessage,
131-
"with --recompute=true",
132-
)
133-
}
134-
135126
envOpts := devopt.EnvOptions{
136-
Hooks: devopt.EnvLifecycleHooks{
137-
OnStaleStateWithSkipRecompute: onStaleState,
127+
Hooks: devopt.LifecycleHooks{
128+
OnStaleState: func() {
129+
if !flags.recomputeEnv {
130+
ux.FHidableWarning(
131+
ctx,
132+
cmd.ErrOrStderr(),
133+
devbox.StateOutOfDateMessage,
134+
"with --recompute=true",
135+
)
136+
}
137+
},
138138
},
139139
OmitNixEnv: flags.omitNixEnv,
140140
Pure: flags.pure,

internal/boxcli/shell.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@ func runShellCmd(cmd *cobra.Command, flags shellCmdFlags) error {
9696
return shellInceptionErrorMsg("devbox shell")
9797
}
9898

99-
onStaleState := func() {
100-
ux.FHidableWarning(
101-
ctx,
102-
cmd.ErrOrStderr(),
103-
devbox.StateOutOfDateMessage,
104-
"with --recompute=true",
105-
)
106-
}
107-
10899
return box.Shell(ctx, devopt.EnvOptions{
109-
Hooks: devopt.EnvLifecycleHooks{
110-
OnStaleStateWithSkipRecompute: onStaleState,
100+
Hooks: devopt.LifecycleHooks{
101+
OnStaleState: func() {
102+
if !flags.recomputeEnv {
103+
ux.FHidableWarning(
104+
ctx,
105+
cmd.ErrOrStderr(),
106+
devbox.StateOutOfDateMessage,
107+
"with --recompute=true",
108+
)
109+
}
110+
},
111111
},
112112
OmitNixEnv: flags.omitNixEnv,
113113
Pure: flags.pure,

internal/boxcli/shellenv.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ func shellEnvFunc(
115115
}
116116
}
117117

118-
onStaleState := func() {
119-
ux.FHidableWarning(
120-
ctx,
121-
cmd.ErrOrStderr(),
122-
devbox.StateOutOfDateMessage,
123-
box.RefreshAliasOrCommand(),
124-
)
125-
}
126-
127118
envStr, err := box.EnvExports(ctx, devopt.EnvExportsOpts{
128119
EnvOptions: devopt.EnvOptions{
129-
Hooks: devopt.EnvLifecycleHooks{
130-
OnStaleStateWithSkipRecompute: onStaleState,
120+
Hooks: devopt.LifecycleHooks{
121+
OnStaleState: func() {
122+
if !flags.recomputeEnv {
123+
ux.FHidableWarning(
124+
ctx,
125+
cmd.ErrOrStderr(),
126+
devbox.StateOutOfDateMessage,
127+
box.RefreshAliasOrCommand(),
128+
)
129+
}
130+
},
131131
},
132132
OmitNixEnv: flags.omitNixEnv,
133133
PreservePathStack: flags.preservePathStack,

internal/devbox/devbox.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -804,14 +804,17 @@ func (d *Devbox) ensureStateIsUpToDateAndComputeEnv(
804804
) (map[string]string, error) {
805805
defer debug.FunctionTimer().End()
806806

807-
if envOpts.SkipRecompute {
808-
upToDate, _ := d.lockfile.IsUpToDateAndInstalled(isFishShell())
809-
if !upToDate {
810-
if envOpts.Hooks.OnStaleStateWithSkipRecompute != nil {
811-
envOpts.Hooks.OnStaleStateWithSkipRecompute()
812-
}
807+
upToDate, err := d.lockfile.IsUpToDateAndInstalled(isFishShell())
808+
if err != nil {
809+
return nil, err
810+
}
811+
if !upToDate {
812+
if envOpts.Hooks.OnStaleState != nil {
813+
envOpts.Hooks.OnStaleState()
813814
}
814-
} else {
815+
}
816+
817+
if !envOpts.SkipRecompute {
815818
// When ensureStateIsUpToDate is called with ensure=true, it always
816819
// returns early if the lockfile is up to date. So we don't need to check here
817820
if err := d.ensureStateIsUpToDate(ctx, ensure); isConnectionError(err) {

internal/devbox/devopt/devboxopts.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ type EnvExportsOpts struct {
7272
// like `shellenv`, `shell` and `run`.
7373
// - The struct is designed for the "common case" to be zero-initialized as `EnvOptions{}`.
7474
type EnvOptions struct {
75-
Hooks EnvLifecycleHooks
75+
Hooks LifecycleHooks
7676
OmitNixEnv bool
7777
PreservePathStack bool
7878
Pure bool
7979
SkipRecompute bool
8080
}
8181

82-
type EnvLifecycleHooks struct {
83-
// OnStaleStateWithSkipRecompute is called when the Devbox state is out of date, AND it is not being recomputed.
84-
OnStaleStateWithSkipRecompute func()
82+
type LifecycleHooks struct {
83+
// OnStaleState is called when the Devbox state is out of date, AND it is not being recomputed.
84+
OnStaleState func()
8585
}

0 commit comments

Comments
 (0)