Rename App.UnknownFlagHandler to App.InvalidFlagAccessHandler

main
Ilia Choly 2 years ago committed by Dan Buch
parent 6331815fae
commit e19a34c3c2
Signed by: meatballhat
GPG Key ID: A12F782281063434

@ -78,8 +78,8 @@ type App struct {
CommandNotFound CommandNotFoundFunc CommandNotFound CommandNotFoundFunc
// Execute this function if a usage error occurs // Execute this function if a usage error occurs
OnUsageError OnUsageErrorFunc OnUsageError OnUsageErrorFunc
// Execute this function when an unknown flag is accessed from the context // Execute this function when an invalid flag is accessed from the context
UnknownFlagHandler UnknownFlagFunc InvalidFlagAccessHandler InvalidFlagAccessFunc
// Compilation date // Compilation date
Compiled time.Time Compiled time.Time
// List of all authors who contributed // List of all authors who contributed

@ -47,7 +47,7 @@ func (cCtx *Context) NumFlags() int {
// Set sets a context flag to a value. // Set sets a context flag to a value.
func (cCtx *Context) Set(name, value string) error { func (cCtx *Context) Set(name, value string) error {
if cCtx.flagSet.Lookup(name) == nil { if cCtx.flagSet.Lookup(name) == nil {
cCtx.onUnknownFlag(name) cCtx.onInvalidFlag(name)
} }
return cCtx.flagSet.Set(name, value) return cCtx.flagSet.Set(name, value)
} }
@ -161,7 +161,7 @@ func (cCtx *Context) lookupFlagSet(name string) *flag.FlagSet {
return c.flagSet return c.flagSet
} }
} }
cCtx.onUnknownFlag(name) cCtx.onInvalidFlag(name)
return nil return nil
} }
@ -193,9 +193,9 @@ func (cCtx *Context) checkRequiredFlags(flags []Flag) requiredFlagsErr {
return nil return nil
} }
func (cCtx *Context) onUnknownFlag(name string) { func (cCtx *Context) onInvalidFlag(name string) {
if cCtx.App != nil && cCtx.App.UnknownFlagHandler != nil { if cCtx.App != nil && cCtx.App.InvalidFlagAccessHandler != nil {
cCtx.App.UnknownFlagHandler(cCtx, name) cCtx.App.InvalidFlagAccessHandler(cCtx, name)
} }
} }

@ -150,11 +150,11 @@ func TestContext_Value(t *testing.T) {
expect(t, c.Value("unknown-flag"), nil) expect(t, c.Value("unknown-flag"), nil)
} }
func TestContext_Value_UnknownFlagHandler(t *testing.T) { func TestContext_Value_InvalidFlagAccessHandler(t *testing.T) {
set := flag.NewFlagSet("test", 0) set := flag.NewFlagSet("test", 0)
var flagName string var flagName string
app := &App{ app := &App{
UnknownFlagHandler: func(_ *Context, name string) { InvalidFlagAccessHandler: func(_ *Context, name string) {
flagName = name flagName = name
}, },
} }
@ -271,11 +271,11 @@ func TestContext_Set(t *testing.T) {
expect(t, c.IsSet("int"), true) expect(t, c.IsSet("int"), true)
} }
func TestContext_Set_StrictLookup(t *testing.T) { func TestContext_Set_InvalidFlagAccessHandler(t *testing.T) {
set := flag.NewFlagSet("test", 0) set := flag.NewFlagSet("test", 0)
var flagName string var flagName string
app := &App{ app := &App{
UnknownFlagHandler: func(_ *Context, name string) { InvalidFlagAccessHandler: func(_ *Context, name string) {
flagName = name flagName = name
}, },
} }

@ -23,8 +23,8 @@ type CommandNotFoundFunc func(*Context, string)
// is displayed and the execution is interrupted. // is displayed and the execution is interrupted.
type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error
// UnknownFlagFunc is executed when an unknown flag is accessed from the context. // InvalidFlagAccessFunc is executed when an invalid flag is accessed from the context.
type UnknownFlagFunc func(*Context, string) type InvalidFlagAccessFunc func(*Context, string)
// ExitErrHandlerFunc is executed if provided in order to handle exitError values // ExitErrHandlerFunc is executed if provided in order to handle exitError values
// returned by Actions and Before/After functions. // returned by Actions and Before/After functions.

Loading…
Cancel
Save