{"id":26455006,"url":"https://github.com/mirkobrombin/go-cli-builder","last_synced_at":"2025-12-30T04:50:27.595Z","repository":{"id":282785348,"uuid":"949647412","full_name":"mirkobrombin/go-cli-builder","owner":"mirkobrombin","description":"A lightweight and flexible library for building command-line interfaces (CLIs)  in Go. This library provides a simple and intuitive way to define commands,  flags (including short names), aliases and more.","archived":false,"fork":false,"pushed_at":"2025-04-30T13:50:47.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T17:59:03.327Z","etag":null,"topics":["bash-completion","cli","cli-app","command","command-line","commandline","go","go-cli-builder","golang","golang-library","library","subcommands"],"latest_commit_sha":null,"homepage":"http://go-cli-builder.mirko.pm/","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/mirkobrombin.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-16T22:38:46.000Z","updated_at":"2025-04-30T13:49:19.000Z","dependencies_parsed_at":"2025-06-20T02:33:05.503Z","dependency_job_id":null,"html_url":"https://github.com/mirkobrombin/go-cli-builder","commit_stats":null,"previous_names":["mirkobrombin/go-cli-builder"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mirkobrombin/go-cli-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirkobrombin%2Fgo-cli-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirkobrombin%2Fgo-cli-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirkobrombin%2Fgo-cli-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirkobrombin%2Fgo-cli-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mirkobrombin","download_url":"https://codeload.github.com/mirkobrombin/go-cli-builder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirkobrombin%2Fgo-cli-builder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260865948,"owners_count":23074730,"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":["bash-completion","cli","cli-app","command","command-line","commandline","go","go-cli-builder","golang","golang-library","library","subcommands"],"created_at":"2025-03-18T20:29:37.001Z","updated_at":"2025-12-30T04:50:27.583Z","avatar_url":"https://github.com/mirkobrombin.png","language":"Go","readme":"# Go CLI Builder (V2)\n\nA lightweight and flexible **declarative** library for building command-line interfaces (CLIs) \nin Go. This library provides a simple and intuitive way to define commands, \nflags (including short names), aliases and more using struct tags.\n\n## ⚠️ Migration to V2\n\n**Version 2.0 is a complete rewrite.** It moves from an imperative approach (calling methods to add flags) to a **declarative, code-first approach** (using struct tags). \nV1 code is **not compatible** with V2. Please refer to the [Basic Usage](#basic-usage) section to see the new pattern.\n\n## Features\n\n- **Declarative Command Definition:** Define commands and flags using struct tags (`cmd`, `cli`, `arg`, `help`).\n- **Type-Safe Flag Handling:** Automatically binds flags to basic types (`int`, `bool`, `string`, `time.Duration`, `[]string`) and structs.\n- **Dependency Injection:** Automatically injects `Logger` and `Context` into your commands via embedding.\n- **Environment Variable Integration:** Map environment variables directly to flags using the `env:\"VAR_NAME\"` tag.\n- **Built-in Help Generation:** Automatically generates formatted help messages based on your structs and tags.\n- **Customizable Logging:** Includes a built-in logger (`Info`, `Success`, `Warning`, `Error`) available in every command.\n- **Lifecycle Hooks:** Supports `Before()` and `After()` methods for command initialization and cleanup.\n\n## Getting Started\n\n### Installation\n\n```bash\ngo get github.com/mirkobrombin/go-cli-builder/v2\n```\n\n### Basic Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mirkobrombin/go-cli-builder/v2/cli\"\n)\n\n// Define your root CLI struct\ntype CLI struct {\n\t// Global flags\n\tVerbose bool `cli:\"verbose,v\" help:\"Enable verbose output\" env:\"VERBOSE\"`\n\n\t// Subcommands\n\tAdd  AddCmd  `cmd:\"add\" help:\"Add a new item\"`\n\tList ListCmd `cmd:\"list\" help:\"List all items\"`\n\n\t// Embed Base to get Logger and Context\n\tcli.Base\n}\n\n// Optional: Lifecycle hook\nfunc (c *CLI) Before() error {\n\tif c.Verbose {\n\t\tc.Logger.Info(\"Verbose mode enabled\")\n\t}\n\treturn nil\n}\n\ntype AddCmd struct {\n\tItem string `arg:\"\" required:\"true\" help:\"Item to add\"`\n\tcli.Base\n}\n\n// Run is the entry point for the command\nfunc (c *AddCmd) Run() error {\n\tc.Logger.Success(\"Adding item: %s\", c.Item)\n\treturn nil\n}\n\ntype ListCmd struct {\n\tcli.Base\n}\n\nfunc (c *ListCmd) Run() error {\n\tc.Logger.Info(\"Listing items...\")\n\treturn nil\n}\n\nfunc main() {\n\tapp := \u0026CLI{}\n\n\t// Run the app - the library handles parsing, binding, and execution\n\tif err := cli.Run(app); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Error: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n}\n```\n\n## Documentation\n\nFor more detailed examples, check the `examples/v2` directory.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file \nfor details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirkobrombin%2Fgo-cli-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmirkobrombin%2Fgo-cli-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirkobrombin%2Fgo-cli-builder/lists"}