Add before function to app
This commit is contained in:
parent
78d5f0dd40
commit
f7c1cd9a11
10
app.go
10
app.go
@ -20,6 +20,9 @@ type App struct {
|
|||||||
Commands []Command
|
Commands []Command
|
||||||
// List of flags to parse
|
// List of flags to parse
|
||||||
Flags []Flag
|
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
|
// The action to execute when no subcommands are specified
|
||||||
Action func(context *Context)
|
Action func(context *Context)
|
||||||
// Compilation date
|
// Compilation date
|
||||||
@ -93,6 +96,13 @@ func (a *App) Run(arguments []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.Before != nil {
|
||||||
|
err := a.Before(context)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
args := context.Args()
|
args := context.Args()
|
||||||
if args.Present() {
|
if args.Present() {
|
||||||
name := args.First()
|
name := args.First()
|
||||||
|
Loading…
Reference in New Issue
Block a user