MCPcopy Create free account
hub / github.com/algolia/cli / AtLeastNArgs

Function AtLeastNArgs

pkg/validators/cmd.go:56–71  ·  view source on GitHub ↗

AtLeastNArgs is a validator for commands to print an error with a custom message followed by usage, flags and available commands when too few argument(s) are provided

(n int)

Source from the content-addressed store, hash-verified

54// AtLeastNArgs is a validator for commands to print an error with a custom message
55// followed by usage, flags and available commands when too few argument(s) are provided
56func AtLeastNArgs(n int) cobra.PositionalArgs {
57 argument := "argument"
58 if n > 1 {
59 argument = argument + "s"
60 }
61
62 return func(cmd *cobra.Command, args []string) error {
63 if len(args) < n {
64 msg := fmt.Sprintf("`%s` requires at least %d %s.", cmd.CommandPath(), n, argument)
65
66 return cmdutil.FlagErrorf("%s", msg)
67 }
68
69 return nil
70 }
71}

Callers

nothing calls this directly

Calls 1

FlagErrorfFunction · 0.92

Tested by

no test coverage detected