From 1d6447797e62867d68c99cb9f69ee80bf1b30d11 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 2 Feb 2017 17:32:52 +0100 Subject: [PATCH] kill: requires max 2 arguments Signed-off-by: Giuseppe Scrivano --- kill.go | 3 +++ utils.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/kill.go b/kill.go index e4f5831b..f80c4db7 100644 --- a/kill.go +++ b/kill.go @@ -72,6 +72,9 @@ signal to the init process of the "ubuntu01" container: if err := checkArgs(context, 1, minArgs); err != nil { return err } + if err := checkArgs(context, 2, maxArgs); err != nil { + return err + } container, err := getContainer(context) if err != nil { return err diff --git a/utils.go b/utils.go index ce610440..3c3785b9 100644 --- a/utils.go +++ b/utils.go @@ -13,6 +13,7 @@ import ( const ( exactArgs = iota minArgs + maxArgs ) 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 { 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 {