cleanup subcommand and specs
This commit is contained in:
parent
300288670f
commit
2299852c3c
4
app.go
4
app.go
@ -327,7 +327,6 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
set.SetOutput(ioutil.Discard)
|
set.SetOutput(ioutil.Discard)
|
||||||
err = set.Parse(ctx.Args().Tail())
|
err = set.Parse(ctx.Args().Tail())
|
||||||
nerr := normalizeFlags(a.Flags, set)
|
nerr := normalizeFlags(a.Flags, set)
|
||||||
cerr := checkRequiredFlags(a.Flags, set)
|
|
||||||
context := NewContext(a, set, ctx)
|
context := NewContext(a, set, ctx)
|
||||||
|
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
@ -341,8 +340,9 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cerr := checkRequiredFlags(a.Flags, set)
|
||||||
if cerr != nil {
|
if cerr != nil {
|
||||||
ShowAppHelp(context)
|
ShowSubcommandHelp(context)
|
||||||
return cerr
|
return cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
app_test.go
17
app_test.go
@ -890,22 +890,13 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
expectedAnError bool
|
expectedAnError bool
|
||||||
expectedFlagErrorPrinter 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:
|
// expectations:
|
||||||
// - empty input, when a required flag is present, shows the help message
|
// - 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, errors
|
||||||
// - empty input, when a required flag is present, show the flag error message
|
// - empty input, when a required flag is present, show the flag error message
|
||||||
testCase: "empty_input_with_required_flag",
|
testCase: "empty_input_with_required_flag",
|
||||||
appRunInput: []string{""},
|
appRunInput: []string{"command"},
|
||||||
flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
expectedHelpPrinter: true,
|
expectedHelpPrinter: true,
|
||||||
expectedAnError: true,
|
expectedAnError: true,
|
||||||
@ -966,12 +957,6 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
Command{
|
Command{
|
||||||
Name: "command",
|
Name: "command",
|
||||||
Flags: test.flags,
|
Flags: test.flags,
|
||||||
Subcommands: []Command{
|
|
||||||
Command{
|
|
||||||
Name: "subcommand",
|
|
||||||
Flags: test.flags,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user