diff --git a/cmd/import.go b/cmd/import.go index c5a98d5..59afec2 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -41,26 +41,12 @@ func NewImportCommand() *cobra.Command { Long: `import API artifacts on Microcks server`, Run: func(cmd *cobra.Command, args []string) { // Parse subcommand args first. - if len(os.Args) < 2 { + if len(args) == 0 { fmt.Println("import command require args") os.Exit(1) } - specificationFiles := os.Args[2] - - // Validate presence and values of flags. - if len(microcksURL) == 0 { - fmt.Println("--microcksURL flag is mandatory. Check Usage.") - os.Exit(1) - } - if len(keycloakClientID) == 0 { - fmt.Println("--keycloakClientId flag is mandatory. Check Usage.") - os.Exit(1) - } - if len(keycloakClientSecret) == 0 { - fmt.Println("--keycloakClientSecret flag is mandatory. Check Usage.") - os.Exit(1) - } + specificationFiles := args[0] // Collect optional HTTPS transport flags. if insecureTLS { @@ -128,5 +114,11 @@ func NewImportCommand() *cobra.Command { importCmd.Flags().BoolVar(&insecureTLS, "insecure", false, "Whether to accept insecure HTTPS connection") importCmd.Flags().StringVar(&caCertPaths, "caCerts", "", "Comma separated paths of CRT files to add to Root CAs") importCmd.Flags().BoolVar(&verbose, "verbose", false, "Produce dumps of HTTP exchanges") + + //Marking flags 'required' + importCmd.MarkFlagRequired("microcksURL") + importCmd.MarkFlagRequired("keycloakClientId") + importCmd.MarkFlagRequired("keycloakClientSecret") + return importCmd } diff --git a/cmd/importURL.go b/cmd/importURL.go index 936df25..96b009e 100644 --- a/cmd/importURL.go +++ b/cmd/importURL.go @@ -27,20 +27,6 @@ import ( "github.com/spf13/cobra" ) -// import ( -// "flag" -// "fmt" -// "os" -// "strconv" -// "strings" - -// "github.com/microcks/microcks-cli/pkg/config" -// "github.com/microcks/microcks-cli/pkg/connectors" -// ) - -// type importURLCommand struct { -// } - func NewImportURLCommand() *cobra.Command { var ( microcksURL string @@ -56,27 +42,13 @@ func NewImportURLCommand() *cobra.Command { Long: `import API artifacts from URL on Microcks server`, Run: func(cmd *cobra.Command, args []string) { // Parse subcommand args first. - if len(os.Args) < 2 { + if len(args) == 0 { fmt.Println("import-url command require args") os.Exit(1) } specificationFiles := os.Args[2] - // Validate presence and values of flags. - if len(microcksURL) == 0 { - fmt.Println("--microcksURL flag is mandatory. Check Usage.") - os.Exit(1) - } - if len(keycloakClientID) == 0 { - fmt.Println("--keycloakClientId flag is mandatory. Check Usage.") - os.Exit(1) - } - if len(keycloakClientSecret) == 0 { - fmt.Println("--keycloakClientSecret flag is mandatory. Check Usage.") - os.Exit(1) - } - // Collect optional HTTPS transport flags. if insecureTLS { config.InsecureTLS = true @@ -151,5 +123,10 @@ func NewImportURLCommand() *cobra.Command { importURLCmd.Flags().StringVar(&caCertPaths, "caCerts", "", "Comma separated paths of CRT files to add to Root CAs") importURLCmd.Flags().BoolVar(&verbose, "verbose", false, "Produce dumps of HTTP exchanges") + //Marking flags 'required' + importURLCmd.MarkFlagRequired("microcksURL") + importURLCmd.MarkFlagRequired("keycloakClientId") + importURLCmd.MarkFlagRequired("keycloakClientSecret") + return importURLCmd } diff --git a/cmd/test.go b/cmd/test.go index 386e37a..43c2b52 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -81,18 +81,6 @@ func NewTestCommand() *cobra.Command { } // Validate presence and values of flags. - if len(microcksURL) == 0 { - fmt.Println("--microcksURL flag is mandatory. Check Usage.") - os.Exit(1) - } - if len(keycloakClientID) == 0 { - fmt.Println("--keycloakClientId flag is mandatory. Check Usage.") - os.Exit(1) - } - if len(keycloakClientSecret) == 0 { - fmt.Println("--keycloakClientSecret flag is mandatory. Check Usage.") - os.Exit(1) - } if &waitFor == nil || (!strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min")) { fmt.Println("--waitFor format is wrong. Applying default 5sec") waitFor = "5sec" @@ -200,6 +188,11 @@ func NewTestCommand() *cobra.Command { testCmd.Flags().StringVar(&caCertPaths, "caCerts", "", "Comma separated paths of CRT files to add to Root CAs") testCmd.Flags().BoolVar(&verbose, "verbose", false, "Produce dumps of HTTP exchanges") + //Marking flags 'required' + testCmd.MarkFlagRequired("microcksURL") + testCmd.MarkFlagRequired("keycloakClientId") + testCmd.MarkFlagRequired("keycloakClientSecret") + return testCmd }