Skip to content

Commit

Permalink
Rename App.UnknownFlagHandler to App.InvalidFlagAccessHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Aug 8, 2022
1 parent e948202 commit 4a11183
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ type App struct {
CommandNotFound CommandNotFoundFunc
// Execute this function if a usage error occurs
OnUsageError OnUsageErrorFunc
// Execute this function when an unknown flag is accessed from the context
UnknownFlagHandler UnknownFlagFunc
// Execute this function when an invalid flag is accessed from the context
InvalidFlagAccessHandler InvalidFlagAccessFunc
// Compilation date
Compiled time.Time
// List of all authors who contributed
Expand Down
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (cCtx *Context) checkRequiredFlags(flags []Flag) requiredFlagsErr {
}

func (cCtx *Context) onUnknownFlag(name string) {
if cCtx.App != nil && cCtx.App.UnknownFlagHandler != nil {
cCtx.App.UnknownFlagHandler(cCtx, name)
if cCtx.App != nil && cCtx.App.InvalidFlagAccessHandler != nil {
cCtx.App.InvalidFlagAccessHandler(cCtx, name)
}
}

Expand Down
8 changes: 4 additions & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ func TestContext_Value(t *testing.T) {
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)
var flagName string
app := &App{
UnknownFlagHandler: func(_ *Context, name string) {
InvalidFlagAccessHandler: func(_ *Context, name string) {
flagName = name
},
}
Expand Down Expand Up @@ -271,11 +271,11 @@ func TestContext_Set(t *testing.T) {
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)
var flagName string
app := &App{
UnknownFlagHandler: func(_ *Context, name string) {
InvalidFlagAccessHandler: func(_ *Context, name string) {
flagName = name
},
}
Expand Down
4 changes: 2 additions & 2 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type CommandNotFoundFunc func(*Context, string)
// is displayed and the execution is interrupted.
type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error

// UnknownFlagFunc is executed when an unknown flag is accessed from the context.
type UnknownFlagFunc func(*Context, string)
// InvalidFlagAccessFunc is executed when an invalid flag is accessed from the context.
type InvalidFlagAccessFunc func(*Context, string)

// ExitErrHandlerFunc is executed if provided in order to handle exitError values
// returned by Actions and Before/After functions.
Expand Down

0 comments on commit 4a11183

Please sign in to comment.