Skip to content
Merged
21 changes: 21 additions & 0 deletions cmd/output/interactive_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ func (p *interactivePrinter) Print(v any) error {
w(" git commit: %s\n", t.GitCommit)
w(" build date: %s\n", t.BuildDate)
w(" go: %s %s %s\n", t.GoVersion, t.Compiler, t.Platform)
case UpdateResult:
switch t.Status {
case UpdateStatusUpToDate:
w("%s\n", styleGreen.Render("cloudctl is up to date ("+t.CurrentVersion+")."))
case UpdateStatusAvailable:
w("%s %s %s\n",
styleYellow.Render("A new version is available:"),
styleBold.Render(t.LatestVersion),
styleFaint.Render("(current: "+t.CurrentVersion+")"),
)
w("Run %s to install it.\n", styleBold.Render("cloudctl update"))
case UpdateStatusUpdated:
w("%s %s %s %s\n",
styleGreen.Render("cloudctl updated:"),
t.CurrentVersion,
styleGreen.Render("->"),
styleBold.Render(t.LatestVersion),
)
default:
w("cloudctl update status: %s (current: %s, latest: %s)\n", t.Status, t.CurrentVersion, t.LatestVersion)
}
default:
w("%v\n", v)
}
Expand Down
13 changes: 13 additions & 0 deletions cmd/output/plain_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ func (p *plainPrinter) Print(v any) error {
w(" build date: %s\n", t.BuildDate)
w(" go: %s %s %s\n", t.GoVersion, t.Compiler, t.Platform)

case UpdateResult:
switch t.Status {
case UpdateStatusUpToDate:
w("cloudctl is up to date (%s).\n", t.CurrentVersion)
case UpdateStatusAvailable:
w("A new version is available: %s (current: %s)\n", t.LatestVersion, t.CurrentVersion)
w("Run `cloudctl update` to install it.\n")
case UpdateStatusUpdated:
w("cloudctl updated: %s -> %s\n", t.CurrentVersion, t.LatestVersion)
default:
w("cloudctl update status: %s (current: %s, latest: %s)\n", t.Status, t.CurrentVersion, t.LatestVersion)
}
Comment thread
onuryilmaz marked this conversation as resolved.

default:
w("%v\n", v)
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/output/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ type ErrorResult struct {
Error string `json:"error" yaml:"error"`
}

// UpdateStatus represents the outcome of an update check or install.
type UpdateStatus string

const (
UpdateStatusUpToDate UpdateStatus = "up-to-date"
UpdateStatusAvailable UpdateStatus = "available"
UpdateStatusUpdated UpdateStatus = "updated"
)

// UpdateResult is the output of the update command.
type UpdateResult struct {
CurrentVersion string `json:"currentVersion" yaml:"currentVersion"`
LatestVersion string `json:"latestVersion" yaml:"latestVersion"`
Status UpdateStatus `json:"status" yaml:"status"`
}

// AccessDiff describes one cluster access (context) that is changing.
type AccessDiff struct {
Name string `json:"name" yaml:"name"`
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Commands:
sync Fetch ClusterKubeconfigs from Greenhouse and merge them locally
cluster-version Query the Kubernetes server version of a kubeconfig context
version Print cloudctl build information
update Check for and install the latest cloudctl release

Global flags available on every command:
-o, --output text|json|yaml Output format (default: text)
Expand Down Expand Up @@ -86,6 +87,7 @@ func init() {
rootCmd.AddCommand(syncCmd)
rootCmd.AddCommand(clusterVersionCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(updateCmd)
}

// configWithContext builds a rest.Config for the specified context name from the given kubeconfig path.
Expand Down
Loading
Loading