Cobra Command Line using Go

The Go programming language is an open source project to make programmers more productive.
In the following blog post I assume you already have the Go environment setup.
Previously we have created a Hello World application.
The next step is to create a command line application.
The example below covers the basics of using Cobra
Go Installation
- Confirm Go is installed
If it is not installed check out a previous post to install Go in Linux
Development setup
With go already installed, the setup requires a couple more steps
- Create a directory for your code
- Initialise the location where the module can be found
-
Make the go home directory
-
Initialise the hello directory
- The directory should now look like this:
Install Cobra
- We can use Go to download and build a local
Cobra
binary
-
The binary for
Cobra
will now be available in theGo
bin path. -
The directory should now look like this:
Integrate Cobra
- Add
Cobra
to the existing app
- The directory should now look like this:
- Build the application
-
The build command will produce an application based on the folder name
-
Run the code hello application
- The application output should be as per below: