MCPcopy
hub / github.com/urfave/cli / ExampleCommand_Run_commandHelp

Function ExampleCommand_Run_commandHelp

examples_test.go:151–195  ·  examples_test.go::ExampleCommand_Run_commandHelp
()

Source from the content-addressed store, hash-verified

149}
150
151func ExampleCommand_Run_commandHelp() {
152 cmd := &cli.Command{
153 Name: "greet",
154 Flags: []cli.Flag{
155 &cli.StringFlag{Name: "name", Value: "pat", Usage: "a name to say"},
156 },
157 Action: func(_ context.Context, cmd *cli.Command) error {
158 fmt.Fprintf(cmd.Root().Writer, "hello to %[1]q\n", cmd.String("name"))
159 return nil
160 },
161 Commands: []*cli.Command{
162 {
163 Name: "describeit",
164 Aliases: []string{"d"},
165 Usage: "use it to see a description",
166 Description: "This is how we describe describeit the function",
167 ArgsUsage: "[arguments...]",
168 Action: func(context.Context, *cli.Command) error {
169 fmt.Println("i like to describe things")
170 return nil
171 },
172 },
173 },
174 }
175
176 // Simulate the command line arguments
177 os.Args = []string{"greet", "h", "describeit"}
178
179 _ = cmd.Run(context.Background(), os.Args)
180 // Output:
181 // NAME:
182 // greet describeit - use it to see a description
183 //
184 // USAGE:
185 // greet describeit [options] [arguments...]
186 //
187 // DESCRIPTION:
188 // This is how we describe describeit the function
189 //
190 // OPTIONS:
191 // --help, -h show help
192 //
193 // GLOBAL OPTIONS:
194 // --name string a name to say (default: "pat")
195}
196
197func ExampleCommand_Run_noAction() {
198 cmd := &cli.Command{Name: "greet"}

Callers

nothing calls this directly

Calls 3

RootMethod · 0.95
StringMethod · 0.95
RunMethod · 0.95

Tested by

no test coverage detected