add update integration with the help output
This commit is contained in:
parent
550ed20ea4
commit
746866c10d
11
app.go
11
app.go
@ -209,11 +209,6 @@ func (a *App) Run(arguments []string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if cerr != nil {
|
||||
ShowAppHelp(context)
|
||||
return cerr
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if a.OnUsageError != nil {
|
||||
err := a.OnUsageError(context, err, false)
|
||||
@ -235,6 +230,12 @@ func (a *App) Run(arguments []string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if cerr != nil {
|
||||
fmt.Fprintln(a.Writer, cerr)
|
||||
ShowAppHelp(context)
|
||||
return cerr
|
||||
}
|
||||
|
||||
if a.After != nil {
|
||||
defer func() {
|
||||
if afterErr := a.After(context); afterErr != nil {
|
||||
|
44
app_test.go
44
app_test.go
@ -878,21 +878,41 @@ func TestAppNoHelpFlag(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAppHelpPrinter(t *testing.T) {
|
||||
oldPrinter := HelpPrinter
|
||||
defer func() {
|
||||
HelpPrinter = oldPrinter
|
||||
}()
|
||||
|
||||
var wasCalled = false
|
||||
HelpPrinter = func(w io.Writer, template string, data interface{}) {
|
||||
wasCalled = true
|
||||
tdata := []struct {
|
||||
testCase string
|
||||
flags []Flag
|
||||
}{
|
||||
{
|
||||
testCase: "prints_help_and_does_not_error",
|
||||
},
|
||||
{
|
||||
testCase: "prints_help_and_does_not_error_when_required_flag_is_present",
|
||||
flags: []Flag{StringFlag{Name: "flag", Required: true}},
|
||||
},
|
||||
}
|
||||
for _, test := range tdata {
|
||||
t.Run(test.testCase, func(t *testing.T) {
|
||||
oldPrinter := HelpPrinter
|
||||
defer func() {
|
||||
HelpPrinter = oldPrinter
|
||||
}()
|
||||
|
||||
app := NewApp()
|
||||
app.Run([]string{"-h"})
|
||||
var wasCalled = false
|
||||
HelpPrinter = func(w io.Writer, template string, data interface{}) {
|
||||
wasCalled = true
|
||||
}
|
||||
|
||||
if wasCalled == false {
|
||||
t.Errorf("Help printer expected to be called, but was not")
|
||||
app := NewApp()
|
||||
app.Flags = test.flags
|
||||
err := app.Run([]string{"testCommand", "-h"})
|
||||
|
||||
if wasCalled == false {
|
||||
t.Errorf("Help printer expected to be called, but was not")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("did not expected an error, but there was one: %s", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,13 +288,6 @@ func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
|
||||
}
|
||||
|
||||
func checkRequiredFlags(flags []Flag, set *flag.FlagSet) error {
|
||||
// If the help flag is included then none of the other flags are required.
|
||||
for _, f := range flags {
|
||||
if f.GetName() == "help" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
visited := make(map[string]bool)
|
||||
set.Visit(func(f *flag.Flag) {
|
||||
visited[f.Name] = true
|
||||
|
Loading…
Reference in New Issue
Block a user