POC of a CLI project using Golang inspired from this article.
- Golang installed (go1.15 or newer)
- Cobra library (
go get -u github.com/spf13/cobra/cobra
) - Any code editor of your choice
At the repository root
run:
go install my-cli
Then, the my-cli
command should be recognized on your terminal.
Note: If my-cli
is not recognized by the terminal, please run:
export PATH=$PATH:$(go env GOPATH)/bin
...or check your $HOME/go/bin directory
if the my-cli
bin is there).
Will return SUCCESS if username
and password
flags are the same.
my-cli login -u="username" -p = "password"
Will return the sum of all numbers used as arguments.
my-cli add 1 2 3 4
Will return the sum of all even numbers used as arguments.
my-cli add even 1 2 3 4
Will return the sum of all odd numbers used as arguments.
my-cli add odd 1 2 3 4
Will create something with the specified arg <name>
using the flag --env-from
:
my-cli create <name> --env-from="dev"