Skip to content

Commit

Permalink
nsc: do rely on version cache to notify new version
Browse files Browse the repository at this point in the history
Part of: NSL-2176
  • Loading branch information
gmichelo committed Nov 17, 2023
1 parent fc152af commit 961d93d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/nsc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
// Consider adding auto updates if we frequently change nsc.
fncobra.DoMain(fncobra.MainOpts{
Name: "nsc",
AutoUpdate: true,
NotifyOnNewVersion: true,
ConsoleInhibitReport: true,
FormatErr: formatErr,
ConsoleRenderer: renderLine,
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/fncobra/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"namespacelabs.dev/foundation/internal/cli/nsboot"
"namespacelabs.dev/foundation/internal/cli/version"
"namespacelabs.dev/foundation/internal/cli/versioncheck"
"namespacelabs.dev/foundation/internal/compute"
Expand Down Expand Up @@ -53,7 +52,7 @@ func DeferCheckVersion(ctx context.Context, command string) {
return nil
}

if nsboot.NewerVersion(command, status) {
if status.NewVersion {
compute.On(ctx).Cleanup(tasks.Action(command+".check-updated.notify").LogLevel(1), func(ctx context.Context) error {
fmt.Fprintf(console.Stdout(ctx), "\n\n A new version of %s is available (%s).\n\n", command, status.Version)
return nil
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/fncobra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var (
type MainOpts struct {
Name string
AutoUpdate bool
NotifyOnNewVersion bool
FormatErr FormatErrorFunc
ConsoleInhibitReport bool
ConsoleRenderer consolesink.RendererFunc
Expand Down Expand Up @@ -96,8 +97,8 @@ func doMain(opts MainOpts) (colors.Style, error) {
rootCtx, style, flushLogs := setupContext(context.Background(), opts.ConsoleInhibitReport, opts.ConsoleRenderer)

// Before moving forward, we check if there's a more up-to-date ns we should fork to.
if opts.AutoUpdate {
maybeRunLatest(rootCtx, style, flushLogs, opts.Name, opts.Name == "ns")
if opts.AutoUpdate && opts.Name == "ns" { // Applies only to ns, not nsc and docker-credential-helper
maybeRunLatest(rootCtx, style, flushLogs, opts.Name, true)
}

var cleanupTracer func()
Expand All @@ -123,7 +124,7 @@ func doMain(opts MainOpts) (colors.Style, error) {
ctx := cmd.Context()

// This is a bit of an hack. But don't run version checks when doing an update.
if opts.AutoUpdate && !slices.Contains(cmd.Aliases, "update-ns") {
if opts.NotifyOnNewVersion && !slices.Contains(cmd.Aliases, "update-ns") {
DeferCheckVersion(ctx, opts.Name)
}

Expand Down

0 comments on commit 961d93d

Please sign in to comment.