cli: rename args that collided with builtins (predeclard)

cli/required.go:33:22: param min has same name as predeclared identifier (predeclared)
    func RequiresMinArgs(min int) cobra.PositionalArgs {
                         ^
    cli/required.go:50:22: param max has same name as predeclared identifier (predeclared)
    func RequiresMaxArgs(max int) cobra.PositionalArgs {
                         ^
    cli/required.go:67:24: param min has same name as predeclared identifier (predeclared)
    func RequiresRangeArgs(min int, max int) cobra.PositionalArgs {
                           ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-08-26 13:55:28 +02:00
parent 9c87891278
commit c4a55df7c0
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 13 additions and 13 deletions

View File

@ -30,52 +30,52 @@ func NoArgs(cmd *cobra.Command, args []string) error {
} }
// RequiresMinArgs returns an error if there is not at least min args // RequiresMinArgs returns an error if there is not at least min args
func RequiresMinArgs(min int) cobra.PositionalArgs { func RequiresMinArgs(minArgs int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
if len(args) >= min { if len(args) >= minArgs {
return nil return nil
} }
return errors.Errorf( return errors.Errorf(
"%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage: %[5]s\n\nSee '%[2]s --help' for more information", "%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage: %[5]s\n\nSee '%[2]s --help' for more information",
binName(cmd), binName(cmd),
cmd.CommandPath(), cmd.CommandPath(),
min, minArgs,
pluralize("argument", min), pluralize("argument", minArgs),
cmd.UseLine(), cmd.UseLine(),
) )
} }
} }
// RequiresMaxArgs returns an error if there is not at most max args // RequiresMaxArgs returns an error if there is not at most max args
func RequiresMaxArgs(max int) cobra.PositionalArgs { func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
if len(args) <= max { if len(args) <= maxArgs {
return nil return nil
} }
return errors.Errorf( return errors.Errorf(
"%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nSRun '%[2]s --help' for more information", "%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nSRun '%[2]s --help' for more information",
binName(cmd), binName(cmd),
cmd.CommandPath(), cmd.CommandPath(),
max, maxArgs,
pluralize("argument", max), pluralize("argument", maxArgs),
cmd.UseLine(), cmd.UseLine(),
) )
} }
} }
// RequiresRangeArgs returns an error if there is not at least min args and at most max args // RequiresRangeArgs returns an error if there is not at least min args and at most max args
func RequiresRangeArgs(min int, max int) cobra.PositionalArgs { func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
if len(args) >= min && len(args) <= max { if len(args) >= minArgs && len(args) <= maxArgs {
return nil return nil
} }
return errors.Errorf( return errors.Errorf(
"%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information", "%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information",
binName(cmd), binName(cmd),
cmd.CommandPath(), cmd.CommandPath(),
min, minArgs,
max, maxArgs,
pluralize("argument", max), pluralize("argument", maxArgs),
cmd.UseLine(), cmd.UseLine(),
) )
} }