github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/cmd/state/internal/cmdtree/hello_example.go (about) 1 package cmdtree 2 3 import ( 4 "github.com/ActiveState/cli/internal/captain" 5 "github.com/ActiveState/cli/internal/locale" 6 "github.com/ActiveState/cli/internal/primer" 7 "github.com/ActiveState/cli/internal/runners/hello" 8 ) 9 10 func newHelloCommand(prime *primer.Values) *captain.Command { 11 runner := hello.New(prime) 12 13 params := hello.NewParams() 14 15 cmd := captain.NewCommand( 16 // The command's name should not be localized as we want commands to behave consistently regardless of localization. 17 "_hello", 18 // The title is printed with title formatting when running the command. Leave empty to disable. 19 locale.Tl("hello_cmd_title", "Saying hello"), 20 // The description is shown on --help output 21 locale.Tl("hello_cmd_description", "An example command"), 22 prime, 23 []*captain.Flag{ 24 { 25 Name: "extra", 26 Shorthand: "e", 27 Description: locale.Tl( 28 "flag_state_hello_extra_description", 29 "Toggle extra info", 30 ), 31 Value: ¶ms.Extra, 32 }, 33 { 34 Name: "echo", 35 Description: locale.Tl( 36 "flag_state_hello_echo_description", 37 "Text to echo", 38 ), 39 Value: ¶ms.Echo, 40 }, 41 }, 42 []*captain.Argument{ 43 { 44 Name: "name", 45 Description: locale.Tl( 46 "arg_state_hello_name_description", 47 "The name to say hello to", 48 ), 49 Value: ¶ms.Name, 50 }, 51 }, 52 func(_ *captain.Command, _ []string) error { 53 return runner.Run(params) 54 }, 55 ) 56 57 // The group is used to group together commands in the --help output 58 cmd.SetGroup(UtilsGroup) 59 // Commands should support structured (JSON) output whenever possible. 60 cmd.SetSupportsStructuredOutput() 61 // Any new command should be marked unstable for the first release it goes out in. 62 cmd.SetUnstable(true) 63 // 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. 64 cmd.SetHidden(true) 65 66 return cmd 67 }