| 149 | } |
| 150 | |
| 151 | func 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 | |
| 197 | func ExampleCommand_Run_noAction() { |
| 198 | cmd := &cli.Command{Name: "greet"} |