golang project template for building CLI
git clone https://github.com/mpppk/cli-template your_awesome_tool
- Replace all strings
cli-template
in this repository toyour_awesome_tool
Click "Use this template" button on GitHub project page.
/cmd
includes golang files which implements command and sub commands./domain
includes golang files which implements domain model. This package should not depend on other layers./handler
includes golang files which implements handlers of http request./usecase
includes golang files which implements application use cases. This package is only allowed to depend on domain layer.
/util
includes golang files which implements utilities. All layers can depend on this package. This package should not depend on other packages./scripts
includes scripts/testdata
includes data files for tests. (see https://golang.org/cmd/go/#hdr-Test_packages)
For more detail, see golang-standards/project-layout.
If you want to create new sub command, Add new go file to /cmd
.
For more details, see spf13/cobra.
Use Makefile.
Use golang.org/x/xerrors.
Write godoc(example code) or Example test(example code).
Don't write test in same package, instead put to package-name_test
package.
For example, test of domain/sum.go is in domain_test
package, not domain
package.
To use unexported variables or functions in test, expose these by export_test.go
file.
(ex. /internal/option/root_export_test.go)
For more details, see this article(Japanese).
Recommended way is to wrap cobra.Command instance by func (unlike the code generated by cobra add). For example, see cmd/sum_test.go.
This template depends spf13/afero.
afero.OsFs
is used in packages and afero.MemMapFs
is used in tests.
For example, see cmd/sum_test.go#TestSumWithOutFile
Auto release via Circle CI powered by goreleaser
Create version tag (e.g. v0.0.1) and push to GitHub.
Then goreleaser will release the new version on Circle CI.
(Before push tag, you must provide GitHub token to Circle CI as environment variable)
For more details, see my article (Japanese).
$ docker build -t cli-template .
...
$ docker run cli-template sum 1 2
3
This template includes .circleci/config.yml.
This template includes appveyor.yml.
Makefile includes codecov task which send coverage to CodeCov.
Circle CI also send coverage to CodeCov by its job.
This template includes renovate.json.
Download from GitHub Releases
Download from GitHub Releases
Write usage of your awesome tool here