Skip to content

Commit

Permalink
fix: do not check version for additional commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Jun 11, 2024
1 parent a76a319 commit 359dfab
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ const (
)

func IsManagementAPI(cmd *cobra.Command) bool {
return belongsToGroup(cmd, groupManagementAPI)
}

func belongsToGroup(cmd *cobra.Command, groupId ...string) bool {
if len(groupId) == 0 {
groupId = []string{
groupQuickStart,
groupLocalDev,
groupManagementAPI,
}
}
for cmd != cmd.Root() {
if cmd.GroupID == groupManagementAPI {
if utils.SliceContains(groupId, cmd.GroupID) {
return true
}
// Find the last assigned group
Expand Down Expand Up @@ -134,16 +145,17 @@ var (

func Execute() {
defer recoverAndExit()
if err := rootCmd.Execute(); err != nil {
if c, err := rootCmd.ExecuteC(); err != nil {
panic(err)
}
// Check upgrade last because --version flag is initialised after execute
version, err := checkUpgrade(rootCmd.Context(), afero.NewOsFs())
if err != nil {
fmt.Fprintln(utils.GetDebugLogger(), err)
}
if semver.Compare(version, "v"+utils.Version) > 0 {
fmt.Fprintln(os.Stderr, suggestUpgrade(version))
} else if belongsToGroup(c) {
// Check upgrade last because --version flag is initialised after execute
version, err := checkUpgrade(c.Context(), afero.NewOsFs())
if err != nil {
fmt.Fprintln(utils.GetDebugLogger(), err)
}
if semver.Compare(version, "v"+utils.Version) > 0 {
fmt.Fprintln(os.Stderr, suggestUpgrade(version))
}
}
if len(utils.CmdSuggestion) > 0 {
fmt.Fprintln(os.Stderr, utils.CmdSuggestion)
Expand Down

0 comments on commit 359dfab

Please sign in to comment.