Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ var (
GoArch = runtime.GOARCH
)

func getCommands() *core.Commands {
// Import all commands available in CLI from various packages.
// NB: Merge order impacts scw usage sort.
commands := core.NewCommands()
commands.Merge(instance.GetCommands())
commands.Merge(marketplace.GetCommands())
commands.Merge(initNamespace.GetCommands())
commands.Merge(configNamespace.GetCommands())
commands.Merge(autocompleteNamespace.GetCommands())
commands.Merge(versionNamespace.GetCommands())
return commands
}

func main() {
buildInfo := &core.BuildInfo{
Version: version.Must(version.NewSemver(Version)), // panic when version does not respect semantic versionning
Expand All @@ -39,18 +52,9 @@ func main() {
// Catch every panic after this line. This will send an anonymous report on Scaleway's sentry.
defer sentry.RecoverPanicAndSendReport(buildInfo)

// Import all commands available in CLI from various packages.
commands := core.NewCommands()
commands.Merge(instance.GetCommands())
commands.Merge(initNamespace.GetCommands())
commands.Merge(configNamespace.GetCommands())
commands.Merge(marketplace.GetCommands())
commands.Merge(autocompleteNamespace.GetCommands())
commands.Merge(versionNamespace.GetCommands())

exitCode, _, _ := core.Bootstrap(&core.BootstrapConfig{
Args: os.Args,
Commands: commands,
Commands: getCommands(),
BuildInfo: buildInfo,
Stdout: os.Stdout,
Stderr: os.Stderr,
Expand Down
18 changes: 18 additions & 0 deletions cmd/scw/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"testing"

"github.com/scaleway/scaleway-cli/internal/core"
)

func Test_MainUsage(t *testing.T) {
t.Run("usage", core.Test(&core.TestConfig{
Commands: getCommands(),
Cmd: "scw -h",
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
core.TestCheckGolden(),
),
}))
}
19 changes: 19 additions & 0 deletions cmd/scw/testdata/test-main-usage-usage.stderr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
USAGE:
scw [global-flags] <command> [flags]

AVAILABLE COMMANDS:
instance Instance API
marketplace Marketplace API
init Initialize the config
config Config file management
autocomplete Install autocompletion script
version Display cli version
help Help about any command

FLAGS:
-D, --debug Enable debug mode
-h, --help help for scw
-o, --output string Output format: json or human
-p, --profile string The config profile to use

Use "scw [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions internal/core/cobra_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (b *cobraBuilder) build() *cobra.Command {
b.hydrateCobra(index[k], commandsIndex[k])
}

b.hydrateCobra(rootCmd, &Command{})
return rootCmd
}

Expand Down