{"id":18464299,"url":"https://github.com/projectdiscovery/goflags","last_synced_at":"2025-05-16T07:04:35.484Z","repository":{"id":37445379,"uuid":"332050093","full_name":"projectdiscovery/goflags","owner":"projectdiscovery","description":"A go flag wrapper with convenience helpers","archived":false,"fork":false,"pushed_at":"2025-04-16T22:56:50.000Z","size":6956,"stargazers_count":89,"open_issues_count":12,"forks_count":17,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-05-15T17:09:14.027Z","etag":null,"topics":["goflags","hacktoberfest","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/projectdiscovery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2021-01-22T20:02:51.000Z","updated_at":"2025-05-04T06:38:59.000Z","dependencies_parsed_at":"2023-10-12T06:14:52.682Z","dependency_job_id":"fedbb244-7ab1-47ba-8fd2-2506ba8fff30","html_url":"https://github.com/projectdiscovery/goflags","commit_stats":{"total_commits":218,"total_committers":17,"mean_commits":"12.823529411764707","dds":0.7064220183486238,"last_synced_commit":"6de7e8a882aba48e42d1cb8c4ee9a579a5d7a86a"},"previous_names":[],"tags_count":84,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectdiscovery%2Fgoflags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectdiscovery%2Fgoflags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectdiscovery%2Fgoflags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectdiscovery%2Fgoflags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectdiscovery","download_url":"https://codeload.github.com/projectdiscovery/goflags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485055,"owners_count":22078767,"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":["goflags","hacktoberfest","library"],"created_at":"2024-11-06T09:09:23.470Z","updated_at":"2025-05-16T07:04:35.466Z","avatar_url":"https://github.com/projectdiscovery.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goflags\n\n[![License](https://img.shields.io/github/license/projectdiscovery/goflags)](LICENSE.md)\n![Go version](https://img.shields.io/github/go-mod/go-version/projectdiscovery/goflags?filename=go.mod)\n[![Release](https://img.shields.io/github/release/projectdiscovery/goflags)](https://github.com/projectdiscovery/goflags/releases/)\n[![Checks](https://github.com/projectdiscovery/goflags/actions/workflows/build-test.yml/badge.svg)](https://github.com/projectdiscovery/goflags/actions/workflows/build-test.yml)\n\nAn extension of the go `flag` library that adds convenience functions and functionalities like config file, better usage, short and long flag support, custom types for string slices and maps etc.\n\n## Features\n\n- In-built YAML Configuration file support.\n- Better usage instructions\n- Short and long flags support\n- Custom String Slice types with different options (comma-separated,normalized,etc)\n- Custom Map type\n- Flags grouping support (CreateGroup,SetGroup)\n\n## Usage\n\nThe following types are supported by the goflags library. The `\u003cname\u003eP` suffix means that the flag supports both a long and a short flag for the option.\n\n### Flag Types\n\n| Function                 | Description                                                         |\n|--------------------------|---------------------------------------------------------------------|\n| BoolVar                  | Boolean value with long name                                        |\n| BoolVarP                 | Boolean value with long short name                                  |\n| DurationVar              | Time Duration value with long name                                  |\n| DurationVarP             | Time Duration value with long short name                            |\n| IntVar                   | Integer value with long name                                        |\n| IntVarP                  | Integer value with long short name                                  |\n| PortVar                  | Port value with long name\t\t\t\t\t\t\t\t\t\t\t |\n| PortVarP                 | Port value with long short name\t\t\t\t\t\t\t\t\t |\n| RuntimeMapVar            | Map value with long name                                            |\n| RuntimeMapVarP           | Map value with long short name                                      |\n| StringSliceVar           | String Slice value with long name and options                       |\n| StringSliceVarConfigOnly | String Slice value with long name read from config file only        |\n| StringSliceVarP          | String slice value with long short name and options                 |\n| StringVar                | String value with long name                                         |\n| StringVarEnv             | String value with long short name read from environment             |\n| StringVarP               | String value with long short name                                   |\n| Var                      | Custom value with long name implementing flag.Value interface       |\n| VarP                     | Custom value with long short name implementing flag.Value interface |\n| EnumVar                  | Enum value with long name                                           |\n| EnumVarP                 | Enum value with long short name                                     |\n| CallbackVar\t\t\t   | Callback function as value with long name\t\t\t\t\t\t\t |\n| CallbackVarP\t\t\t   | Callback function as value with long short name\t\t\t\t\t |\n| SizeVar                  | String value with long name                                         |\n| SizeVarP                 | String value with long short name                                   |\n\n\n### String Slice Options\n\n| String Slice Option                  | Tokenization | Normalization | Description                                   |\n|--------------------------------------|--------------|---------------|-----------------------------------------------|\n| StringSliceOptions                   | None         | None          | Default String Slice                          |\n| CommaSeparatedStringSliceOptions     | Comma        | None          | Comma-separated string slice                  |\n| FileCommaSeparatedStringSliceOptions | Comma        | None          | Comma-separated items from file/cli           |\n| NormalizedOriginalStringSliceOptions | None         | Standard      | List of normalized string slice               |\n| FileNormalizedStringSliceOptions     | Comma        | Standard      | List of normalized string slice from file/cli |\n| FileStringSliceOptions               | Standard     | Standard      | List of string slice from file                |\n| NormalizedStringSliceOptions         | Comma        | Standard      | List of normalized string slice               |\n\n## Example\n\nAn example showing various options of the library is specified below.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/projectdiscovery/goflags\"\n)\n\ntype options struct {\n\tsilent bool\n\tinputs goflags.StringSlice\n\tconfig string\n\tvalues goflags.RuntimeMap\n}\n\nconst (\n\tNil goflags.EnumVariable = iota\n\tType1\n\tType2\n)\n\nfunc main() {\n\tenumAllowedTypes := goflags.AllowdTypes{\"type1\": Type1, \"type2\": Type2}\n\topt := \u0026options{}\n\n\tflagSet := goflags.NewFlagSet()\n\tflagSet.SetDescription(\"Test program to demonstrate goflags options\")\n\n\tflagSet.EnumVarP(\u0026options.Type, \"enum-type\", \"et\", Nil, \"Variable Type (type1/type2)\", enumAllowedTypes)\n\tflagSet.BoolVar(\u0026opt.silent, \"silent\", true, \"show silent output\")\n\tflagSet.StringSliceVarP(\u0026opt.inputs, \"inputs\", \"i\", nil, \"list of inputs (file,comma-separated)\", goflags.FileCommaSeparatedStringSliceOptions)\n\n\tupdate := func(tool string ) func() { \n\t\treturn func()  {\n\t\t\tfmt.Printf(\"%v updated successfully!\", tool)\n\t\t}\n\t}\n\tflagSet.CallbackVarP(update(\"tool_1\"), \"update\", \"up\", \"update tool_1\")\n\n\n\t// Group example\n\tflagSet.CreateGroup(\"config\", \"Configuration\",\n\t\tflagSet.StringVar(\u0026opt.config, \"config\", \"\", \"file to read config from\"),\n\t\tflagSet.RuntimeMapVar(\u0026opt.values, \"values\", nil, \"key-value runtime values\"),\n\t)\n\tif err := flagSet.Parse(); err != nil {\n\t\tlog.Fatalf(\"Could not parse flags: %s\\n\", err)\n\t}\n\tif opt.config != \"\" {\n\t\tif err := flagSet.MergeConfigFile(opt.config); err != nil {\n\t\t\tlog.Fatalf(\"Could not merge config file: %s\\n\", err)\n\t\t}\n\t}\n\tfmt.Printf(\"silent: %v inputs: %v config: %v values: %v\\n\", opt.silent, opt.inputs, opt.config, opt.values)\n}\n```\n\n### Thanks\n\n1. spf13/cobra - For the very nice usage template for the command line.\n2. nmap/nmap - For the service-port mapping and top-ports list.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectdiscovery%2Fgoflags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectdiscovery%2Fgoflags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectdiscovery%2Fgoflags/lists"}