kill: requires max 2 arguments

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2017-02-02 17:32:52 +01:00
parent 1c9c074d79
commit 1d6447797e
2 changed files with 8 additions and 0 deletions

View File

@ -72,6 +72,9 @@ signal to the init process of the "ubuntu01" container:
if err := checkArgs(context, 1, minArgs); err != nil { if err := checkArgs(context, 1, minArgs); err != nil {
return err return err
} }
if err := checkArgs(context, 2, maxArgs); err != nil {
return err
}
container, err := getContainer(context) container, err := getContainer(context)
if err != nil { if err != nil {
return err return err

View File

@ -13,6 +13,7 @@ import (
const ( const (
exactArgs = iota exactArgs = iota
minArgs minArgs
maxArgs
) )
func checkArgs(context *cli.Context, expected, checkType int) error { func checkArgs(context *cli.Context, expected, checkType int) error {
@ -27,6 +28,10 @@ func checkArgs(context *cli.Context, expected, checkType int) error {
if context.NArg() < expected { if context.NArg() < expected {
err = fmt.Errorf("%s: %q requires a minimum of %d argument(s)", os.Args[0], cmdName, expected) err = fmt.Errorf("%s: %q requires a minimum of %d argument(s)", os.Args[0], cmdName, expected)
} }
case maxArgs:
if context.NArg() > expected {
err = fmt.Errorf("%s: %q requires a maximum of %d argument(s)", os.Args[0], cmdName, expected)
}
} }
if err != nil { if err != nil {