December 2021
Intermediate to advanced
510 pages
11h 20m
English
After initializing the application, use the Cobra generator to add subcommands to it. The generator includes a file in the cmd directory for each subcommand. Each file includes boilerplate code for the subcommand. It also adds the subcommand to its parent, forming the tree-like structure.
Add a new subcommand called hosts to your application to manage hosts in the hosts list. By default, Cobra adds this subcommand to the root command:
| | $ cobra add hosts |
| | Using config file: /home/ricardo/.cobra.yaml |
| | hosts created at /home/ricardo/pragprog.com/rggo/cobra/pScan |
At this point, your application directory looks like this:
| | $ tree |
| | . |
| | ├── cmd |
| | │ ├── hosts.go |
| | │ └── root.go |
| | ├── ... |
Read now
Unlock full access