{"id":13410500,"url":"https://github.com/jessevdk/go-flags","last_synced_at":"2025-05-11T03:44:53.458Z","repository":{"id":4490137,"uuid":"5629366","full_name":"jessevdk/go-flags","owner":"jessevdk","description":"go command line option parser","archived":false,"fork":false,"pushed_at":"2024-07-26T07:31:57.000Z","size":720,"stargazers_count":2658,"open_issues_count":59,"forks_count":311,"subscribers_count":30,"default_branch":"main","last_synced_at":"2025-05-08T00:59:17.901Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/jessevdk/go-flags","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jessevdk.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":"2012-08-31T13:57:58.000Z","updated_at":"2025-04-28T09:06:14.000Z","dependencies_parsed_at":"2024-09-17T00:27:46.374Z","dependency_job_id":null,"html_url":"https://github.com/jessevdk/go-flags","commit_stats":{"total_commits":547,"total_committers":74,"mean_commits":7.391891891891892,"dds":0.6416819012797075,"last_synced_commit":"8eae68f0a7870eec41bc8061c2194040048cdf59"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessevdk%2Fgo-flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessevdk%2Fgo-flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessevdk%2Fgo-flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessevdk%2Fgo-flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jessevdk","download_url":"https://codeload.github.com/jessevdk/go-flags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978754,"owners_count":21834915,"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-07-30T20:01:07.340Z","updated_at":"2025-05-08T00:59:23.064Z","avatar_url":"https://github.com/jessevdk.png","language":"Go","funding_links":[],"categories":["命令行工具### 标准 CLI`用于创建一个标准命令行应用程序的库`","开源类库","Go","Command Line","命令行","Open source library","Build Automation","\u003cspan id=\"命令行-command-line\"\u003e命令行 Command Line\u003c/span\u003e","Miscellaneous","命令行工具"],"sub_categories":["命令行","Standard CLI","标准CLI","Command Line","Advanced Console UIs","标准 CLI"],"readme":"go-flags: a go library for parsing command line arguments\n=========================================================\n\n[![GoDoc](https://godoc.org/github.com/jessevdk/go-flags?status.png)](https://godoc.org/github.com/jessevdk/go-flags)\n\nThis library provides similar functionality to the builtin flag library of\ngo, but provides much more functionality and nicer formatting. From the\ndocumentation:\n\nPackage flags provides an extensive command line option parser.\nThe flags package is similar in functionality to the go builtin flag package\nbut provides more options and uses reflection to provide a convenient and\nsuccinct way of specifying command line options.\n\nSupported features:\n* Options with short names (-v)\n* Options with long names (--verbose)\n* Options with and without arguments (bool v.s. other type)\n* Options with optional arguments and default values\n* Multiple option groups each containing a set of options\n* Generate and print well-formatted help message\n* Passing remaining command line arguments after -- (optional)\n* Ignoring unknown command line options (optional)\n* Supports -I/usr/include -I=/usr/include -I /usr/include option argument specification\n* Supports multiple short options -aux\n* Supports all primitive go types (string, int{8..64}, uint{8..64}, float)\n* Supports same option multiple times (can store in slice or last option counts)\n* Supports maps\n* Supports function callbacks\n* Supports namespaces for (nested) option groups\n\nThe flags package uses structs, reflection and struct field tags\nto allow users to specify command line options. This results in very simple\nand concise specification of your application options. For example:\n\n```go\ntype Options struct {\n\tVerbose []bool `short:\"v\" long:\"verbose\" description:\"Show verbose debug information\"`\n}\n```\n\nThis specifies one option with a short name -v and a long name --verbose.\nWhen either -v or --verbose is found on the command line, a 'true' value\nwill be appended to the Verbose field. e.g. when specifying -vvv, the\nresulting value of Verbose will be {[true, true, true]}.\n\nExample:\n--------\n```go\nvar opts struct {\n\t// Slice of bool will append 'true' each time the option\n\t// is encountered (can be set multiple times, like -vvv)\n\tVerbose []bool `short:\"v\" long:\"verbose\" description:\"Show verbose debug information\"`\n\n\t// Example of automatic marshalling to desired type (uint)\n\tOffset uint `long:\"offset\" description:\"Offset\"`\n\n\t// Example of a callback, called each time the option is found.\n\tCall func(string) `short:\"c\" description:\"Call phone number\"`\n\n\t// Example of a required flag\n\tName string `short:\"n\" long:\"name\" description:\"A name\" required:\"true\"`\n\n\t// Example of a flag restricted to a pre-defined set of strings\n\tAnimal string `long:\"animal\" choice:\"cat\" choice:\"dog\"`\n\n\t// Example of a value name\n\tFile string `short:\"f\" long:\"file\" description:\"A file\" value-name:\"FILE\"`\n\n\t// Example of a pointer\n\tPtr *int `short:\"p\" description:\"A pointer to an integer\"`\n\n\t// Example of a slice of strings\n\tStringSlice []string `short:\"s\" description:\"A slice of strings\"`\n\n\t// Example of a slice of pointers\n\tPtrSlice []*string `long:\"ptrslice\" description:\"A slice of pointers to string\"`\n\n\t// Example of a map\n\tIntMap map[string]int `long:\"intmap\" description:\"A map from string to int\"`\n\n\t// Example of env variable\n\tThresholds  []int     `long:\"thresholds\" default:\"1\" default:\"2\" env:\"THRESHOLD_VALUES\"  env-delim:\",\"`\n}\n\n// Callback which will invoke callto:\u003cargument\u003e to call a number.\n// Note that this works just on OS X (and probably only with\n// Skype) but it shows the idea.\nopts.Call = func(num string) {\n\tcmd := exec.Command(\"open\", \"callto:\"+num)\n\tcmd.Start()\n\tcmd.Process.Release()\n}\n\n// Make some fake arguments to parse.\nargs := []string{\n\t\"-vv\",\n\t\"--offset=5\",\n\t\"-n\", \"Me\",\n\t\"--animal\", \"dog\", // anything other than \"cat\" or \"dog\" will raise an error\n\t\"-p\", \"3\",\n\t\"-s\", \"hello\",\n\t\"-s\", \"world\",\n\t\"--ptrslice\", \"hello\",\n\t\"--ptrslice\", \"world\",\n\t\"--intmap\", \"a:1\",\n\t\"--intmap\", \"b:5\",\n\t\"arg1\",\n\t\"arg2\",\n\t\"arg3\",\n}\n\n// Parse flags from `args'. Note that here we use flags.ParseArgs for\n// the sake of making a working example. Normally, you would simply use\n// flags.Parse(\u0026opts) which uses os.Args\nargs, err := flags.ParseArgs(\u0026opts, args)\n\nif err != nil {\n\tpanic(err)\n}\n\nfmt.Printf(\"Verbosity: %v\\n\", opts.Verbose)\nfmt.Printf(\"Offset: %d\\n\", opts.Offset)\nfmt.Printf(\"Name: %s\\n\", opts.Name)\nfmt.Printf(\"Animal: %s\\n\", opts.Animal)\nfmt.Printf(\"Ptr: %d\\n\", *opts.Ptr)\nfmt.Printf(\"StringSlice: %v\\n\", opts.StringSlice)\nfmt.Printf(\"PtrSlice: [%v %v]\\n\", *opts.PtrSlice[0], *opts.PtrSlice[1])\nfmt.Printf(\"IntMap: [a:%v b:%v]\\n\", opts.IntMap[\"a\"], opts.IntMap[\"b\"])\nfmt.Printf(\"Remaining args: %s\\n\", strings.Join(args, \" \"))\n\n// Output: Verbosity: [true true]\n// Offset: 5\n// Name: Me\n// Ptr: 3\n// StringSlice: [hello world]\n// PtrSlice: [hello world]\n// IntMap: [a:1 b:5]\n// Remaining args: arg1 arg2 arg3\n```\n\nMore information can be found in the godocs: \u003chttp://godoc.org/github.com/jessevdk/go-flags\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessevdk%2Fgo-flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjessevdk%2Fgo-flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessevdk%2Fgo-flags/lists"}