{"id":25021052,"url":"https://github.com/excoriate/golang-cli-boilerplate","last_synced_at":"2025-04-28T14:24:30.899Z","repository":{"id":192559362,"uuid":"685109733","full_name":"Excoriate/golang-cli-boilerplate","owner":"Excoriate","description":"Golang CLI Boilerplate is a bulletproof Golang CLI template with batteries included 🔋","archived":false,"fork":false,"pushed_at":"2023-12-19T00:19:37.000Z","size":172,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T10:30:00.697Z","etag":null,"topics":["cli","devops","ecs","example","sre","tooling"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Excoriate.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-30T14:35:13.000Z","updated_at":"2024-07-30T14:18:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0adbec5-95e7-4557-97c2-2c84c9260dcb","html_url":"https://github.com/Excoriate/golang-cli-boilerplate","commit_stats":null,"previous_names":["excoriate/golang-cli-boilerplate"],"tags_count":5,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Excoriate%2Fgolang-cli-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Excoriate%2Fgolang-cli-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Excoriate%2Fgolang-cli-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Excoriate%2Fgolang-cli-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Excoriate","download_url":"https://codeload.github.com/Excoriate/golang-cli-boilerplate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251327873,"owners_count":21571832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","devops","ecs","example","sre","tooling"],"created_at":"2025-02-05T12:18:45.888Z","updated_at":"2025-04-28T14:24:30.880Z","avatar_url":"https://github.com/Excoriate.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang CLI Boilerplate 🛠️\n\nThis is a versatile and easy-to-use template for building a robust Golang CLI with [Cobra](https://github.com/spf13/cobra) and [Viper](https://github.com/spf13/viper). It comes with built-in AWS adapters via Golang SDK v2 and handy utilities.\n\n---\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/Excoriate/golang-cli-boilerplate)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser)\n[![Docker Build](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/docker-build.yml/badge.svg)](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/docker-build.yml)\n[![Go Build](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/go-build.yml/badge.svg)](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/go-build.yml)\n[![Go linter](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/go-ci-lint.yaml/badge.svg)](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/go-ci-lint.yaml)\n[![Go unit tests](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/go-ci-test.yml/badge.svg)](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/go-ci-test.yml)\n[![Lint Docker](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/docker-hadolint.yml/badge.svg)](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/docker-hadolint.yml)\n[![Yamllint GitHub Actions](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/yaml-linter.yml/badge.svg)](https://github.com/Excoriate/golang-cli-boilerplate/actions/workflows/yaml-linter.yml)\n\n---\n## Getting Started 🚦\nUse this repository as a [GitHub Template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) to create your own CLI:\n\n- [ ] Clone this repository and start adding your command and flag definitions. Utilize pre-installed AWS adapters and included utilities to kickstart your CLI development.\n- [ ] This template's CLI is called `golang-cli-boilerplate`. You can rename it by changing the name using your favourite tool, or just using our IDE with a simple `Ctrl+Shift+R` and replace all the occurrences of `golang-cli-boilerplate` with your new name (or including the org/`golang-cli-boilerplate`) if applicable.\n- [ ] Configure [PreCommit](https://pre-commit.com/) hooks by running `task pre-commit-init`. This will install the pre-commit hooks in your local repository.\n- [ ] Update the `LICENSE.md` file with your own license.\n- [ ] Verify that everything is working as expected:\n```bash\n# If you want to use the MakeFile included.\nmake lint\n\n# Or, if you're using Taskfile\ntask go-lint\n```\n- [ ] After this step, you should be able to run your CLI:\n```bash\n# TaskFile wraps the binary in a task, so you can run it like this:\ntask cli-run -- help\n\n# Or directly, just ensure you're building the binary first\ngo build -o \u003cmy-cli\u003e main.go\n\n# Or, with TaskFile\ntask cli-build\n```\n\u003e**NOTE**: This template includes a [MakeFile](Makefile) and a [TaskFile](Taskfile.yml) with the necessary (best practices) configuration to build and lint your CLI. Both tools include the same capability, so you can choose the one you prefer.\n\n---\n\n## 🔧 Release your CLI\nThe release of your CLI is done using [GoReleaser](https://goreleaser.com/). For MacOs, you can use [Homebrew](https://brew.sh/). This template already includes a `.goreleaser.yml` file with the necessary (best practices) configuration to release your CLI.\nIn addition, a [GitHub Action](.github/workflows/release.yml) is included to automate the release process.\n```yaml\n  goreleaser:\n    if: needs.release-please.outputs.releases_created == 'true'\n    permissions:\n      contents: write\n    needs:\n      - release-please\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3\n        with:\n          fetch-depth: 0\n      - name: Set up Go\n        uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4\n        with:\n          go-version: '1.20'\n      - name: Download Syft\n        uses: anchore/sbom-action/download-syft@422cb34a0f8b599678c41b21163ea6088edb2624 # v0.14.1\n      - name: Run GoReleaser\n        uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4\n        with:\n          distribution: goreleaser\n          version: latest\n          args: release --clean\n        env:\n          GITHUB_TOKEN: ${{secrets.GH_HOMEBREW_TOKEN}}\n\n```\n\u003e**NOTE**: In order to use the GitHub Action, you need to create a `GH_HOMEBREW_TOKEN` secret in your repository with enough permissions to read and write into the `tap` repository.\n\n\n---\n## 📚 Documentation\nDocumenting your CLI is relevant. This repository includes a [docs](docs/templates/) folder with a template for the documentation of your CLI. You can use it as a starting point for your own documentation. It includes:\n- 📃 `README.md` with a standard structure for a CLI repository.\n- 📃 `INSTALLATION.md` file with the installation instructions for your CLI.\n- 📃 `CONTRIBUTING.md` file with the instructions for contributing to your CLI.\n- 📃 `CODE_OF_CONDUCT.md` file with the code of conduct for your CLI.\n- 📃 `LICENSE.md` file with the license for your CLI.\n```bash\ntree -L 3  docs/\ndocs/\n├── about_docs.md\n└── templates\n    ├── CODE_OF_CONDUCT.md\n    ├── CONTRIBUTING.md\n    ├── INSTALLATION.md\n    ├── LICENSE\n    └── README.md\n```\n\u003e**NOTE**: It's recommended to move these files accordingly, nevertheless it's strongly encouraged to keep a concise documentation structure, keeping the `README.md` simple, concise, and store the more detailed documentation in the `docs` folder.\nFor more details about the document templates, see [this](docs/about_docs.md).\n\n---\n## Features 🧩\n\n* Out-of-the-box environment variable management 🌳\n* Auto-scan host environment variables for `AWS` and `Terraform` credentials 📄\n* Import env vars from dotfiles (`.env`) 📄\n* Leverages built-in AWS adapters ([Golang SDK v2](https://aws.github.io/aws-sdk-go-v2/))\n* Ready-to-use utilities for common tasks 🧰. See the [pkg](pkg) folder for more details.\n* Built-in [Docker](https://www.docker.com/) support 🐳\n* Out-of-the-box [GitHub Actions](https://docs.github.com/en/actions) workflows for CI/CD 🚀\n* Built-in [PreCommit](https://pre-commit.com/) hooks for linting and formatting 🧹\n* Out-of-the-box support for output data in `yaml`, `json` or `tables`🤖\n\n### Safely share the `cliClient` to `subCommands` 🤝\nOn each subcommand (at the parent level, which means, those that are in the top of your `pkg`), ensure you're implementing the `GetClient` function:\n```go\nfunc GetClient(cmd *cobra.Command) *cli.Client {\n\tctx := cmd.Context().Value(cliutils.GetCtxKey())\n\tif ctx == nil {\n\t\tlog.Fatal(\"Unable to get the client context.\")\n\t}\n\tclient, ok := ctx.(*cli.Client)\n\tif !ok {\n\t\tlog.Fatal(\"Unable to assert client.\")\n\t}\n\treturn client\n}\n```\n### Adapters 🧩\nAdapters are known also as `clients`. They can plug into the `cliClient` and provide additional functionality. This template includes a subcommand called `aws-ecs` in the `cmd/example` package. It's a subcommand that use the `aws` adapter to read the `ECS` clusters in your account. It's a good example of how to use the `cliClient` and the `aws` adapter. See [here](https://github.com/Excoriate/golang-cli-boilerplate/blob/4caff5eade39799fb3945e52d14f937251233e9a/cmd/example/aws.go#L68-L68)\n\n---\n\n## Tooling 🧑‍🔧\n\nThis template is equipped with an array of tools to maintain a high standard of code quality and accelerate the development process:\n\n* [Precommit](https://pre-commit.com/) framework for managing and maintaining multi-language pre-commit hooks\n* [Taskfile](https://taskfile.dev/#/) is a simpler way to automate tasks\n* [Makefile](https://www.gnu.org/software/make/) for managing build workflow\n* [GolangCI-linter](https://golangci-lint.run/) for consolidated linting to improve code quality\n* [GoReleaser](https://goreleaser.com/) for easy binary release management\n* [Docker](https://www.docker.com/) for containerization\n* [ShellCheck](https://www.shellcheck.net/) for shell script linting\n* [Release please](https://github.com/googleapis/release-please) for automated releases\n\u003e**NOTE**: For pre-commit, ensure you're running `task pre-commmit-init` to add the pre-configured hooks into your `git` hooks. This will ensure that the code is linted and formatted before committing it. Also, there are other linters included (yaml, docker, shell, md, etc.).\n\n---\n## Roadmap 🗓️\n* [ ] Add a built-in `GitHub` adapter.\n* [ ] Add a CLI for quickly bootstrapping a new CLI\n* [ ] Add an [OpenAI](https://openai.com/) adapter for generating CLI documentation and/or other purposes.\n\n## Contributing\nPlease read our [contributing guide](./CONTRIBUTING.md). All issues, pull requests and GitHub stars are welcome! Happy coding! 💻\n\n\n## Community\nFind me in:\n\n- 📧 [Email](mailto:alex_torres@outlook.com)\n- 🧳 [Linkedin](https://www.linkedin.com/in/alextorresruiz/)\n\n\n\u003ca href=\"https://github.com/Excoriate/golang-cli-boilerplate/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=Excoriate/golang-cli-boilerplate\" /\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexcoriate%2Fgolang-cli-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexcoriate%2Fgolang-cli-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexcoriate%2Fgolang-cli-boilerplate/lists"}