Skip to content

[ux] Improve refresh messaging #2173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/boxcli/shellenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"
"go.jetpack.io/devbox/internal/devbox"
"go.jetpack.io/devbox/internal/devbox/devopt"
"go.jetpack.io/devbox/internal/ux"
)

type shellEnvCmdFlags struct {
Expand Down Expand Up @@ -94,6 +95,10 @@ func shellEnvFunc(
if err != nil {
return "", err
}
ctx := cmd.Context()
if flags.recomputeEnv {
ctx = ux.HideMessage(ctx, devbox.StateOutOfDateMessage)
}
box, err := devbox.Open(&devopt.Opts{
Dir: flags.config.path,
Environment: flags.config.environment,
Expand All @@ -105,12 +110,12 @@ func shellEnvFunc(
}

if flags.install {
if err := box.Install(cmd.Context()); err != nil {
if err := box.Install(ctx); err != nil {
return "", err
}
}

envStr, err := box.EnvExports(cmd.Context(), devopt.EnvExportsOpts{
envStr, err := box.EnvExports(ctx, devopt.EnvExportsOpts{
DontRecomputeEnvironment: !flags.recomputeEnv,
EnvOptions: devopt.EnvOptions{
OmitNixEnv: flags.omitNixEnv,
Expand Down
11 changes: 4 additions & 7 deletions internal/devbox/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,11 @@ func (d *Devbox) EnvExports(ctx context.Context, opts devopt.EnvExportsOpts) (st
if opts.DontRecomputeEnvironment {
upToDate, _ := d.lockfile.IsUpToDateAndInstalled(isFishShell())
if !upToDate {
cmd := `eval "$(devbox global shellenv --recompute)"`
if isFishShell() {
cmd = `devbox global shellenv --recompute | source`
}
ux.Finfo(
ux.FHidableWarning(
ctx,
d.stderr,
"Your devbox environment may be out of date. Please run \n\n%s\n\n",
cmd,
StateOutOfDateMessage,
d.refreshAliasOrCommand(),
)
}

Expand Down
7 changes: 5 additions & 2 deletions internal/devbox/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"go.jetpack.io/devbox/internal/ux"
)

const StateOutOfDateMessage = "Your devbox environment may be out of date. Run %s to update it.\n"

// packages.go has functions for adding, removing and getting info about nix
// packages

Expand Down Expand Up @@ -285,9 +287,10 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
// be out of date after the user installs something. If have direnv active
// it should reload automatically so we don't need to refresh.
if d.IsEnvEnabled() && !upToDate && !d.IsDirenvActive() {
ux.Fwarning(
ux.FHidableWarning(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about FHidableWarning

ctx,
d.stderr,
"Your shell environment may be out of date. Run `%s` to update it.\n",
StateOutOfDateMessage,
d.refreshAliasOrCommand(),
)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/devbox/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (d *Devbox) isGlobal() bool {
// great, we just print out the entire command.
func (d *Devbox) refreshAliasOrCommand() string {
if !d.isRefreshAliasSet() {
return d.refreshCmd()
// even if alias is not set, it might still be set by the end of this process
return fmt.Sprintf("`%s` or `%s`", d.refreshAliasName(), d.refreshCmd())
}
return d.refreshAliasName()
}
Expand Down