cli-go
Template for Command Line Interface (CLI) tool in Go
Development
Setup for macOS
Install goenv
:
brew install goenv
Install Go:
goenv install 1.22.5
goenv install latest
Work on macOS
Configure project:
source configure.sh
Open the project in Visual Studio Code:
code .
Build
go build ./...
Run
echo "John" > name.txt
./cli-go greet name.txt
./cli-go greet --language es name.txt
./cli-go greet -l bg name.txt
Output:
Hello, John!
Hola, John!
Здравей, John!
Test
go test -v
Generate Docs
godoc
Browse docs:
open http://localhost:6060/pkg/github.com/swiftsoftwaregroup/cli-go
open http://localhost:6060/pkg/
How to create a new project
go mod init github.com/<username>/cli-go
go get github.com/spf13/cobra
touch main.go
Tools:
go install golang.org/x/tools/cmd/godoc@latest