{"id":20728980,"url":"https://github.com/gers2017/flago","last_synced_at":"2025-12-16T09:34:08.378Z","repository":{"id":39656689,"uuid":"491314568","full_name":"Gers2017/flago","owner":"Gers2017","description":"🐉 Simple and Flexible Command line flag parser in go (Working on it)","archived":false,"fork":false,"pushed_at":"2022-07-29T15:43:20.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T00:08:56.610Z","etag":null,"topics":["command-line","command-line-parser","flag-parser","flags","go","golang","parser"],"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/Gers2017.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}},"created_at":"2022-05-12T00:41:30.000Z","updated_at":"2022-06-02T02:45:28.000Z","dependencies_parsed_at":"2022-09-15T20:50:13.819Z","dependency_job_id":null,"html_url":"https://github.com/Gers2017/flago","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gers2017%2Fflago","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gers2017%2Fflago/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gers2017%2Fflago/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gers2017%2Fflago/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gers2017","download_url":"https://codeload.github.com/Gers2017/flago/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243011399,"owners_count":20221601,"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":["command-line","command-line-parser","flag-parser","flags","go","golang","parser"],"created_at":"2024-11-17T04:40:48.797Z","updated_at":"2025-12-16T09:34:08.280Z","avatar_url":"https://github.com/Gers2017.png","language":"Go","readme":"# Flago\n### 🐉 Simple and Flexible Command line flag parser\n\u003cbr\u003e\n\n[![Stars](https://img.shields.io/github/stars/Gers2017/flago.svg?style=for-the-badge)](https://github.com/Gers2017/flago/stargazers)\n[![Issues](https://img.shields.io/github/issues/Gers2017/flago.svg?style=for-the-badge)](https://github.com/Gers2017/flago/issues)\n[![Contributors](https://img.shields.io/github/contributors/Gers2017/flago?style=for-the-badge)](https://github.com/Gers2017/flago/graphs/contributors)\n[![LICENSE](https://img.shields.io/github/license/Gers2017/flago.svg?style=for-the-badge)](./LICENSE)\n[![Pkg.go](https://img.shields.io/badge/reference-12c9c0?style=for-the-badge\u0026logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/Gers2017/flago)\n\n\n## Install ⭐️\n\n```sh\ngo get github.com/Gers2017/flago\n```\n\n## Basic Usage 🔥\nImport flago\n```go\nimport (\n    \"github.com/Gers2017/flago\"\n)\n```\n\nPopulate the flagset\n```go\nget := flago.NewFlagSet(\"get\")\nget.Bool(\"all\", false)\nget.Switch(\"verbose\") // Same as get.Bool(\"verbose\", false)\n```\n### Builder\n```go\nget := flago.NewFlagSet(\"get\").\n    Bool(\"all\", false).\n    Switch(\"verbose\") // Same as get.Bool(\"verbose\", false)\n```\n### Using the Cli struct\n```go\ncli := flago.NewCli()\ncli.Handle(get, func(fs *flago.FlagSet) error {\n    HandleFlagset(fs) // do something with parsed get\n    return nil\n})\n\nif err := cli.Execute(os.Args); err != nil {\n    log.Fatal(err)\n}\n```\n\n```go \nfunc HandleFlagset(fs *flago.FlagSet) {\n    if fs.Bool(\"help\") {\n\t\tfmt.Println(\"Some helpful help message\")\n\t\treturn\n\t}\n\n    // Do something...\n    fmt.Println(todos)\n}\n```\n### Without the Cli struct\nParse the arguments into flags\n```go\n// os.Args = []string{ \"cli\", \"all\", \"help\" }\nif err := get.ParseFlags(os.Args[1:]); err != nil {\n    log.Fatal(err)\n    return\n}\n```\n\nThen use the parsed flagset\n```go\nif get.IsParsed(\"all\") {\n    if get.Bool(\"help\") {\n        fmt.Println(\"Some helpful help message\")\n        return\n    }\n    // Do something...\n    fmt.Println(todos)\n}\n```\n\n## Demo 🐲\nA complete example can be found **[here](./demo/demo.go)**\n\n### New FlagSet\n```go\nget := flago.NewFlagSet(\"get\")\n```\n\n### Add flags\n```go\nget.SetSwitch(\"verbose\")\nget.Int(\"x\", 0)\n```\n\n### Check if a flag was parsed\nIt's highly recommended to use this method to check first if a flag was parsed correctly.\n```go\nget.IsParsed(\"your-flag-name\")\n```\nThe `FlagSet.[Bool, Int, Float, Str]` methods are just a shortcut for:\n\n### Get values\n```go\nverbose := get.Bool(\"verbose\")\nx := get.Int(\"x\")\n```\n\nIf the flag name inside the getter method is not registered in the flagset, you'll get an error at runtime.\n```go\nwrong := get.Bool(\"some-invalid-flag\")\n```\n\n## About the API\n\n### Why so many strings? Isn't that error-prone?\n1) The `FlagSet.[Bool, Int, Float, Str]` method can raise an error at runtine (use `FlagSet.IsParsed` to avoid this)\n\n2)  A note on golang's generics\n    Behind the scenes flago uses maps + generics + type parsing\n    The `Flag struct` contains a `Value` property of type `any`.\n    \n    Because if we try to use generics we'd need to declare a map for every type of flag inside Flagset, and `Flags map[string]*Flag` wouldn't work anymore leading to repeated code.\n\n    The flag module in the standard library solves this by using pointers to the underliying values.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgers2017%2Fflago","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgers2017%2Fflago","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgers2017%2Fflago/lists"}