{"id":18468344,"url":"https://github.com/profoak/flag2","last_synced_at":"2025-04-08T10:32:23.423Z","repository":{"id":50779593,"uuid":"61505336","full_name":"ProfOak/flag2","owner":"ProfOak","description":"A more traditional flag library for the go programming language","archived":false,"fork":false,"pushed_at":"2021-05-30T01:35:59.000Z","size":20,"stargazers_count":38,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T10:51:10.727Z","etag":null,"topics":["command-line","flag","golang","like","posix"],"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/ProfOak.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":"2016-06-19T23:38:31.000Z","updated_at":"2021-05-30T01:36:02.000Z","dependencies_parsed_at":"2022-08-24T00:41:24.490Z","dependency_job_id":null,"html_url":"https://github.com/ProfOak/flag2","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/ProfOak%2Fflag2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProfOak%2Fflag2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProfOak%2Fflag2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProfOak%2Fflag2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProfOak","download_url":"https://codeload.github.com/ProfOak/flag2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247824096,"owners_count":21002206,"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","flag","golang","like","posix"],"created_at":"2024-11-06T10:05:54.265Z","updated_at":"2025-04-08T10:32:22.838Z","avatar_url":"https://github.com/ProfOak.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Flag2\n---\nA more traditional flag library for the go programming language\n\nWhat?\n---\n\nA more traditional flag library for the Go programming language. I also have a long history with Python, so the implimentation code looks similar to Python's argparse class.\n\nWhy?\n---\n\nI did not like how the flag library that comes with Go parses command line flags.\n\nDifferences\n---\n\n* You can define full word flags with the `--` prefix. You can define single character flags with the `-` prefix.\n\n* Example of a full word flag: `--help`\n\n* Example of a single character flag: `-h`\n\n* Single character strings can be grouped, but only for boolean types: `-abcd` is essentially `-a, -b, -c, -d`\n  * This only works for boolean type flags\n\n* `--` denotes the end of the command line flag options\n  * Everything to the right of `--` will not be counted as flags\n\nGetting started\n---\n\nTo install: `go get github.com/ProfOak/flag2`\n\n```\npackage main\n\nimport (\n    \"os\"\n    \"fmt\"\n    \"github.com/ProfOak/flag2\"\n)\n\nfunc main() {\n    f := flag2.NewFlag()\n\n    // short flag, long flag, description, default argument\n    f.AddString(\"n\", \"name\", \"this flag wants a name as input\", \"billy\")\n    f.AddBool(\"b\", \"bool\", \"this flag will store true\", false)\n\n    // a help flag is added during the parse step\n    options, args := f.Parse(os.Args)\n\n    // A usage method is provided, with details about each flag\n\n    // unfortunate side effect of interfaces\n    if options[\"help\"] == true {\n        f.Usage()\n    }\n\n    fmt.Println()\n    if options[\"name\"] != nil {\n        fmt.Println(\"The name is:\", options[\"name\"])\n    }\n\n    fmt.Println()\n    fmt.Println(\"===== FINAL RESULTS =====\")\n    fmt.Println(\"Options:\", options)\n    fmt.Println(\"Args:\", args)\n}\n\n```\n\nThe result of running this program:\n\n```\ngo run main.go -b -n ProfOak Extra args\n\n--- Bools ---\n-b, --bool      this flag will store true\n-h, --help      Display this message and exit\n\n--- Strings ---\n-n, --name      this flag wants a name as input\n\nName is: ProfOak\n\n===== FINAL RESULTS =====\nOptions: map[help:true bool:true name:ProfOak]\nArgs: [Extra args]\n\n```\n\nReference ./test/test.go for a more detailed example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofoak%2Fflag2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofoak%2Fflag2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofoak%2Fflag2/lists"}