diff options
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/server/server.go | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/pkg/server/server.go b/pkg/server/server.go index 0c3d2af..d8a014d 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -55,7 +55,6 @@ type request struct { cmd *cmd - name string argc int args []string @@ -99,37 +98,29 @@ func (r *request) expect(c ...int) { var sep string if n == 1 { - sep = "is" + sep = " is " } else { - sep = "are" + sep = " are " } - return fmt.Sprintf("%d %s expected", n, sep) + return fmt.Sprint(n, sep, "expected") } - switch len(c) { - case 0: - if r.argc > 0 { - r.Fatal("args are not expected") + check := func (cond bool, args ...interface{}) { + if cond { + r.Fatal(args...) } + } + switch len(c) { + case 0: + check(r.argc > 0, "args are not expected") case 1: - if r.argc < c[0] { - r.Fatal("not enough args: ", desc(c[0])) - } - - if r.argc > c[0] { - r.Fatal("too many args: ", desc(c[0])) - } - + check(r.argc < c[0], "not enough args: ", desc(c[0])) + check(r.argc > c[0], "too many args: ", desc(c[0])) case 2: - if r.argc < c[0] { - r.Fatal("not enough args: at least ", desc(c[0])) - } - - if r.argc > c[1] { - r.Fatal("too many args: no more than ", desc(c[1])) - } + check(r.argc < c[0], "not enough args: at least ", desc(c[0])) + check(r.argc > c[1], "too many args: no more than ", desc(c[1])) } } |
