2016-04-19 16:59:48 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2016-05-26 21:57:31 +00:00
|
|
|
"strings"
|
2016-04-19 16:59:48 +00:00
|
|
|
|
2017-03-09 18:23:45 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-04-19 16:59:48 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-07-03 12:47:39 +00:00
|
|
|
// NoArgs validates args and returns an error if there are any args
|
2016-05-26 21:57:31 +00:00
|
|
|
func NoArgs(cmd *cobra.Command, args []string) error {
|
|
|
|
if len(args) == 0 {
|
2016-04-19 16:59:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-26 21:57:31 +00:00
|
|
|
if cmd.HasSubCommands() {
|
2017-03-09 18:23:45 +00:00
|
|
|
return errors.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n"))
|
2016-05-16 21:20:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 18:23:45 +00:00
|
|
|
return errors.Errorf(
|
2016-06-04 14:19:54 +00:00
|
|
|
"\"%s\" accepts no argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
|
|
|
cmd.CommandPath(),
|
2016-05-16 21:20:29 +00:00
|
|
|
cmd.CommandPath(),
|
|
|
|
cmd.UseLine(),
|
|
|
|
cmd.Short,
|
|
|
|
)
|
|
|
|
}
|