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

Function ExampleCommand_Run_subcommand

examples_test.go:46–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46func ExampleCommand_Run_subcommand() {
47 cmd := &cli.Command{
48 Name: "say",
49 Commands: []*cli.Command{
50 {
51 Name: "hello",
52 Aliases: []string{"hi"},
53 Usage: "use it to see a description",
54 Description: "This is how we describe hello the function",
55 Commands: []*cli.Command{
56 {
57 Name: "english",
58 Aliases: []string{"en"},
59 Usage: "sends a greeting in english",
60 Description: "greets someone in english",
61 Flags: []cli.Flag{
62 &cli.StringFlag{
63 Name: "name",
64 Value: "Bob",
65 Usage: "Name of the person to greet",
66 },
67 },
68 Action: func(_ context.Context, cmd *cli.Command) error {
69 fmt.Println("Hello,", cmd.String("name"))
70 return nil
71 },
72 },
73 },
74 },
75 },
76 }
77
78 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
79 defer cancel()
80
81 // Simulate the command line arguments
82 os.Args = []string{"say", "hi", "english", "--name", "Jeremy"}
83
84 _ = cmd.Run(ctx, os.Args)
85 // Output:
86 // Hello, Jeremy
87}
88
89func ExampleCommand_Run_appHelp() {
90 cmd := &cli.Command{

Callers

nothing calls this directly

Calls 2

StringMethod · 0.95
RunMethod · 0.95

Tested by

no test coverage detected