Skip to content

Commit 4755900

Browse files
committed
set default apiServer, allow to run init and version subcommands without arguments
1 parent ad5dc81 commit 4755900

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

cmd/command.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ func commandRun(cmd *cobra.Command, command SchemaCommand) {
5757
}
5858
}
5959
}
60+
numErrors := 0
61+
if apiClientid == "" {
62+
fmt.Printf("ERROR: --%s flag is required\n", flagApiClientid)
63+
numErrors += 1
64+
}
65+
if apiSecret == "" {
66+
fmt.Printf("ERROR: --%s flag is required\n", flagApiSecret)
67+
numErrors += 1
68+
}
69+
if numErrors > 0 {
70+
os.Exit(exitCodeInvalidFlags)
71+
}
6072
if command.Run.Cmd == "getList" {
6173
commandRunGetList(cmd, command, false, false, nil, "")
6274
} else if command.Run.Cmd == "post" {

cmd/global_flags.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,15 @@ func loadGlobalFlags() {
5454
}
5555
}
5656
numFailures := 0
57-
if apiServer = strings.TrimSpace(viper.GetString(flagApiServerKey)); apiServer == "" {
58-
numFailures += 1
59-
fmt.Printf("ERROR: --%s flag is required\n", flagApiServer)
60-
} else if debug {
61-
_, _ = fmt.Fprintf(os.Stderr, "%s = %s\n", flagApiServerKey, apiServer)
57+
apiServer = strings.TrimSpace(viper.GetString(flagApiServerKey))
58+
apiClientid = strings.TrimSpace(viper.GetString(flagApiClientidKey))
59+
apiSecret = strings.TrimSpace(viper.GetString(flagApiSecretKey))
60+
if apiServer == "" {
61+
apiServer = "https://cloudcli.cloudwm.com"
6262
}
63-
if apiClientid = strings.TrimSpace(viper.GetString(flagApiClientidKey)); apiClientid == "" {
64-
numFailures += 1
65-
fmt.Printf("ERROR: --%s flag is required\n", flagApiClientid)
66-
} else if debug {
63+
if debug {
64+
_, _ = fmt.Fprintf(os.Stderr, "%s = %s\n", flagApiServerKey, apiServer)
6765
_, _ = fmt.Fprintf(os.Stderr, "%s = %s\n", flagApiClientidKey, apiClientid)
68-
}
69-
if apiSecret = strings.TrimSpace(viper.GetString(flagApiSecretKey)); apiSecret == "" {
70-
numFailures += 1
71-
fmt.Printf("ERROR: --%s flag is required\n", flagApiSecret)
72-
} else if debug {
7366
_, _ = fmt.Fprintf(os.Stderr, "%s = %s\n", flagApiSecretKey, apiSecret)
7467
}
7568
format = strings.TrimSpace(viper.GetString(flagFormatKey))

0 commit comments

Comments
 (0)