diff --git a/cmd/env.go b/cmd/env.go index 176865d..b803045 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -65,8 +65,8 @@ var errModesIncompatible = exit.Error{ ExitCode: exit.ExitCommandArguments, } -func (e _env) Run(context ggman.Context) error { - // check that at most one mode was provided +func (e _env) AfterParse() error { + // check that at most one mode was given count := 0 if e.Describe { count++ @@ -80,7 +80,10 @@ func (e _env) Run(context ggman.Context) error { if count > 1 { return errModesIncompatible } + return nil +} +func (e _env) Run(context ggman.Context) error { variables, err := e.variables() if err != nil { return err diff --git a/cmd/env_test.go b/cmd/env_test.go index 305b453..99cd86f 100644 --- a/cmd/env_test.go +++ b/cmd/env_test.go @@ -85,6 +85,33 @@ func TestCommandEnv(t *testing.T) { "${GGROOT}\n", "", }, + { + "more than one mode", + "", + []string{"env", "--list", "--raw"}, + + 4, + "", + "At most one of `--raw`, `--list` and `--describe` may be given\n", + }, + { + "more than one mode (2)", + "", + []string{"env", "--list", "--describe"}, + + 4, + "", + "At most one of `--raw`, `--list` and `--describe` may be given\n", + }, + { + "more than one mode (3)", + "", + []string{"env", "--raw", "--describe"}, + + 4, + "", + "At most one of `--raw`, `--list` and `--describe` may be given\n", + }, } for _, tt := range tests {