diff --git a/app.go b/app.go index 807ae83..a614236 100644 --- a/app.go +++ b/app.go @@ -20,6 +20,9 @@ type App struct { Commands []Command // List of flags to parse Flags []Flag + // An action to execute before any subcommands are run, but after the context is ready + // If a non-nil error is returned, no subcommands are run + Before func(context *Context) error // The action to execute when no subcommands are specified Action func(context *Context) // Compilation date @@ -93,6 +96,13 @@ func (a *App) Run(arguments []string) error { return nil } + if a.Before != nil { + err := a.Before(context) + if err != nil { + return err + } + } + args := context.Args() if args.Present() { name := args.First()