The cobra Package II

Let’s add commands to our cobra package.

Adding command-line flags

We are going to create two global command-line flags and one command-line flag that is attached to a given command (two) and is not supported by the other two commands. Global command-line flags are defined in the ./cmd/root.go file. We are going to define two global flags named directory, which is a string, and depth, which is an unsigned integer.

Both global flags are defined in the init() function of ./cmd/root.go.

Get hands-on with 1400+ tech skills courses.