
"Hello, world!" example of Cobra with 100% code coverage
Note : "Cobra
" is an awesome framework of Go to help create CLI apps.
This repo is an example of Cobra's "Hello, world!
" with 100% code coverage.
Including the below to just say "Hello" to the world!
- CI
- Unit tests on Go v1.15 to the latest.
- Static analysis, security scan, lint and format check.
- Monthly vulnerability scan via CodeQL.
- Automated monthly update of
go.mod
and go.sum
on test-pass.
- Automated Homebrew release on release push.
Searching for the best practices of Cobra
We all know keeping 100% of code coverage is a myth. But as a Golang
and Cobra
beginner, we wanted a "Hello-world" example with 100% of coverage, which couldn't be found by googling for "golang
cobra
sample
example
hello
world
coverage
100%
".
This repo aims to find the best-practices of Cobra
by refactoring it on a moment-to-moment basis. But keeping the code coverage as high as possible and less complexity as possible.
- Therefore, this is a forever-WIP-repo.
So any PR for the better is welcome!! We will merge it as long as it passess the tests with 100% coverage and not a prank-kind PR.
Statuses

Note
-
This example app supports Homebrew installation. To know how it works see: .goreleaser.yml
brew install KEINOS/Hello-Cobra/hello-cobra
$ brew install KEINOS/Hello-Cobra/hello-cobra
==> Tapping keinos/hello-cobra
... **snip** ...
==> Installing hello-cobra from keinos/hello-cobra
... **snip** ...
$ hello-cobra --version
hello-cobra version 1.3.2-alpha (c3c9eab)
$ hello-cobra hello foo bar
Hello, foo and bar!
$ hello-cobra hello foo bar --reverse
!rab dna oof ,olleH
-
This package auto-detects the app version from the git
tag if the app was installed via go install
(on Go v1.16+) or go get -u
(on Go 1.15). Try:
# For Go 1.16 or above
cd /tmp
go install "github.com/KEINOS/Hello-Cobra/hello-cobra@latest"
hello-cobra --version
# Output: hello-cobra version v1.3.0
# For Go 1.15
cd /tmp
GO111MODULE="on" go get -u "github.com/KEINOS/Hello-Cobra/hello-cobra@latest"
hello-cobra --version
# Output: hello-cobra version v1.3.0
-
This repo updates monthly the go.mod
and go.sum
files if all the tests succeeds to run in all Go versions (Go v1.15~latest).
License
The repo itself is MIT License. (c) Copyright, Hello-Cobra Contributors.
BUT any app created from this repo as a template/boilerplate may have its willing license.