Skip to content

Commit

Permalink
chore: give user upgrade command when checking for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Jan 10, 2024
1 parent e2ff5dc commit 2f25804
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/cli/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"context"
"fmt"
"os"
"strings"

"github.com/futurice/jalapeno/internal/cli/option"
Expand Down Expand Up @@ -105,27 +106,37 @@ func runCheck(cmd *cobra.Command, opts checkOptions) error {

cmd.Println("Checking for new versions...")

updatesAvailable, errorsFound := false, false
errorsFound := false
upgradeCommands := make([]string, 0, len(sauces))
for _, sauce := range sauces {
versions, err := recipeutil.CheckForUpdates(sauce, opts.OCIRepository)
if err != nil {
errorsFound = true
cmd.Printf("%s: can not check for updates: %s\n", sauce.Recipe.Name, err)

} else if len(versions) > 0 {
updatesAvailable = true
cmd.Printf("%s: new versions found: %s\n", sauce.Recipe.Name, strings.Join(versions, ", "))
upgradeCommands = append(upgradeCommands,
fmt.Sprintf("%s upgrade %s:%s", os.Args[0], sauce.CheckFrom, versions[len(versions)-1]),
)

} else {
cmd.Printf("%s: no new versions found\n", sauce.Recipe.Name)
}
}

if len(upgradeCommands) > 0 {
cmd.Println("To upgrade recipes to the latest version run:")
for _, cmdMsg := range upgradeCommands {
cmd.Printf(" %s\n", cmdMsg)
}
}

var exitCode int
switch {
case errorsFound:
exitCode = ExitCodeError
case updatesAvailable && opts.UseDetailedExitCode:
case len(upgradeCommands) > 0 && opts.UseDetailedExitCode:
exitCode = ExitCodeUpdatesAvailable
default:
exitCode = ExitCodeOK
Expand Down
2 changes: 2 additions & 0 deletions test/check-recipes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Feature: Check for new recipe versions
And I push the recipe "foo" to the local OCI repository
And I check new versions for recipe "foo"
Then CLI produced an output "new versions found: v0.0.2"
Then CLI produced an output "To upgrade recipes to the latest version run:\n (.*) upgrade oci://localhost:\d+/foo:v0.0.2\n"

Scenario: Find multiple newer version for a recipe
Given a project directory
Expand All @@ -30,6 +31,7 @@ Feature: Check for new recipe versions
And I push the recipe "foo" to the local OCI repository
Then I check new versions for recipe "foo"
Then CLI produced an output "new versions found: v0.0.2, v0.0.3"
Then CLI produced an output "To upgrade recipes to the latest version run:\n (.*) upgrade oci://localhost:\d+/foo:v0.0.3\n"

Scenario: Find newer version for multiple recipes
Given a project directory
Expand Down

0 comments on commit 2f25804

Please sign in to comment.