remove showFlagError, we can use the help printer assertion to accomplish the same goal
This commit is contained in:
parent
386b379d19
commit
9438aba3b8
6
app.go
6
app.go
@ -23,8 +23,6 @@ var (
|
||||
errInvalidActionType = NewExitError("ERROR invalid Action type. "+
|
||||
fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+
|
||||
fmt.Sprintf("See %s", appActionDeprecationURL), 2)
|
||||
|
||||
showFlagError printerFunc = fmt.Fprintln
|
||||
)
|
||||
|
||||
// App is the main structure of a cli application. It is recommended that
|
||||
@ -235,7 +233,7 @@ func (a *App) Run(arguments []string) (err error) {
|
||||
|
||||
cerr := checkRequiredFlags(a.Flags, set)
|
||||
if cerr != nil {
|
||||
showFlagError(a.Writer, cerr)
|
||||
fmt.Fprintln(a.Writer, cerr)
|
||||
ShowAppHelp(context)
|
||||
return cerr
|
||||
}
|
||||
@ -366,7 +364,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
||||
|
||||
cerr := checkRequiredFlags(a.Flags, set)
|
||||
if cerr != nil {
|
||||
showFlagError(a.Writer, cerr)
|
||||
fmt.Fprintln(a.Writer, cerr)
|
||||
ShowSubcommandHelp(context)
|
||||
return cerr
|
||||
}
|
||||
|
14
app_test.go
14
app_test.go
@ -913,17 +913,6 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
||||
}
|
||||
for _, test := range tdata {
|
||||
t.Run(test.testCase, func(t *testing.T) {
|
||||
// setup - undo showFlagError mock when finished
|
||||
oldShowError := showFlagError
|
||||
defer func() {
|
||||
showFlagError = oldShowError
|
||||
}()
|
||||
// setup - mock showFlagError
|
||||
var showFlagErrorWasCalled = false
|
||||
showFlagError = func(writer io.Writer, err ...interface{}) (int, error) {
|
||||
showFlagErrorWasCalled = true
|
||||
return 0, nil
|
||||
}
|
||||
// setup - undo HelpPrinter mock when finished
|
||||
oldPrinter := HelpPrinter
|
||||
defer func() {
|
||||
@ -948,9 +937,6 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
||||
if test.expectedAnError && err == nil {
|
||||
t.Errorf("expected an error, but there was none")
|
||||
}
|
||||
if test.expectedAnError && showFlagErrorWasCalled == false {
|
||||
t.Errorf("showFlagError expected to be called, but was not")
|
||||
}
|
||||
if !test.expectedAnError && err != nil {
|
||||
t.Errorf("did not expected an error, but there was one: %s", err)
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
||||
|
||||
cerr := checkRequiredFlags(c.Flags, set)
|
||||
if cerr != nil {
|
||||
showFlagError(context.App.Writer, cerr)
|
||||
fmt.Fprintln(context.App.Writer, cerr)
|
||||
ShowCommandHelp(context, c.Name)
|
||||
return cerr
|
||||
}
|
||||
@ -273,7 +273,7 @@ func reorderArgs(args []string) []string {
|
||||
}
|
||||
|
||||
func translateShortOptions(set *flag.FlagSet, flagArgs Args) []string {
|
||||
allCharsFlags := func (s string) bool {
|
||||
allCharsFlags := func(s string) bool {
|
||||
for i := range s {
|
||||
f := set.Lookup(string(s[i]))
|
||||
if f == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user