...

/

Comparing Cobra to Alternatives

Comparing Cobra to Alternatives

Let's install Cobra and learn how Cobra can be used either as a library or as an application generator.

We will compare Cobra with some alternatives ways to parse command-line programs including the built-in ways Go provides as well as other third-party command-line parsing solutions.

Installing Cobra

First, we need to install Cobra. The official instructions recommend using the following command:

go get -u github.com/spf13/cobra/cobra

Unfortunately, this hangs indefinitely for me using Go 1.13.1. However, this command works:

go get -u github.com/spf13/cobra/cobra/...

Try the above commands in the following terminal.

Terminal 1
Terminal
Loading...

Cobra as a library

Once Cobra is installed, we can import it as a library into our application:

import "github.com/spf13/cobra"

At this point, we can start using ...