{"id":13410523,"url":"https://github.com/devfacet/gocmd","last_synced_at":"2025-08-03T05:15:02.431Z","repository":{"id":50373036,"uuid":"116631337","full_name":"devfacet/gocmd","owner":"devfacet","description":"A Go library for building command line applications.","archived":false,"fork":false,"pushed_at":"2023-04-04T21:43:27.000Z","size":137,"stargazers_count":66,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-30T23:23:08.343Z","etag":null,"topics":["go","golang","golang-library"],"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/devfacet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-08T04:52:02.000Z","updated_at":"2024-08-24T05:31:12.000Z","dependencies_parsed_at":"2024-01-08T14:30:56.901Z","dependency_job_id":"aaac1f41-4ed9-42ed-a9f4-a8bee4acbcf1","html_url":"https://github.com/devfacet/gocmd","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/devfacet/gocmd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfacet%2Fgocmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfacet%2Fgocmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfacet%2Fgocmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfacet%2Fgocmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devfacet","download_url":"https://codeload.github.com/devfacet/gocmd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devfacet%2Fgocmd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268496076,"owners_count":24259411,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","golang-library"],"created_at":"2024-07-30T20:01:07.472Z","updated_at":"2025-08-03T05:15:02.404Z","avatar_url":"https://github.com/devfacet.png","language":"Go","readme":"# gocmd\n\n[![Godoc][doc-image]][doc-url] [![Release][release-image]][release-url] [![Build][build-image]][build-url] [![Report][report-image]][report-url]\n\nA Go library for building command line applications.\n\n## Features\n\n- Advanced command line arguments handling\n\t- Subcommand handling\n\t- Short and long command line arguments\n\t- Multiple arguments (repeated or delimited)\n\t- Support for environment variables\n\t- Well formatted usage printing\n\t- Auto usage and version printing\n\t- Unknown argument handling\n- Output tables in the terminal\n- Template support for config files\n- No external dependency\n\n## Installation\n\n```shell\ngo get github.com/devfacet/gocmd/v3\n```\n\n## Usage\n\n### A basic app\n\nFor the full code [click here](_examples/basic/main.go).\n\n```go\nfunc main() {\n\tflags := struct {\n\t\tHelp      bool `short:\"h\" long:\"help\" description:\"Display usage\" global:\"true\"`\n\t\tVersion   bool `short:\"v\" long:\"version\" description:\"Display version\"`\n\t\tVersionEx bool `long:\"vv\" description:\"Display version (extended)\"`\n\t\tEcho      struct {\n\t\t\tSettings bool `settings:\"true\" allow-unknown-arg:\"true\"`\n\t\t} `command:\"echo\" description:\"Print arguments\"`\n\t\tMath struct {\n\t\t\tSqrt struct {\n\t\t\t\tNumber float64 `short:\"n\" long:\"number\" required:\"true\" description:\"Number\"`\n\t\t\t} `command:\"sqrt\" description:\"Calculate square root\"`\n\t\t\tPow struct {\n\t\t\t\tBase     float64 `short:\"b\" long:\"base\" required:\"true\" description:\"Base\"`\n\t\t\t\tExponent float64 `short:\"e\" long:\"exponent\" required:\"true\" description:\"Exponent\"`\n\t\t\t} `command:\"pow\" description:\"Calculate base exponential\"`\n\t\t} `command:\"math\" description:\"Math functions\" nonempty:\"true\"`\n\t}{}\n\n\t// Echo command\n\tgocmd.HandleFlag(\"Echo\", func(cmd *gocmd.Cmd, args []string) error {\n\t\tfmt.Printf(\"%s\\n\", strings.Join(cmd.FlagArgs(\"Echo\")[1:], \" \"))\n\t\treturn nil\n\t})\n\n\t// Math commands\n\tgocmd.HandleFlag(\"Math.Sqrt\", func(cmd *gocmd.Cmd, args []string) error {\n\t\tfmt.Println(math.Sqrt(flags.Math.Sqrt.Number))\n\t\treturn nil\n\t})\n\tgocmd.HandleFlag(\"Math.Pow\", func(cmd *gocmd.Cmd, args []string) error {\n\t\tfmt.Println(math.Pow(flags.Math.Pow.Base, flags.Math.Pow.Exponent))\n\t\treturn nil\n\t})\n\n\t// Init the app\n\tgocmd.New(gocmd.Options{\n\t\tName:        \"basic\",\n\t\tDescription: \"A basic app\",\n\t\tVersion:     fmt.Sprintf(\"%s (%s)\", version, gitCommit),\n\t\tFlags:       \u0026flags,\n\t\tConfigType:  gocmd.ConfigTypeAuto,\n\t})\n}\n```\n\n## Test\n\n```shell\n# Run tests\nmake test\n\n# Continuous testing\nmake test-ui\n\n# Benchmarks\nmake test-benchmarks\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## License\n\nLicensed under The MIT License (MIT)  \nFor the full copyright and license information, please view the LICENSE.txt file.\n\n[doc-url]: https://pkg.go.dev/github.com/devfacet/gocmd\n[doc-image]: https://pkg.go.dev/badge/github.com/devfacet/gocmd\n\n[release-url]: https://github.com/devfacet/gocmd/releases/latest\n[release-image]: https://img.shields.io/github/release/devfacet/gocmd.svg?style=flat-square\n\n[build-url]: https://github.com/devfacet/gocmd/actions/workflows/test.yaml\n[build-image]: https://github.com/devfacet/gocmd/workflows/Test/badge.svg\n\n[report-url]: https://goreportcard.com/report/github.com/devfacet/gocmd\n[report-image]: https://goreportcard.com/badge/github.com/devfacet/gocmd?style=flat-square\n","funding_links":[],"categories":["Command Line","命令行","Build Automation","命令行工具### 标准 CLI`用于创建一个标准命令行应用程序的库`","命令行工具"],"sub_categories":["Standard CLI","标准CLI","标准 CLI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevfacet%2Fgocmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevfacet%2Fgocmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevfacet%2Fgocmd/lists"}