{"id":25392252,"url":"https://github.com/wolferhua/command","last_synced_at":"2025-04-10T00:53:29.522Z","repository":{"id":68552190,"uuid":"153580662","full_name":"wolferhua/command","owner":"wolferhua","description":"Go命令行类库，快速自定义命令，获取参数。","archived":false,"fork":false,"pushed_at":"2018-10-24T14:01:43.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T00:53:26.587Z","etag":null,"topics":["cmd","command","go","shell"],"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/wolferhua.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}},"created_at":"2018-10-18T07:21:31.000Z","updated_at":"2018-10-24T14:03:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"711610c4-156a-4fd1-b47f-9030e1f47ebc","html_url":"https://github.com/wolferhua/command","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolferhua%2Fcommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolferhua%2Fcommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolferhua%2Fcommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolferhua%2Fcommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wolferhua","download_url":"https://codeload.github.com/wolferhua/command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137995,"owners_count":21053775,"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":["cmd","command","go","shell"],"created_at":"2025-02-15T16:27:53.009Z","updated_at":"2025-04-10T00:53:29.500Z","avatar_url":"https://github.com/wolferhua.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# command\ngo command library\n\n# 项目描述\n\ngo命令行管理工具，go 原生提供了flag管理命令行。使用起来诸多不便，所以整理如下框架实现。\n\n# 使用入门\n\n### 第〇步： 获取command\n\n```shell\ngo get -u github.com/wolferhua/command\n```\n\n### 第一步： 建立命令行文件目录\n\n```shell\nmkdir -p project/commands\n```\n\n### 第二步： 创建命令文件 commands/test.go\n\n```go\npackage commands\n\nimport (\n\t\"fmt\"\n\t\"github.com/wolferhua/command\"\n)\n\ntype Test struct {\n\tcommand.Cmd\n\tB bool\n}\n\n//设置名称\nfunc (c *Test) GetName() string {\n\treturn \"test\"\n}\n\n//设置描述\nfunc (c *Test) GetDesc() string {\n\treturn \"test demo\"\n}\n//运行\nfunc (c *Test) Run() {\n\tfmt.Println(\"test is run\")\n\tfmt.Println(c.B)\n}\n\n//参数设置\nfunc (c *Test) SetFlags() {\n\tc.BoolVar(\u0026c.B, \"b\", false, \"bool test\")\n}\n\n```\n\n\n### 第三步： 创建命令注册文件 commands/commands.go\n\n```go\npackage commands\n\nimport \"github.com/wolferhua/command\"\n\nfunc init() {\n\tcommand.Registry(\n\t\t\u0026Test{},\n\t)\n}\n```\n### 第四步： main中运行\n\n```go\npackage main\n\nimport (\n\t\"github.com/wolferhua/command\"\n\t_ \"github.com/wolferhua/command/example/commands\" //注册commands\n)\n\nfunc main() {\n\tif command.Run() {\n\t\t//command 运行了。可以退出程序\n\t}else{\n\t\t//没有运行，可以运行其他操作\n\t}\n}\n```\n\n\n### 第五步： 运行\n\n**参数运行**\n```bash\ngo run example/main.go test -b\n```\n\n```bash\n# test is run\n# true //接收数据\n```\n\n**不带参数运行**\n\n```bash\ngo run example/main.go test \n```\n\n```bash\n# test is run\n# false //没有数据\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolferhua%2Fcommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwolferhua%2Fcommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolferhua%2Fcommand/lists"}