Boilerplate to kickstart creating a Go command-line tool.
Click the "Use this template" button.
Alternatively, create a new directory and clone the repo:
mkdir new-directory
cd new-directory
curl -fsSL https://github.com/johnsonshi/go-cli-boilerplate/archive/main.tar.gz | tar -xz --strip-components=1
Initialize go.mod
and go.sum
.
Note: Replace <your-github-username>
and <your-github-repo-name>
before running the following command:
rm go.mod go.sum
go mod init github.com/<your-github-username>/<your-github-repo-name>
go mod tidy
git init
git add -A
git status
git commit -s -m "Initial commit"
Build the command-line tool with the make
command using the Makefile
.
This builds an executable binary at ./bin/command
.
make build-cli
To run the command-line tool:
./bin/command
The command-line tool can be modified to suit your needs through changes to ./cmd/cli/root.go
and ./cmd/cli/subcommand.go
.
There are several GitHub Actions Workflows under the .github/workflows
directory.
These should kickstart builds and releases for your Go command-line tool.
Builds the command-line tool on each push to the main
branch.
When a git tag with the format v*
is pushed, the release workflow builds the command-line tool and creates a GitHub release.
E.g. A GitHub release is created when the tag v1.2.5
is pushed (conforms to the git tag format v*
).
When a git tag containing -alpha.
, -beta.
, -rc.
, or -nightly.
is pushed, a GitHub pre-release is created instead.
GitHub will point out that this release is identified as non-production ready.