-
Notifications
You must be signed in to change notification settings - Fork 13
/
hello_example.go
67 lines (61 loc) · 1.9 KB
/
hello_example.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmdtree
import (
"github.com/ActiveState/cli/internal/captain"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runners/hello"
)
func newHelloCommand(prime *primer.Values) *captain.Command {
runner := hello.New(prime)
params := hello.NewParams()
cmd := captain.NewCommand(
// The command's name should not be localized as we want commands to behave consistently regardless of localization.
"_hello",
// The title is printed with title formatting when running the command. Leave empty to disable.
locale.Tl("hello_cmd_title", "Saying hello"),
// The description is shown on --help output
locale.Tl("hello_cmd_description", "An example command"),
prime,
[]*captain.Flag{
{
Name: "extra",
Shorthand: "e",
Description: locale.Tl(
"flag_state_hello_extra_description",
"Toggle extra info",
),
Value: ¶ms.Extra,
},
{
Name: "echo",
Description: locale.Tl(
"flag_state_hello_echo_description",
"Text to echo",
),
Value: ¶ms.Echo,
},
},
[]*captain.Argument{
{
Name: "name",
Description: locale.Tl(
"arg_state_hello_name_description",
"The name to say hello to",
),
Value: ¶ms.Name,
},
},
func(_ *captain.Command, _ []string) error {
return runner.Run(params)
},
)
// The group is used to group together commands in the --help output
cmd.SetGroup(UtilsGroup)
// Commands should support structured (JSON) output whenever possible.
cmd.SetSupportsStructuredOutput()
// Any new command should be marked unstable for the first release it goes out in.
cmd.SetUnstable(true)
// Certain commands like `state deploy` are there for backwards compatibility, but we don't want to show them in the --help output as they are not part of the happy path or our long term goals.
cmd.SetHidden(true)
return cmd
}