This is a simple cobra cli quickstart project written in Go. The aim of the repo is to provide a starting point for a new Go cli project.
The project provides main.go and a cmd/root.go files that form a starting point for a cli. The cobra cli can the be used to create additional commands.
A Makefile is provided to test, build and verify the project. Additionally the Makefile will allow the project to be distributed as three separate binaries covering, Linux, MacOS and Windows.
The dependency management is fulfilled through go modules. The GO111MODULE
environment variable should be set to on
export GO111MODULE=on
To download the dependencies execute the dependencies
target. This will download the dependencies into the Go cache.
make dependencies
To vendor the dependencies into the location project execute the vendor-dependencies
target. This will download the dependencies into a vendor
directory within the project.
make vendor-dependencies
To remove the vendor directory execute the clean-dependencies
target. This will delete the vendor
directory.
make clean-dependencies
To build the project execute the build
target. The binary will be placed in a bin
directory.
make build
To execute the binary the following command can be executed at the root of the project.
./bin/cobra-cli-quickstart
To test the project execute the test
target.
make test
To build a distribution of the project execute the dist target. The default behaviour is to build linux, darwin and windows distributions.
Distributions are made up of a compressed tar file under the dist
directory.
make dist
To override the default list of distributions a variable called PLATFORMS
can be defined. The following example builds darwin and windows distributions
PLATFORMS="darwin windows" make dist
Individual distributions can be created by using the distribution name. For example darwin
, linux
or windows
can be built using the following commands.
make darwin
make linux
make windows
All of the binaries built into a directory structure under the bin
directory. The structure reflects the operating system and architecture.
For example darwin amd64 binaries are built into the following structure
cobra-cli-quickstart
|-- bin
|-- darwin
|-- amd64
|-- cobra-cli-quickstart
To clean the project execute the clean target. If the bin or dist directories were previously created then they will be deleted.
The cleaning of the vendor directory is handled by the clean-dependencies
make clean
The following is a brief list of additional targets that can be executed against the project.
make bootstrap
- Ensures that add tools are present in the build environment. For example
golint
.
- Ensures that add tools are present in the build environment. For example
make install
/make uninstall
- Installs or uninstalls the built binary into the
$GOPATH/bin
directory.
- Installs or uninstalls the built binary into the
make fmt
- Executes
go fmt
over the project.
- Executes
make benchmark
- Executes any benchmark tests against the project.
make check
- Executes
go fmt
andgolint
against the project.
- Executes
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to the project.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Trent Rosenbaum - Initial work - trentrosenbaum
See also the list of contributors who participated in this project.
This project is licensed under the ? License - see the LICENSE.md file for details
- List any people or projects that have inspiration this project