moby/cli/required.go
Daniel Nephin 69264beb40 Migrate volume commands to cobra.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2016-05-31 14:41:37 -07:00

23 lines
425 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,
)
}