]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | package cli |
2 | ||
3 | import ( | |
4 | "github.com/posener/complete" | |
5 | ) | |
6 | ||
7 | // MockCommand is an implementation of Command that can be used for tests. | |
8 | // It is publicly exported from this package in case you want to use it | |
9 | // externally. | |
10 | type MockCommand struct { | |
11 | // Settable | |
12 | HelpText string | |
13 | RunResult int | |
14 | SynopsisText string | |
15 | ||
16 | // Set by the command | |
17 | RunCalled bool | |
18 | RunArgs []string | |
19 | } | |
20 | ||
21 | func (c *MockCommand) Help() string { | |
22 | return c.HelpText | |
23 | } | |
24 | ||
25 | func (c *MockCommand) Run(args []string) int { | |
26 | c.RunCalled = true | |
27 | c.RunArgs = args | |
28 | ||
29 | return c.RunResult | |
30 | } | |
31 | ||
32 | func (c *MockCommand) Synopsis() string { | |
33 | return c.SynopsisText | |
34 | } | |
35 | ||
36 | // MockCommandAutocomplete is an implementation of CommandAutocomplete. | |
37 | type MockCommandAutocomplete struct { | |
38 | MockCommand | |
39 | ||
40 | // Settable | |
41 | AutocompleteArgsValue complete.Predictor | |
42 | AutocompleteFlagsValue complete.Flags | |
43 | } | |
44 | ||
45 | func (c *MockCommandAutocomplete) AutocompleteArgs() complete.Predictor { | |
46 | return c.AutocompleteArgsValue | |
47 | } | |
48 | ||
49 | func (c *MockCommandAutocomplete) AutocompleteFlags() complete.Flags { | |
50 | return c.AutocompleteFlagsValue | |
51 | } | |
52 | ||
53 | // MockCommandHelpTemplate is an implementation of CommandHelpTemplate. | |
54 | type MockCommandHelpTemplate struct { | |
55 | MockCommand | |
56 | ||
57 | // Settable | |
58 | HelpTemplateText string | |
59 | } | |
60 | ||
61 | func (c *MockCommandHelpTemplate) HelpTemplate() string { | |
62 | return c.HelpTemplateText | |
63 | } |