{"id":16370764,"url":"https://github.com/integralist/go-flags","last_synced_at":"2026-03-08T22:30:16.422Z","repository":{"id":140160917,"uuid":"285513071","full_name":"Integralist/go-flags","owner":"Integralist","description":"Abstraction for command-line flag parsing (no dependencies outside of the Standard Library)","archived":false,"fork":false,"pushed_at":"2021-05-19T11:19:11.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-31T13:43:16.509Z","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/Integralist.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":"2020-08-06T08:12:45.000Z","updated_at":"2020-11-24T00:42:09.000Z","dependencies_parsed_at":"2023-04-07T13:04:37.524Z","dependency_job_id":null,"html_url":"https://github.com/Integralist/go-flags","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/Integralist%2Fgo-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Integralist","download_url":"https://codeload.github.com/Integralist/go-flags/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239906689,"owners_count":19716581,"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":[],"created_at":"2024-10-11T03:05:55.652Z","updated_at":"2026-03-08T22:30:16.368Z","avatar_url":"https://github.com/Integralist.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-flags\n\nAbstraction for command-line flag parsing (with no dependencies outside of the Standard Library).\n\n\u003e **Note**: implementation is heavily reliant on the `reflection` package.\n\n## Usage\n\nCreate a schema that defines your program flags (along with any commands, and the flags associated with those commands). \n\nOnce you have that schema defined, then call `flags.Parse()` and pass it a pointer to your schema. \n\nThis will result in the required flags being created while also populating the schema struct with the data provided by the user when running your cli application.\n\nIt supports creating both short and long flags (as well as specifying a 'usage' description for each flag) by utilizing golang's 'struct tag' feature.\n\n## Command Line Format\n\nThis package expects your CLI program to use the following format:\n\n```\n\u003cprogram\u003e \u003cflags\u003e \u003ccommand\u003e \u003ccommand-flags\u003e\n```\n\ne.g. `your_app -foo \"bar\" some_command -baz 123`\n\n## Example\n\nImagine you want to build a CLI program that has two commands `foo` and `bar`.\n\nEach command has its own set of flags:\n\n- `foo`: `-a/-aaa` (`string`), `-b/-bbb` (`string`).\n- `bar`: `-c/-ccc` (`bool`).\n\nBut also there are a bunch of top-level, non command specific flags you want to define:\n\n- `-d/-debug`\n- `-n/-number`\n- `-m/-message`\n\nHere is an example of how a user of your CLI program might call it:\n\n```bash\nyour_app -debug -n 123 -m \"something here\" foo -a beepboop -b 666\n```\n\nFor that example to work, be sure to define the following code within your `main.go`.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/integralist/go-flags/flags\"\n)\n\ntype Schema struct {\n\tDebug   bool   `short:\"d\" usage:\"enable debug level logs\"`\n\tNumber  int    `short:\"n\" usage:\"a number field\"`\n\tMessage string `short:\"m\" usage:\"a message field\"`\n\tFoo     struct {\n\t\tAAA string `short:\"a\" usage:\"does A\"`\n\t\tBBB string `short:\"b\" usage:\"does B\"`\n\t}\n\tBar struct {\n\t\tCCC bool `short:\"c\" usage:\"does C\"`\n\t}\n}\n\nfunc main() {\n\tvar s Schema\n\n\terr := flags.Parse(\u0026s)\n\tif err != nil {\n\t\tfmt.Printf(\"error parsing schema: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n}\n```\n\nYou should now find the `s` struct is populated with the following data:\n\n```go\n{\n\tDebug:true\n\tNumber:123\n\tMessage:something here\n\tFoo:{\n\t\tAAA:beepboop\n\t\tBBB:666\n\t}\n\tBar:{\n\t\tCCC:false\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintegralist%2Fgo-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintegralist%2Fgo-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintegralist%2Fgo-flags/lists"}