-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: arekkas <aeneas@ory.am>
- Loading branch information
arekkas
committed
Oct 9, 2018
1 parent
2dfc052
commit 2f9e0a8
Showing
1 changed file
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,35 @@ | ||
package cmdx | ||
|
||
import "github.com/spf13/cobra" | ||
import ( | ||
"github.com/spf13/cobra" | ||
"strings" | ||
) | ||
|
||
func MinArgs(cmd *cobra.Command, args []string, min int) { | ||
if len(args) < min { | ||
Fatalf(`%s | ||
Expected %d command line arguments but got %d.`, cmd.UsageString(), min, len(args)) | ||
Expected at least %d command line arguments but only got %d.`, cmd.UsageString(), min, len(args)) | ||
} | ||
} | ||
|
||
func ExactArgs(cmd *cobra.Command, args []string, min int) { | ||
if len(args) < min { | ||
Fatalf(`%s | ||
Expected exactly %d command line arguments but got %d.`, cmd.UsageString(), min, len(args)) | ||
} | ||
} | ||
|
||
func RangeArgs(cmd *cobra.Command, args []string, allowed []int) { | ||
for _, a := range allowed { | ||
if len(args) == a { | ||
return | ||
} | ||
} | ||
if len(args) < min { | ||
Fatalf(`%s | ||
Expected exact %s command line arguments but got %d.`, cmd.UsageString(), strings.Join(allowed, ", "), len(args)) | ||
} | ||
} |