-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
51 lines (42 loc) · 1.83 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cli
import "context"
type (
// Command defines the minimal interface required to execute a CLI command.
Command interface {
Execute(ctx context.Context, args, dashedArgs []string) error
}
// CommandContext defines a way to propagate a custom context to child commands.
CommandContext interface {
Context(ctx context.Context) context.Context
}
// CommandDescription defines a way to set a description on the command.
// A short description is created from the first description line.
CommandDescription interface{ Description() string }
// CommandExamples defines a way to set command examples.
CommandExamples interface{ Examples() []string }
// CommandUsage defines a way to set the way to use the command.
CommandUsage interface{ Usage() string }
// CommandFlags defines the flagValue of the command.
CommandFlags interface{ Flags() []Flag }
// CommandPersistentFlags defines the persistent flags of the command.
CommandPersistentFlags interface{ PersistentFlags() []Flag }
// CommandHook defines some callback called during command lifecycle.
CommandHook interface{ Hook() *Hook }
// CommandPersistentHook defines some persistent callback called during command lifecycle.
// Differences between CommandHook and CommandPersistentHook is that executed command's
// hierarchy will also be called.
CommandPersistentHook interface{ PersistentHook() *PersistentHook }
// HookFunc defines the hook signature.
HookFunc func(ctx context.Context) error
// Hook defines callbacks to add custom behavior to the command lifecycle.
Hook struct {
BeforeCommandExecution HookFunc
AfterCommandExecution HookFunc
}
// PersistentHook defines callbacks to add custom behavior to the command lifecycle.
PersistentHook struct {
BeforeFlagsDefinition HookFunc
BeforeCommandExecution HookFunc
AfterCommandExecution HookFunc
}
)