{"id":37174401,"url":"https://github.com/evilmonkeyinc/golang-cli","last_synced_at":"2026-01-14T20:22:48.134Z","repository":{"id":45655516,"uuid":"424404947","full_name":"evilmonkeyinc/golang-cli","owner":"evilmonkeyinc","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-02T17:00:16.000Z","size":2111,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-09T02:45:13.077Z","etag":null,"topics":[],"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/evilmonkeyinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-11-03T22:57:40.000Z","updated_at":"2022-09-23T18:17:31.000Z","dependencies_parsed_at":"2025-08-24T20:10:09.314Z","dependency_job_id":"4d74eeac-274a-4a4a-9c3a-3f7c7d9e8446","html_url":"https://github.com/evilmonkeyinc/golang-cli","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/evilmonkeyinc/golang-cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evilmonkeyinc%2Fgolang-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evilmonkeyinc%2Fgolang-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evilmonkeyinc%2Fgolang-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evilmonkeyinc%2Fgolang-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evilmonkeyinc","download_url":"https://codeload.github.com/evilmonkeyinc/golang-cli/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evilmonkeyinc%2Fgolang-cli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":[],"created_at":"2026-01-14T20:22:47.370Z","updated_at":"2026-01-14T20:22:48.110Z","avatar_url":"https://github.com/evilmonkeyinc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![codecov](https://codecov.io/gh/evilmonkeyinc/golang-cli/branch/main/graph/badge.svg?token=4PU85I7J2R)](https://codecov.io/gh/evilmonkeyinc/golang-cli)\n[![test](https://github.com/evilmonkeyinc/golang-cli/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/evilmonkeyinc/golang-cli/actions/workflows/test.yaml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/evilmonkeyinc/golang-cli.svg)](https://pkg.go.dev/github.com/evilmonkeyinc/golang-cli)\n\n\u003e This library is on the unstable version v0.X.X, which means there is a chance that any minor update may introduce a breaking change. Where I will endeavor to avoid this, care should be taken updating your dependency on this library until the first stable release v1.0.0 at which point any future breaking changes will result in a new major release.\n\n# Golang-CLI\n\nA simple command-line tool-set for Golang modeled after HTTP routing patterns.\n\n## Install\n\n`go get -u github.com/evilmonkeyinc/golang-cli`\n\n## Usage\n\n### Shell\n\n```golang\nimport \"github.com/evilmonkeyinc/golang-cli/shell\"\n...\n    newShell := new(shell.Shell)\n...\n```\n\n### Options\n\nOptions adds the ability to customize the shell's properties for your project.\n\n```golang\n    newShell.Options(shell.OptionOutputWriter(customOutput))\n```\n\n\u003e Options should be set before performing any other actions on the shell\n\n### Middleware\n\nMiddleware adds the ability to wrap all shell handler functions in additional logic.\n\n```golang\n    newShell.Use(middleware.Recoverer())\n```\n\nThe most common use-case has been included in the library, panic recovery, which \nmakes it possible for the shell to recover from a panic without exiting the interactive-shell\n\nMiddleware can also be used to manipulate the shell handler functions ResponseWriter and Request to add or manipulate the existing functionality\n\n### Groups\n\nGroups allow you to define a new inline-router to the shell router stack.\n\n```golang\n\tnewShell.Group(func(r shell.Router) {\n\t...\n\t})\n```\n\nAn inline-routers handlers will be evaluated at the same level as the containing router, but makes it possible to define middleware that will be executed for the inline-router handlers only.\n\n### Routes\n\nRoutes allow you do define a sub-router which is executed as a shell handler, but include additional\nrouting instructions to handle sub-commands for the shell.\n\n```golang\n    newShell.Route(\"users\", func(r shell.Router) {\n\t\tr.HandleFunction(\"add\", func(rw shell.ResponseWriter, r *shell.Request) error { return nil })\n\t\tr.HandleFunction(\"list\", func(rw shell.ResponseWriter, r *shell.Request) error { return nil })\n\t})\n```\n\nThe sub commands would then be executed by including spaces between the commands:\n\n```bash\n./yourcli users list\n```\n\nRoutes will also support specific middleware for these sub-commands in the same way as the inline-routers created by Group.\n\n### Handlers\n\nThe Handle and HandleFunction functions add shell handlers to the router stack. \n\n```golang\n\tnewShell.Handle(\"help\", \u0026commands.HelpCommand{})\n\tnewShell.HandleFunction(\"ping\", func(rw shell.ResponseWriter, r *shell.Request) error {\n\t\tfmt.Fprintln(rw, \"pong\")\n\t\treturn nil\n\t})\n```\n\n```bash\n./yourcli ping\npong\n```\n\n### Flags\n\nIt is possible to define global flags directly on the shell, or on each route using the `Flags()` function\n\n```golang\n\tnewShell := new(shell.Shell)\n\tnewShell.Flags(flags.FlagHandlerFunction(func(fd flags.FlagDefiner) {\n\t\tfd.Bool(\"toUpper\", false, \"\")\n\t}))\n```\n\nIt is also possible to allow individual commands define flags if the Handler also conforms to the FlagHandler interface, as the sample Command struct does.\n\n```golang\n\tpingCommand := \u0026commands.Command{\n\t\t...\n\t\tFlags: func(fd flags.FlagDefiner) {\n\t\t\tfd.String(\"suffix\", \"\", \"\")\n\t\t},\n\t\t...\n\t}\n```\n\nThese flags can be set on the command-line at any point after they are defined, so if they are defined globally on the shell then it could be set any time after the package is executed and would give the same result\n\n```base\n.my-cli -toUpper ping\n\u003e PONG\n\n.my-cli ping -toUpper\n\u003e PONG\n```\n\nbut those flags defined in routes or commands will be ignored if used before they are defined\n\n```base\n.my-cli ping -suffix=go\n\u003e ponggo\n\n.my-cli -suffix=go ping\n\u003e flag provided but not defined: -suffix\n\u003e pong\n```\n\n## Examples\n\n- [CLI Example](examples/cli/main.go)  \nUsing this library for a standard command-line interface tool.\n\n- [Shell Example](examples/shell/main.go)  \nUsing this library for an interactive-shell interface.\n\n## References and Inspirations\n\nThe following projects were used as references and inspiration for this project \n\n- [Valdimir Vivien's GOSH](https://github.com/vladimirvivien/gosh)  \n- [Go Chi's Chi Router](https://github.com/go-chi/chi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevilmonkeyinc%2Fgolang-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevilmonkeyinc%2Fgolang-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevilmonkeyinc%2Fgolang-cli/lists"}