Skip to content

Commit 63d043a

Browse files
authored
fix(core): change command signature to fix sort of same command (#2705)
1 parent fa9a24b commit 63d043a

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

cmd/scw/testdata/test-all-usage-account-usage#01.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
This API allows you to manage projects.
3+
Account API
44

55
USAGE:
66
scw account <command>

cmd/scw/testdata/test-all-usage-account-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
This API allows you to manage projects.
3+
Account API
44

55
USAGE:
66
scw account <command>

cmd/scw/testdata/test-main-usage-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ USAGE:
44
scw <command>
55

66
AVAILABLE COMMANDS:
7-
account User related data
7+
account Account API
88
apple-silicon Apple silicon API
99
autocomplete Autocomplete related commands
1010
baremetal Elastic metal API

internal/core/command.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (c *Commands) GetSortedCommand() []*Command {
246246
copy(commands, c.commands)
247247

248248
sort.Slice(commands, func(i, j int) bool {
249-
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)
249+
return commands[i].signature() < commands[j].signature()
250250
})
251251
return commands
252252
}
@@ -278,3 +278,8 @@ func (c *Command) getHumanMarshalerOpt() *human.MarshalOpt {
278278
}
279279
return nil
280280
}
281+
282+
// get a signature to sort commands
283+
func (c *Command) signature() string {
284+
return c.Namespace + " " + c.Resource + " " + c.Verb + " " + c.Short
285+
}

0 commit comments

Comments
 (0)