Skip to content

Commit 629641a

Browse files
authored
chore: sort namespace in scw usage (#652)
1 parent f134e9b commit 629641a

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

cmd/scw/main.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ var (
2525
GoArch = runtime.GOARCH
2626
)
2727

28+
func getCommands() *core.Commands {
29+
// Import all commands available in CLI from various packages.
30+
// NB: Merge order impacts scw usage sort.
31+
commands := core.NewCommands()
32+
commands.Merge(instance.GetCommands())
33+
commands.Merge(marketplace.GetCommands())
34+
commands.Merge(initNamespace.GetCommands())
35+
commands.Merge(configNamespace.GetCommands())
36+
commands.Merge(autocompleteNamespace.GetCommands())
37+
commands.Merge(versionNamespace.GetCommands())
38+
return commands
39+
}
40+
2841
func main() {
2942
buildInfo := &core.BuildInfo{
3043
Version: version.Must(version.NewSemver(Version)), // panic when version does not respect semantic versionning
@@ -39,18 +52,9 @@ func main() {
3952
// Catch every panic after this line. This will send an anonymous report on Scaleway's sentry.
4053
defer sentry.RecoverPanicAndSendReport(buildInfo)
4154

42-
// Import all commands available in CLI from various packages.
43-
commands := core.NewCommands()
44-
commands.Merge(instance.GetCommands())
45-
commands.Merge(initNamespace.GetCommands())
46-
commands.Merge(configNamespace.GetCommands())
47-
commands.Merge(marketplace.GetCommands())
48-
commands.Merge(autocompleteNamespace.GetCommands())
49-
commands.Merge(versionNamespace.GetCommands())
50-
5155
exitCode, _, _ := core.Bootstrap(&core.BootstrapConfig{
5256
Args: os.Args,
53-
Commands: commands,
57+
Commands: getCommands(),
5458
BuildInfo: buildInfo,
5559
Stdout: os.Stdout,
5660
Stderr: os.Stderr,

cmd/scw/main_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/internal/core"
7+
)
8+
9+
func Test_MainUsage(t *testing.T) {
10+
t.Run("usage", core.Test(&core.TestConfig{
11+
Commands: getCommands(),
12+
Cmd: "scw -h",
13+
Check: core.TestCheckCombine(
14+
core.TestCheckExitCode(0),
15+
core.TestCheckGolden(),
16+
),
17+
}))
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
USAGE:
2+
scw [global-flags] <command> [flags]
3+
4+
AVAILABLE COMMANDS:
5+
instance Instance API
6+
marketplace Marketplace API
7+
init Initialize the config
8+
config Config file management
9+
autocomplete Install autocompletion script
10+
version Display cli version
11+
help Help about any command
12+
13+
FLAGS:
14+
-D, --debug Enable debug mode
15+
-h, --help help for scw
16+
-o, --output string Output format: json or human
17+
-p, --profile string The config profile to use
18+
19+
Use "scw [command] --help" for more information about a command.

internal/core/cobra_builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (b *cobraBuilder) build() *cobra.Command {
7676
b.hydrateCobra(index[k], commandsIndex[k])
7777
}
7878

79+
b.hydrateCobra(rootCmd, &Command{})
7980
return rootCmd
8081
}
8182

0 commit comments

Comments
 (0)