Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
}
}

if err = runFlagActions(cCtx, a.Flags); err != nil {
return err
}

var c *Command
args := cCtx.Args()
if args.Present() {
Expand Down Expand Up @@ -523,6 +527,10 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
}
}

if err = runFlagActions(cCtx, a.Flags); err != nil {
return err
}

args := cCtx.Args()
if args.Present() {
name := args.First()
Expand Down Expand Up @@ -646,6 +654,26 @@ func (a *App) argsWithDefaultCommand(oldArgs Args) Args {
return oldArgs
}

func runFlagActions(c *Context, fs []Flag) error {
for _, f := range fs {
isSet := false
for _, name := range f.Names() {
if c.IsSet(name) {
isSet = true
break
}
}
if isSet {
if af, ok := f.(ActionableFlag); ok {
if err := af.RunAction(c); err != nil {
return err
}
}
}
}
return nil
}

// Author represents someone who has contributed to a cli project.
type Author struct {
Name string // The Authors name
Expand Down
Loading