Skip to content

Commit

Permalink
Check for more arguments than required
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyr committed May 3, 2021
1 parent c1d4cad commit 126d001
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/apikey/apikeyCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func checkCreateArgs(cmd *cobra.Command, args []string) error {
os.Exit(0)
} else if argsLen < 3 {
return fmt.Errorf("requires ORG_SLUG, NAME and ROLE argument")
} else if argsLen > 3 {
return fmt.Errorf("requires only ORG_SLUG, NAME and ROLE argument")
}

if err := ak.SetOrgSlug(args[0]); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/apikey/apikeyDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func checkDeleteArgs(cmd *cobra.Command, args []string) error {
os.Exit(0)
} else if argsLen < 2 {
return fmt.Errorf("requires ORG_SLUG and NAME argument")
} else if argsLen > 2 {
return fmt.Errorf("requires only ORG_SLUG and NAME argument")
}

if err := ak.SetOrgSlug(args[0]); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/apikey/apikeyList.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func checkListArgs(cmd *cobra.Command, args []string) error {
os.Exit(0)
}

if argsLen > 2 {
return fmt.Errorf("requires only ORG_SLUG and optionally NAME argument")
}

if err := ak.SetOrgSlug(args[0]); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/grafana/apikey/apikeyCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func checkCreateArgs(cmd *cobra.Command, args []string) error {
return errors.New("requires NAME and ROLE argument")
}

if argsLen > 2 {
return errors.New("requires only NAME and ROLE argument")
}

if err := ak.SetName(args[0]); err != nil {
return err
}
Expand All @@ -66,6 +70,8 @@ func checkCreateArgs(cmd *cobra.Command, args []string) error {
}
} else if argsLen < 3 {
return errors.New("requires STACK_SLUG, NAME and ROLE argument")
} else if argsLen > 3 {
return errors.New("requires only STACK_SLUG, NAME and ROLE argument")
} else {
if err := ak.SetStackSlug(args[0]); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cmd/grafana/apikey/apikeyDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func checkDeleteArgs(cmd *cobra.Command, args []string) error {
return errors.New("requires NAME argument")
}

if argsLen > 1 {
return errors.New("requires only NAME argument")
}

if err := ak.SetName(args[0]); err != nil {
return err
}
Expand All @@ -55,6 +59,8 @@ func checkDeleteArgs(cmd *cobra.Command, args []string) error {
}
} else if argsLen < 3 {
return errors.New("requires ORG_SLUG, STACK_SLUG and NAME argument")
} else if argsLen > 3 {
return errors.New("requires only ORG_SLUG, STACK_SLUG and NAME argument")
} else {
if err := ak.SetOrgSlug(args[0]); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cmd/grafana/apikey/apikeyList.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func checkListArgs(cmd *cobra.Command, args []string) error {
return err
}

if argsLen > 1 {
return errors.New("requires only optional NAME argument")
}

if argsLen == 1 {
if err := ak.SetName(args[0]); err != nil {
return err
Expand All @@ -58,6 +62,8 @@ func checkListArgs(cmd *cobra.Command, args []string) error {
os.Exit(0)
} else if argsLen < 2 {
return errors.New("requires ORG_SLUG and STACK_SLUG argument")
} else if argsLen > 2 {
return errors.New("requires only ORG_SLUG and STACK_SLUG argument")
} else {
if err := ak.SetOrgSlug(args[0]); err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion cmd/grafana/grafanaRestart.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ func NewCmdRestart() *cobra.Command {
// checkRestartArgs checks if the positional arguments have correct value. If no
// args are specified, it prints out the command usage.
func checkRestartArgs(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
argsLen := len(args)

if argsLen == 0 {
cmd.Usage()
os.Exit(0)
}

if argsLen > 1 {
return fmt.Errorf("requires only STACK_SLUG argument")
}

if err := gr.SetStackSlug(args[0]); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/stack/stackCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func checkCreateArgs(cmd *cobra.Command, args []string) error {
os.Exit(0)
}

if argsLen > 2 {
return fmt.Errorf("requires only STACK_SLUG and optionally NAME argument")
}

if err := st.SetStackSlug(args[0]); err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/stack/stackDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ func NewCmdDelete() *cobra.Command {
// checkDeleteArgs checks if the positional arguments have correct value. If no
// args are specified, it prints out the command usage.
func checkDeleteArgs(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
argsLen := len(args)

if argsLen == 0 {
cmd.Usage()
os.Exit(0)
}

if argsLen > 1 {
return fmt.Errorf("requires only STACK_SLUG argument")
}

if err := st.SetStackSlug(args[0]); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/stack/stackList.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func checkListArgs(cmd *cobra.Command, args []string) error {
os.Exit(0)
}

if argsLen > 2 {
return fmt.Errorf("requires only ORG_SLUG and optionally STACK_SLUG argument")
}

if err := st.SetOrgSlug(args[0]); err != nil {
return err
}
Expand Down

0 comments on commit 126d001

Please sign in to comment.