Template for Command Line Interface (CLI) tool in Go
Install goenv:
brew install goenvInstall Go:
# install go 1.22.5
goenv install 1.22.5
# to install latest Go version
goenv install latestConfigure project:
source configure.shOpen the project in Visual Studio Code:
code .go build ./...echo "John" > name.txt
./cli-go greet name.txt
./cli-go greet --language es name.txt
./cli-go greet -l bg name.txtOutput:
Hello, John!
Hola, John!
Здравей, John!go test -vgodocBrowse docs:
# this package
open http://localhost:6060/pkg/github.com/swiftsoftwaregroup/cli-go
# all packages
open http://localhost:6060/pkg/# create module
go mod init github.com/<username>/cli-go
# add packages
# see: https://cobra.dev
go get github.com/spf13/cobra
touch main.goTools:
go install golang.org/x/tools/cmd/godoc@latest