A simple cobra example

In this section, we are going to implement a simple command-line utility using cobra and the ~/go/bin/cobra tool that comes with the package. If you execute ~/go/bin/cobra without any command-line arguments, you will get the following output:

$ ~/go/bin/cobra
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.
    
Usage:
  cobra [command]
    
Available Commands:
  add         Add a command to a Cobra Application
  help        Help about any command
  init        Initialize a Cobra Application
    
Flags:
  -a, --author string    author name for copyright attribution (default "YOUR NAME")
      --config string    config file (default is $HOME/.cobra.yaml)
  -h, --help help for ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.