Skip to content

Commit

Permalink
Fix required service attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
meap committed Sep 13, 2024
1 parent 80c2cba commit 648af6b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ var service string

var rootCmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if cmd.Name() != "list" && service == "" {
commandsWithoutService := []string{"completion", "help", "list", "version"}

serviceRequired := true
for _, c := range commandsWithoutService {
if cmd.Name() == c {
serviceRequired = false
break
}
}

if serviceRequired && service == "" {
return fmt.Errorf("--service flag is required for this command")
}

Expand Down

0 comments on commit 648af6b

Please sign in to comment.