Skip to content

Commit db8e3de

Browse files
committed
add flags combination validation func
1 parent 0cd3aa6 commit db8e3de

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/araddon/dateparse"
3030
"github.com/olekukonko/tablewriter"
31+
"github.com/spf13/cobra"
3132
gitlab "github.com/xanzy/go-gitlab"
3233

3334
"github.com/ghodss/yaml"
@@ -55,6 +56,16 @@ func newSetAtLeastOneFlagError(flags ...string) error {
5556
setAtLeastOneFlagError, strings.Join(flags, ", "))
5657
}
5758

59+
func validateFlagCombination(cmd *cobra.Command, mainFlag string, flags ...string) error {
60+
for _, fName := range flags {
61+
if cmd.Flag(fName).Changed && !cmd.Flag(mainFlag).Changed {
62+
return fmt.Errorf("'--%s' flag can only be used with '--%s' flag",
63+
fName, mainFlag)
64+
}
65+
}
66+
return nil
67+
}
68+
5869
func getUserIDbyUsername(username string) (int, error) {
5970
userInfo, err := getUserByUsername(username)
6071
if err != nil {

0 commit comments

Comments
 (0)