moby/cli/required.go
Daniel Nephin 667dcb0e8e Update usage and help to (almost) match the existing docker behaviour
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2016-05-31 14:41:37 -07:00

37 lines
718 B
Go

package cli
import (
"fmt"
"github.com/spf13/cobra"
)
// MinRequiredArgs checks if the minimum number of args exists, and returns an
// error if they do not.
func MinRequiredArgs(args []string, min int, cmd *cobra.Command) error {
if len(args) >= min {
return nil
}
return fmt.Errorf(
"\"%s\" requires at least %d argument(s).\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
min,
cmd.UseLine(),
cmd.Short,
)
}
// AcceptsNoArgs returns an error message if there are args
func AcceptsNoArgs(args []string, cmd *cobra.Command) error {
if len(args) == 0 {
return nil
}
return fmt.Errorf(
"\"%s\" accepts no argument(s).\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
cmd.UseLine(),
cmd.Short,
)
}