{"id":37856734,"url":"https://github.com/oncilla/boa","last_synced_at":"2026-01-16T16:27:50.249Z","repository":{"id":57545650,"uuid":"271846091","full_name":"oncilla/boa","owner":"oncilla","description":"A venom-free generator for cobra applications","archived":false,"fork":false,"pushed_at":"2020-10-14T17:45:24.000Z","size":107,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T17:59:01.774Z","etag":null,"topics":["cli","cobra","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oncilla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-12T16:43:28.000Z","updated_at":"2021-02-11T20:33:11.000Z","dependencies_parsed_at":"2022-09-26T18:31:55.129Z","dependency_job_id":null,"html_url":"https://github.com/oncilla/boa","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/oncilla/boa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncilla%2Fboa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncilla%2Fboa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncilla%2Fboa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncilla%2Fboa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oncilla","download_url":"https://codeload.github.com/oncilla/boa/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oncilla%2Fboa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","cobra","golang"],"created_at":"2026-01-16T16:27:49.610Z","updated_at":"2026-01-16T16:27:50.232Z","avatar_url":"https://github.com/oncilla.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# boa - all snake, no venom\n[![Documentation](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white)](https://pkg.go.dev/mod/github.com/oncilla/boa)\n[![Go](https://img.shields.io/github/workflow/status/oncilla/boa/Go)](https://github.com/Oncilla/boa/actions?query=workflow%3AGo)\n[![Go Report Card](https://goreportcard.com/badge/github.com/oncilla/boa)](https://goreportcard.com/report/github.com/oncilla/boa)\n[![GitHub issues](https://img.shields.io/github/issues/oncilla/boa/help%20wanted.svg?label=help%20wanted\u0026color=purple)](https://github.com/oncilla/boa/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)\n[![GitHub issues](https://img.shields.io/github/issues/oncilla/boa/good%20first%20issue.svg?label=good%20first%20issue\u0026color=purple)](https://github.com/oncilla/boa/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)\n[![Release](https://img.shields.io/github/release-pre/oncilla/boa.svg)](https://github.com/oncilla/boa/releases)\n[![License](https://img.shields.io/github/license/oncilla/boa.svg?maxAge=2592000)](https://github.com/oncilla/boa/blob/master/LICENSE)\n\n\nA venom-free generator for cobra applications.\n\n## Installation\n\n```txt\ngo get -u github.com/oncilla/boa/cmd/boa\n```\n\n## Docker\n\nIf you prefer using docker instead:\n\n```txt\nWORKDIR=$(pwd)/path/to/application\ndocker run \\\n    -v $WORKDIR/:/workdir \\\n    --user \"$(id -u):$(id -g)\" \\\n    docker.pkg.github.com/oncilla/boa/boa:latest\n```\n\n## Getting started\n\n`boa` proposes a different layout than what `cobra` proposes as a [typical\nstructure](https://github.com/spf13/cobra#getting-started).\n\nThe commands all live in main package, alongside the main function.\n\n```\ncmd/my-app/\n├── my-app.go      # main function\n├── completion.go  # completion command\n└── version.go     # version command\n```\n\nThe commands should be fairly slim and only take care of checking flags and\ninitializing the application. Business logic should not go here, but move to\na separate package to ensure it is decoupled from the CLI, reusable and has\nno access to global values.\n\nWhere you put it is up to you, just try to have the main package as slim as\npossible.\n\n### Initializing an application\n\nWith boa, your project can have one or multiple cobra based applications.\nThe simplest approach is to have the `main` package in the project root.\n\n```txt\nboa init my-app\n```\n\nThis creates a runnable cobra application skeleton. Try it out with:\n\n```txt\ngo run *.go --help\n```\n\nThe `completion` and `version` are created by default, to showcase how a boa\nstyle application can look like.\n\nIf you want to support multiple cobra applications in your project, or want to\nkeep the root directory clean, you can create the application in a\nsub-directory:\n\n```txt\nboa init --path cmd/my-app my-app\n```\n\n### Adding a command\n\nTo add a command, simply run the `add` command:\n\n```txt\nboa add greet --flags name:string,age:int\n```\n\nIf you have provided a path before, make sure to provide the same path again,\nor navigate to the corresponding main package first.\n\nThis command creates new file called `greet.go` with a license header and\na cobra command generation function.\n\n```go\nfunc newGreet(pather CommandPather) *cobra.Command {\n        var flags struct {\n                name string\n                age  int\n        }\n\n        var cmd = \u0026cobra.Command{\n                Use:     \"greet \u003carg\u003e\",\n                Short:   \"greet does amazing work!\",\n                Example: fmt.Sprintf(\"  %[1]s greet --sample\", pather.CommandPath()),\n                RunE: func(cmd *cobra.Command, args []string) error {\n                        // Add basic sanity checks, where the usage help message should be\n                        // printed on error, before this line. After this line, the usage\n                        // message is no longer printed on error.\n                        cmd.SilenceUsage = true\n\n                        // TODO: Amazing work goes here!\n                        return nil\n                },\n        }\n\n        cmd.Flags().StringVar(\u0026flags.name, \"name\", \"\", \"name description\")\n        cmd.Flags().IntVar(\u0026flags.age, \"age\", 0, \"age description\")\n        return cmd\n}\n```\n\nBoa suggests to use the `SilenceErrors` and `SilenceUsage`.\nFor more information, see: https://github.com/spf13/cobra/issues/340#issuecomment-374617413\n\nYou now need to register the command with its parent. For the sake of this\nexample, it is simply the root command. Update `my-app.go` with:\n\n```go\n    cmd.AddCommand(\n        newCompletion(cmd),\n        newGreet(cmd),\n        newVersion(cmd),\n    )\n\n```\n\nThat's it, the new command is now registered and can already be used:\n\n```txt\n$ go run *.go greet --help\ngreet does amazing work!\n\nUsage:\n  my-app greet \u003carg\u003e [flags]\n\nExamples:\n  my-app greet --sample\n\nFlags:\n      --age int       age description\n  -h, --help          help for greet\n      --name string   name description\n```\n\n## Why boa?\n\nThe [cobra](https://github.com/spf13/cobra) library is an amazing and powerful\ntoolkit for creating command line applications. However, the example projects\ndisplay some drawbacks that boa tries to improve upon.\n\n### Directory structure\n\nThe proposed rigid directory structure in the examples and the generator go\nagainst the commonly used patterns how applications are structured nowadays.\n\nboa proposes to have all commands in the same directory. The key here is, that\nthe `main` package should only be used for initialization and very simple tasks.\nBigger business logic should live in a separate package, ensuring that it is\nreusable, and decoupled from the CLI interface.\n\n### Command registration\n\nCommands are proposed to be registered inside an `init` function. Essentially\nforcing global state, and making it hard for commands to be tested.\n\nWith the approach proposed by boa, testing a command is as simple as:\n\n```go\nfunc TestMyCommand(t *testing.T) {\n    cmd := newMyCommand(boa.Pather(\"\"))\n    cmd.SetArgs([]string{\"--my\", \"args\"})\n    err := cmd.Execute()\n    if err != nil {\n        t.Fail()\n    }\n}\n```\n\n### Global flags\n\nFlags are proposed to be package global variables and registered in the `init`\nfunction. This can lead to code that is full of surprises, as package globals\ntaint logic very easily if you do not take care.\n\nWith the approach proposed by boa, each instance of a command has its own set\nof flags, and there is no way for other components to access them directly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foncilla%2Fboa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foncilla%2Fboa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foncilla%2Fboa/lists"}