https://github.com/keinos/hello-cobra
✅ Hello, world! sample/example of Cobra in Golang with a 100% coverage test.
https://github.com/keinos/hello-cobra
cobra go golang hello-world hello-world-for-beginner helloworld helloworld-demo
Last synced: 5 months ago
JSON representation
✅ Hello, world! sample/example of Cobra in Golang with a 100% coverage test.
- Host: GitHub
- URL: https://github.com/keinos/hello-cobra
- Owner: KEINOS
- License: mit
- Created: 2020-11-02T11:14:50.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-02T15:39:34.000Z (over 2 years ago)
- Last Synced: 2025-03-31T01:13:26.189Z (6 months ago)
- Topics: cobra, go, golang, hello-world, hello-world-for-beginner, helloworld, helloworld-demo
- Language: Go
- Homepage:
- Size: 208 KB
- Stars: 19
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
[](https://github.com/KEINOS/dev-go/actions/workflows/go-versions.yml "Supported versions")
[](https://pkg.go.dev/github.com/KEINOS/Hello-Cobra#section-documentation "Read generated documentation of the app")# "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](https://cobra.dev/)'s "`Hello, world!`" with 100% code coverage__.
Including the below to just say "Hello" to the world!
- [CI](./github/workflows/)
- 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](https://github.com/KEINOS/homebrew-Hello-Cobra) 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%`](https://www.google.com/search?q=%22golang%22+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](https://en.wikipedia.org/wiki/Work_in_progress)-repo.
So any [PR](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) 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.
- Branch to PR: `main`## Statuses
[](https://github.com/KEINOS/Hello-Cobra/actions/workflows/platform-test.yaml)
[](https://github.com/KEINOS/Hello-Cobra/actions/workflows/version-tests.yaml)
[](https://github.com/KEINOS/Hello-Cobra/actions/workflows/golangci-lint.yaml)
[](https://codecov.io/gh/KEINOS/Hello-Cobra "View details on CodeCov.IO")
[](https://goreportcard.com/report/github.com/KEINOS/Hello-Cobra "View on Go Report Card")
[](https://github.com/KEINOS/Hello-Cobra/actions/workflows/codeQL-analysis.yaml "Vulnerability Scan")## Note
- This example app supports Homebrew installation. To know how it works see: [.goreleaser.yml](./.goreleaser.yml)
```bash
brew install KEINOS/Hello-Cobra/hello-cobra
``````shellsession
$ 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:
```bash
# 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
``````bash
# 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](https://github.com/KEINOS/Hello-Cobra/graphs/contributors).
BUT any app created from this repo as a template/boilerplate may have its willing license.