cleanup subcommand and specs

main
Lynn Cyrin 5 years ago
parent 300288670f
commit 2299852c3c
No known key found for this signature in database
GPG Key ID: EE9CCB427DFEC897

@ -327,7 +327,6 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
set.SetOutput(ioutil.Discard)
err = set.Parse(ctx.Args().Tail())
nerr := normalizeFlags(a.Flags, set)
cerr := checkRequiredFlags(a.Flags, set)
context := NewContext(a, set, ctx)
if nerr != nil {
@ -341,8 +340,9 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
return nerr
}
cerr := checkRequiredFlags(a.Flags, set)
if cerr != nil {
ShowAppHelp(context)
ShowSubcommandHelp(context)
return cerr
}

@ -890,22 +890,13 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
expectedAnError bool
expectedFlagErrorPrinter bool
}{
{
// expectations:
// - empty input shows the help message
// - empty input explicitly does not error
testCase: "empty_input",
appRunInput: []string{""},
expectedHelpPrinter: true,
expectedAnError: false, // explicit false for readability (this is the default value)
},
{
// expectations:
// - empty input, when a required flag is present, shows the help message
// - empty input, when a required flag is present, errors
// - empty input, when a required flag is present, show the flag error message
testCase: "empty_input_with_required_flag",
appRunInput: []string{""},
appRunInput: []string{"command"},
flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
expectedHelpPrinter: true,
expectedAnError: true,
@ -966,12 +957,6 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
Command{
Name: "command",
Flags: test.flags,
Subcommands: []Command{
Command{
Name: "subcommand",
Flags: test.flags,
},
},
},
}

Loading…
Cancel
Save