{"id":34176074,"url":"https://github.com/mix-go/xcli","last_synced_at":"2026-04-11T10:02:06.776Z","repository":{"id":57570713,"uuid":"345941568","full_name":"mix-go/xcli","owner":"mix-go","description":"CLI Interactive Commander / 命令行交互指挥官","archived":false,"fork":false,"pushed_at":"2023-09-11T03:21:57.000Z","size":40,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T10:13:33.512Z","etag":null,"topics":["cli","command-line","commander","mixgo","xcli"],"latest_commit_sha":null,"homepage":"https://openmix.org/mix-go","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/mix-go.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":"2021-03-09T08:52:39.000Z","updated_at":"2023-05-10T01:33:22.000Z","dependencies_parsed_at":"2024-06-18T21:30:39.554Z","dependency_job_id":"344010a5-8049-4aa8-be3a-ea2c7af205de","html_url":"https://github.com/mix-go/xcli","commit_stats":null,"previous_names":["mix-go/cli"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/mix-go/xcli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxcli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxcli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxcli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxcli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-go","download_url":"https://codeload.github.com/mix-go/xcli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-go%2Fxcli/sbom","scorecard":{"id":650708,"data":{"date":"2025-08-11","repo":{"name":"github.com/mix-go/xcli","commit":"a5e9821478c5fa38ac30e2793cbc7f466292e71a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T13:26:54.785Z","repository_id":57570713,"created_at":"2025-08-21T13:26:54.786Z","updated_at":"2025-08-21T13:26:54.786Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31676210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T08:18:19.405Z","status":"ssl_error","status_checked_at":"2026-04-11T08:17:08.892Z","response_time":54,"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","command-line","commander","mixgo","xcli"],"created_at":"2025-12-15T12:24:58.523Z","updated_at":"2026-04-11T10:02:06.771Z","avatar_url":"https://github.com/mix-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e OpenMix 出品：[https://openmix.org](https://openmix.org/mix-go)\n\n## Mix XCLI\n\n命令行交互指挥官\n\nCLI Interactive Commander\n\n## Overview\n\n一个命令行交互与指挥管理工具，它可以让单个 CLI 可执行多种功能，同时它还包括命令行参数获取、全局 panic 捕获与处理、程序后台执行等命令行开发常用功能。\n\n## Installation\n\n```\ngo get github.com/mix-go/xcli\n```\n\n## Quick start\n\n```go\npackage main\n\nimport (\n    \"github.com/mix-go/xcli\"\n    \"github.com/mix-go/xcli/flag\"\n)\n\nfunc main() {\n    xcli.SetName(\"app\").SetVersion(\"0.0.0-alpha\")\n    cmd := \u0026xcli.Command{\n        Name:  \"hello\",\n        Short: \"Echo demo\",\n        RunF:  func() {\n            name := flag.Match(\"n\", \"name\").String(\"default\")\n            // do something\n        },\n    }\n    opt := \u0026xcli.Option{\n        Names: []string{\"n\", \"name\"},\n        Usage: \"Your name\",\n    }\n    cmd.AddOption(opt)\n    xcli.AddCommand(cmd).Run()\n}\n```\n\n上面是采用闭包，也可以使用对象\n\n```go\ntype FooCommand struct {\n}\nfunc (t *FooCommand) Main() {\n    // do something\n}\ncmd := \u0026xcli.Command{\n    Name:  \"hello\",\n    Short: \"Echo demo\",\n    RunI:  \u0026FooCommand{},\n}\n```\n\n编译后，查看整个命令行程序的帮助\n\n```\n$ ./go_build_main_go \nUsage: ./go_build_main_go [OPTIONS] COMMAND [opt...]\n\nCommands:\n  hello         Echo demo\n\nGlobal Options:\n  -h, --help    Print usage\n  -v, --version Print version information\n\nRun './go_build_main_go COMMAND --help' for more information on a command.\n\nDeveloped with Mix Go framework. (openmix.org/mix-go)\n```\n\n查看命令行程序的版本信息\n\n```\n$ ./go_build_main_go -v\napp 0.0.0-alpha\n```\n\n查看 `hello` 命令的帮助\n\n```\n$ ./go_build_main_go hello --help\nUsage: ./go_build_main_go hello [opt...]\n\nCommand Options:\n  -n, --name    Your name\n\nDeveloped with Mix Go framework. (openmix.org/mix-go)\n```\n\n执行 `hello` 命令\n\n```\n$ ./go_build_main_go hello \n```\n\n## Flag 参数获取\n\n\u003e 该 flag 比 golang 自带的更加好用，不需要 Parse 操作\n\n参数规则 (部分UNIX风格+GNU风格)\n\n```\n/examples/app home -d -rf --debug -v vvv --page 23 -s=test --name=john arg0\n```\n- 命令：\n    - 第一个参数，可以为空：`home`\n- 选项：\n    - 短选项：一个中杠，如 `-d`、`-rf`\n    - 长选项：二个中杠，如：`--debug`\n- 选项值：\n    - 无值：`-d`、`-rf`、 `--debug`\n    - 有值(空格)：`-v vvv`、`--page 23`\n    - 有值(等号)：`-s=test`、`--name=john`\n- 参数：\n    - 没有定义 `-` 的参数：`arg0`\n\n获取选项，可以获取 `String`、`Bool`、`Int64`、`Float64` 多种类型，也可以指定默认值。\n\n```\nname := flag.Match(\"n\", \"name\").String(\"Xiao Ming\")\n```\n\n获取第一个参数\n\n```\narg0 := flag.Arguments().First().String()\n```\n\n获取全部参数\n\n```\nfor k, v := range flag.Arguments().Values() {\n    // do something\n}\n```\n\n## Daemon 后台执行\n\n将命令行程序变为后台执行，该方法只可在 Main 协程中使用。\n\n```\nprocess.Daemon()\n```\n\n我们可以通过配合 `flag` 获取参数，实现通过某几个参数控制程序后台执行。\n\n```go\nif flag.Match(\"d\", \"daemon\").Bool() {\n    process.Daemon()\n}\n```\n\n上面就实现了一个当命令行参数中带有 `-d/--daemon` 参数时，程序就在后台执行。\n\n## Handle panic 错误处理\n\n使用中间件处理异常，也可以单独对某个命令配置中间件\n\n```go\nh := func(next func()) {\n    defer func() {\n        if err := recover(); err != nil {\n            // handle panic\n        }\n    }()\n    next()\n}\ncmd := \u0026xcli.Command{\n    Name:  \"hello\",\n    Short: \"Echo demo\",\n    RunF:  func() {\n        // do something\n    },\n}\nxcli.Use(h).AddCommand(cmd).Run()\n```\n\n## Application\n\n我们在编写代码时，可能会要用到 App 中的一些信息。\n\n```\n// 获取基础路径(二进制所在目录路径)\nxcli.App().BasePath\n\n// App名称\nxcli.App().Name\n\n// App版本号\nxcli.App().Version\n\n// 是否开启debug\nxcli.App().Debug\n```\n\n## Singleton 单命令\n\n当我们的 CLI 只有一个命令时，只需要配置一下 `Singleton`：\n\n~~~go\ncmd := \u0026xcli.Command{\n    Name:  \"hello\",\n    Short: \"Echo demo\",\n    RunF:  func() {\n        // do something\n    },\n    Singleton: true,\n}\n~~~\n\n命令的 Options 将会在 `-h/--help` 中打印\n\n~~~\n$ ./go_build_main_go \nUsage: ./go_build_main_go [OPTIONS] COMMAND [opt...]\n\nCommand Options:\n  -n, --name    Your name\n\nGlobal Options:\n  -h, --help    Print usage\n  -v, --version Print version information\n\nRun './go_build_main_go --help' for more information on a command.\n\nDeveloped with Mix Go framework. (openmix.org/mix-go)\n~~~\n\n## Default 默认执行\n\n当我们的 CLI 有 CUI 时，需要实现点击后默认启动 UI 界面，只需要配置一下 `Default`：\n\n~~~go\ncmd := \u0026xcli.Command{\n    Name:  \"hello\",\n    Short: \"Echo demo\",\n    RunF:  func() {\n        // do something\n    },\n    Default: true,\n}\n~~~\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-go%2Fxcli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-go%2Fxcli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-go%2Fxcli/lists"}