{"id":16296837,"url":"https://github.com/windomz/go-commander","last_synced_at":"2025-03-20T04:31:39.169Z","repository":{"id":57517193,"uuid":"83383181","full_name":"WindomZ/go-commander","owner":"WindomZ","description":":lollipop: The solution for building command shell programs,  drive by \u003cdocopt\u003e, inspired by \u003ccommander.js\u003e","archived":false,"fork":false,"pushed_at":"2017-07-04T10:08:12.000Z","size":149,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T23:10:48.270Z","etag":null,"topics":["cli","command-line","commander","commandline-interface","docopt","go","golang","shell"],"latest_commit_sha":null,"homepage":"","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/WindomZ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-28T03:05:41.000Z","updated_at":"2024-09-10T06:04:42.000Z","dependencies_parsed_at":"2022-09-15T21:52:08.133Z","dependency_job_id":null,"html_url":"https://github.com/WindomZ/go-commander","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindomZ%2Fgo-commander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindomZ%2Fgo-commander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindomZ%2Fgo-commander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindomZ%2Fgo-commander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WindomZ","download_url":"https://codeload.github.com/WindomZ/go-commander/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244052166,"owners_count":20390045,"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","command-line","commander","commandline-interface","docopt","go","golang","shell"],"created_at":"2024-10-10T20:24:08.542Z","updated_at":"2025-03-20T04:31:38.835Z","avatar_url":"https://github.com/WindomZ.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-commander\n\n[![Build Status](https://travis-ci.org/WindomZ/go-commander.svg?branch=master)](https://travis-ci.org/WindomZ/go-commander)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)\n[![Go Report Card](https://goreportcard.com/badge/github.com/WindomZ/go-commander)](https://goreportcard.com/report/github.com/WindomZ/go-commander)\n[![Coverage Status](https://coveralls.io/repos/github/WindomZ/go-commander/badge.svg?branch=master)](https://coveralls.io/github/WindomZ/go-commander?branch=master)\n\n\u003e The solution for building command shell programs, \ndrive by \u003c[docopt](https://github.com/docopt/docopt.go)\u003e, \ninspired by \u003c[commander.js](https://github.com/tj/commander.js)\u003e\n\n![v1.2.2](https://img.shields.io/badge/version-v1.2.2-blue.svg)\n![status](https://img.shields.io/badge/status-stable-green.svg)\n\n## Features\n\n- [x] Has all the features of [docopt](https://github.com/docopt/docopt.go).\n- [x] Usage like [commander.js](https://github.com/tj/commander.js) as simple and readable.\n- [x] Automatic generated a help message, easy to use, or advanced usage see [documents](http://docopt.org/) of docopt.\n- [x] Automatically execute the correct action function, don't worry about conflict.\n- [x] Can customize the action function, better with context.\n- [x] Code colloquial use, from top to bottom.\n\n## Installation\n\nTo get the package, execute:\n\n```bash\ngo get gopkg.in/WindomZ/go-commander.v1\n```\n\nTo import this package, add the following line to your code:\n\n```go\nimport \"gopkg.in/WindomZ/go-commander.v1\"\n```\n\n## Examples\n\n### [Quick example](https://github.com/WindomZ/go-commander/blob/master/examples/quick_example/quick_example.go)\n\nSuch as the following help message\n\n```markdown\nUsage:\n  quick_example tcp \u003chost\u003e \u003cport\u003e [--timeout=\u003cseconds\u003e]\n  quick_example serial \u003cport\u003e [--baud=9600] [--timeout=\u003cseconds\u003e]\n  quick_example -h|--help\n  quick_example -v|--version\n\nOptions:\n  -h --help     output usage information\n  -v --version  output the version number\n```\n\nTo coding with `go-commander` just like this:\n\n```go\nimport \"github.com/WindomZ/go-commander\"\n...\n\n// quick_example\ncommander.Program.\n\tCommand(\"quick_example\").\n\tVersion(\"0.1.1rc\")\n\n// quick_example tcp \u003chost\u003e \u003cport\u003e [--timeout=\u003cseconds\u003e]\ncommander.Program.\n\tCommand(\"tcp \u003chost\u003e \u003cport\u003e\").\n\tOption(\"--timeout=\u003cseconds\u003e\").\n\tAction(func() {\n\t\tfmt.Printf(\"tcp %s %s %s\\n\",\n\t\t\tcommander.Program.MustString(\"\u003chost\u003e\"),\n\t\t\tcommander.Program.MustString(\"\u003cport\u003e\"),\n\t\t\tcommander.Program.MustString(\"--timeout\"),\n\t\t)\n\t})\n\n// quick_example serial \u003cport\u003e [--baud=9600] [--timeout=\u003cseconds\u003e]\ncommander.Program.\n\tCommand(\"serial \u003cport\u003e\").\n\tOption(\"--baud=9600\").\n\tOption(\"--timeout=\u003cseconds\u003e\").\n\tAction(func() {\n\t\tfmt.Printf(\"serial %s %s %s\\n\",\n\t\t\tcommander.Program.MustString(\"\u003cport\u003e\"),\n\t\t\tcommander.Program.MustString(\"--baud\"),\n\t\t\tcommander.Program.MustString(\"--timeout\"),\n\t\t)\n\t})\n\ncommander.Program.Parse()\n```\n\nGet the terminal output:\n\n```bash\n$ quick_example --version\n# output: 0.1.1rc\n\n$ quick_example tcp 127.0.0.1 1080 --timeout=110\n# output: tcp 127.0.0.1 1080 110\n\n$ quick_example serial 80 --baud=5800 --timeout=120\n# output: serial 80 5800 120\n```\n\n### [Counted example](https://github.com/WindomZ/go-commander/blob/master/examples/counted_example/counted_example.go)\n\nSuch as the following help message\n\n```markdown\nUsage:\n  counted_example -v...\n  counted_example go [go]\n  counted_example (--path=\u003cpath\u003e)...\n  counted_example \u003cfile\u003e \u003cfile\u003e\n  counted_example -h|--help\n  counted_example -v|--version\n\nOptions:\n  -h --help     output usage information\n  -v --version  output the version number\n```\n\nTo coding with `go-commander` just like this:\n\n```go\nimport \"github.com/WindomZ/go-commander\"\n...\n\n// counted_example -v...\ncommander.Program.\n\tCommand(\"counted_example\").\n\tOption(\"-v...\", \"\", func(c commander.Context) {\n\t\tfmt.Println(\"-v =\", c.Get(\"-v\"))\n\t})\n\n// counted_example go [go]\ncommander.Program.\n\tCommand(\"go [go]\").\n\tAction(func(c commander.Context) {\n\t\tfmt.Println(\"go =\", c.Get(\"go\"))\n\t})\n\n// counted_example (--path=\u003cpath\u003e)...\ncommander.Program.\n\tCommand(\"(--path=\u003cpath\u003e)...\", \"\", func(c commander.Context) {\n\t\tfmt.Printf(\"--path = %q\\n\",\n\t\t\tc.MustStrings(\"--path\"))\n\t})\n\n// counted_example \u003cfile\u003e \u003cfile\u003e\ncommander.Program.\n\tCommand(\"\u003cfile\u003e \u003cfile\u003e\", \"\", func(c commander.Context) {\n\t\tfmt.Printf(\"\u003cfile\u003e = %q\\n\",\n\t\t\tc.MustStrings(\"\u003cfile\u003e\"))\n\t})\n\ncommander.Program.Parse()\n```\n\nGet the terminal output:\n\n```bash\n$ counted_example -vvvvvvvvvv\n# output: -v = 10\n\n$ counted_example go go\n# output: go = 2\n\n$ counted_example --path ./here --path ./there\n# output: --path = [\"./here\" \"./there\"]\n\n$ counted_example this.txt that.txt\n# output: \u003cfile\u003e = [\"this.txt\" \"that.txt\"]\n```\n\n### [Calculator example](https://github.com/WindomZ/go-commander/blob/master/examples/calculator_example/calculator_example.go)\n\nSuch as the following help message\n\n```markdown\nsimple calculator example\n\nUsage:\n  calculator_example \u003cvalue\u003e ( ( + | - | * | / ) \u003cvalue\u003e )...\n  calculator_example \u003cfunction\u003e \u003cvalue\u003e [( , \u003cvalue\u003e )]...\n  calculator_example -h|--help\n  calculator_example -v|--version\n\nOptions:\n  -h --help     output usage information\n  -v --version  output the version number\n\nExamples:\n  calculator_example 1 + 2 + 3 + 4 + 5\n  calculator_example 1 + 2 '*' 3 / 4 - 5    # note quotes around '*'\n  calculator_example sum 10 , 20 , 30 , 40\n```\n\nTo coding with `go-commander` just like this:\n\n```go\nimport . \"github.com/WindomZ/go-commander\"\n...\n\n// calculator_example\nProgram.Command(\"calculator_example\").\n\tVersion(\"0.0.1\").\n\tDescription(\"Simple calculator example\")\n\n// calculator_example \u003cvalue\u003e ( ( + | - | * | / ) \u003cvalue\u003e )...\nProgram.Command(\"\u003cvalue\u003e ( ( + | - | * | / ) \u003cvalue\u003e )...\", \"\", func() {\n\tvar result int\n\tvalues := Program.MustStrings(\"\u003cvalue\u003e\")\n\tfor index, value := range values {\n\t\tif i, err := strconv.Atoi(value); err != nil {\n\t\t} else if index == 0 {\n\t\t\tresult = i\n\t\t} else {\n\t\t\tswitch Program.GetArg(index*2 - 1) {\n\t\t\tcase \"+\":\n\t\t\t\tresult += i\n\t\t\tcase \"-\":\n\t\t\t\tresult -= i\n\t\t\tcase \"*\":\n\t\t\t\tresult *= i\n\t\t\tcase \"/\":\n\t\t\t\tresult /= i\n\t\t\t}\n\t\t}\n\t}\n\tfmt.Println(Program.ArgsString(), \"=\", result)\n})\n\n// calculator_example \u003cfunction\u003e \u003cvalue\u003e [( , \u003cvalue\u003e )]...\nProgram.Command(\"\u003cfunction\u003e \u003cvalue\u003e [( , \u003cvalue\u003e )]...\", \"\", func() {\n\tvar result int\n\tswitch Program.MustString(\"\u003cfunction\u003e\") {\n\tcase \"sum\":\n\t\tvalues := Program.MustStrings(\"\u003cvalue\u003e\")\n\t\tfor _, value := range values {\n\t\t\tif i, err := strconv.Atoi(value); err == nil {\n\t\t\t\tresult += i\n\t\t\t}\n\t\t}\n\t}\n\tfmt.Println(Program.ArgsString(), \"=\", result)\n})\n\n// Examples: ...\nProgram.Annotation(\"Examples\",\n\t[]string{\n\t\t\"calculator_example 1 + 2 + 3 + 4 + 5\",\n\t\t\"calculator_example 1 + 2 '*' 3 / 4 - 5    # note quotes around '*'\",\n\t\t\"calculator_example sum 10 , 20 , 30 , 40\",\n\t},\n)\n\ncommander.Program.Parse()\n```\n\nGet the terminal output:\n\n```bash\n$ calculator_example 1 + 2 + 3 + 4 + 5\n# output: 15\n\n$ calculator_example 1 + 2 '*' 3 / 4 - 5\n# output: -3\n\n$ calculator_example sum 10 , 20 , 30 , 40\n# output: 100\n```\n\n## UsingList\n\n- [gitclone](https://github.com/WindomZ/gitclone)\n- [gitinit](https://github.com/WindomZ/gitinit)\n- [gitdate](https://github.com/WindomZ/gitdate)\n- [gituser](https://github.com/WindomZ/gituser)\n\n## Development\n\nI would **love** to hear what you think about `go-commander` on [issues page](https://github.com/WindomZ/go-commander/issues)\n\nMake pull requests, report bugs, suggest ideas and discuss `go-commander`.\n\n## License\n\nThe [MIT License](https://github.com/WindomZ/go-commander/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindomz%2Fgo-commander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindomz%2Fgo-commander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindomz%2Fgo-commander/lists"}