Skip to content

Commit

Permalink
fix(core): change command signature to fix sort of same command (#2705)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Dec 27, 2022
1 parent fa9a24b commit 63d043a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-all-usage-account-usage#01.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This API allows you to manage projects.
Account API

USAGE:
scw account <command>
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-all-usage-account-usage.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This API allows you to manage projects.
Account API

USAGE:
scw account <command>
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw/testdata/test-main-usage-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ USAGE:
scw <command>

AVAILABLE COMMANDS:
account User related data
account Account API
apple-silicon Apple silicon API
autocomplete Autocomplete related commands
baremetal Elastic metal API
Expand Down
7 changes: 6 additions & 1 deletion internal/core/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (c *Commands) GetSortedCommand() []*Command {
copy(commands, c.commands)

sort.Slice(commands, func(i, j int) bool {
return fmt.Sprintf("%s %s %s", commands[i].Namespace, commands[i].Resource, commands[i].Verb) < fmt.Sprintf("%s %s %s", commands[j].Namespace, commands[j].Resource, commands[j].Verb)
return commands[i].signature() < commands[j].signature()
})
return commands
}
Expand Down Expand Up @@ -278,3 +278,8 @@ func (c *Command) getHumanMarshalerOpt() *human.MarshalOpt {
}
return nil
}

// get a signature to sort commands
func (c *Command) signature() string {
return c.Namespace + " " + c.Resource + " " + c.Verb + " " + c.Short
}

0 comments on commit 63d043a

Please sign in to comment.