Skip to content
Myr

Add dots in comments of args.go

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 18eefcd · Browse files · 1 file+8 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−17 removed

  • other:+8 added−17 removed

1 file+8 added−17 removed

modified:args.go+8 added-17 removed
14 unmodified lines
15 if !cmd.HasSubCommands() {16 return nil17 }1819 // root command with subcommands, do subcommand checking19 // root command with subcommands, do subcommand checking.20 if !cmd.HasParent() && len(args) > 0 {21 return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0]))22 }23 return nil24}2526// NoArgs returns an error if any args are included26// NoArgs returns an error if any args are included.27func NoArgs(cmd *Command, args []string) error {28 if len(args) > 0 {29 return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath())30 }31 return nil32}3334// OnlyValidArgs returns an error if any args are not in the list of ValidArgs34// OnlyValidArgs returns an error if any args are not in the list of ValidArgs.35func OnlyValidArgs(cmd *Command, args []string) error {36 if len(cmd.ValidArgs) > 0 {37 for _, v := range args {38 if !stringInSlice(v, cmd.ValidArgs) {
3 unmodified lines
42 }43 return nil44}4546func stringInSlice(a string, list []string) bool {47 for _, b := range list {48 if b == a {49 return true50 }51 }52 return false53}5455// ArbitraryArgs never returns an error46// ArbitraryArgs never returns an error.47func ArbitraryArgs(cmd *Command, args []string) error {48 return nil49}5060// MinimumNArgs returns an error if there is not at least N args51// MinimumNArgs returns an error if there is not at least N args.52func MinimumNArgs(n int) PositionalArgs {53 return func(cmd *Command, args []string) error {54 if len(args) < n {55 return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args))
1 unmodified line
57 return nil58 }59}6070// MaximumNArgs returns an error if there are more than N args61// MaximumNArgs returns an error if there are more than N args.62func MaximumNArgs(n int) PositionalArgs {63 return func(cmd *Command, args []string) error {64 if len(args) > n {65 return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args))
1 unmodified line
67 return nil68 }69}7080// ExactArgs returns an error if there are not exactly n args71// ExactArgs returns an error if there are not exactly n args.72func ExactArgs(n int) PositionalArgs {73 return func(cmd *Command, args []string) error {74 if len(args) != n {75 return fmt.Errorf("accepts %d arg(s), received %d", n, len(args))
1 unmodified line
77 return nil78 }79}8090// RangeArgs returns an error if the number of args is not within the expected range81// RangeArgs returns an error if the number of args is not within the expected range.82func RangeArgs(min int, max int) PositionalArgs {83 return func(cmd *Command, args []string) error {84 if len(args) < min || len(args) > max {85 return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args))
4 unmodified lines