Skip to content

Commit 5f54ebd

Browse files
author
Arthur Amstutz
committed
Pull request #41: fix: Clean commands that are not relevant for WASM mode
Merge in API/ovh-cli from dev/aamstutz/hide-cmds-wasm to master * commit 'ea2a9c160c90e9cba438832a0eff2b61528c8859': fix: Clean commands that are not relevant for WASM mode
2 parents 801ed5e + ea2a9c1 commit 5f54ebd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

cmd/ovhcloud/main_wasm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func registerCallbacks() {
6262
}
6363

6464
func main() {
65-
cmd.InitWasmHelpCommands(cmd.GetRootCommand())
65+
cmd.WasmCleanCommands()
6666
registerCallbacks()
6767
select {}
6868
}

internal/cmd/root.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ var (
3333
"init-file",
3434
"replace",
3535
"interactive",
36+
"format",
37+
"debug",
38+
}
39+
40+
wasmHiddenCommands = []string{
41+
"login",
42+
"config",
3643
}
3744
)
3845

@@ -83,7 +90,22 @@ func init() {
8390
}
8491
}
8592

86-
func InitWasmHelpCommands(cmd *cobra.Command) {
93+
func WasmCleanCommands() {
94+
// Remove commands that are not relevant in WASM mode
95+
for _, child := range rootCmd.Commands() {
96+
if slices.Contains(wasmHiddenCommands, child.Name()) {
97+
rootCmd.RemoveCommand(child)
98+
}
99+
}
100+
101+
// Hide "completion" command
102+
rootCmd.CompletionOptions.DisableDefaultCmd = true
103+
104+
// Recursively clean flags that are not relevant in WASM mode
105+
wasmCleanHelpCommands(rootCmd)
106+
}
107+
108+
func wasmCleanHelpCommands(cmd *cobra.Command) {
87109
cmd.SetHelpFunc(func(command *cobra.Command, _ []string) {
88110
// Hide flags that are not relevant in WASM mode
89111
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
@@ -105,7 +127,7 @@ func InitWasmHelpCommands(cmd *cobra.Command) {
105127
})
106128

107129
for _, child := range cmd.Commands() {
108-
InitWasmHelpCommands(child)
130+
wasmCleanHelpCommands(child)
109131
}
110132
}
111133

0 commit comments

Comments
 (0)