{"id":21910085,"url":"https://github.com/mmatczuk/anyflag","last_synced_at":"2025-10-29T03:42:31.488Z","repository":{"id":61624971,"uuid":"539905453","full_name":"mmatczuk/anyflag","owner":"mmatczuk","description":"Generic implementation of Cobra Value and SliceValue types","archived":false,"fork":false,"pushed_at":"2024-07-09T09:03:39.000Z","size":36,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-16T02:13:32.584Z","etag":null,"topics":["cli","cobra","flags","go","golang","slice","struct","value"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmatczuk.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":"2022-09-22T09:38:48.000Z","updated_at":"2025-04-09T10:22:41.000Z","dependencies_parsed_at":"2024-01-05T10:31:21.744Z","dependency_job_id":"bf9e688d-f619-44c6-867d-35c284157756","html_url":"https://github.com/mmatczuk/anyflag","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fanyflag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fanyflag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fanyflag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmatczuk%2Fanyflag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmatczuk","download_url":"https://codeload.github.com/mmatczuk/anyflag/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183111,"owners_count":21226143,"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":["cli","cobra","flags","go","golang","slice","struct","value"],"created_at":"2024-11-28T17:28:22.903Z","updated_at":"2025-10-29T03:42:31.396Z","avatar_url":"https://github.com/mmatczuk.png","language":"Go","readme":"# Anyflag\n\n[![Build Status](https://github.com/mmatczuk/anyflag/actions/workflows/go.yml/badge.svg)](https://github.com/mmatczuk/anyflag/actions/workflows/go.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mmatczuk/anyflag)](https://goreportcard.com/report/github.com/mmatczuk/anyflag)\n\nAnyflag is an implementation of [Cobra](https://github.com/spf13/cobra) `pflag.Value` and `pflag.SliceValue` interfaces using Go Generics.\n\nTo bind your custom type to a flag, all you have to do is specify the value type and parser function, and you are done, no boilerplate.  \n\nIt supports any type including, but not limited to: enums, maps, slices, structs, struct pointers. \n\nIt also supports defining custom String() functions to redact passwords, see [redact example](examples/redact/cmd.go).\n## Installation\n\n```bash\ngo get github.com/mmatczuk/anyflag\n```\n\n## Examples\n\nThis example shows how `anytype` can be used for JSON encoded maps.\n\n```go\nfunc parseJSONMap(val string) (map[string]interface{}, error) {\n\tvar m map[string]interface{}\n\treturn m, json.Unmarshal([]byte(val), \u0026m)\n}\n\nfunc newCommand() *cobra.Command {\n\tvar m map[string]interface{}\n\n\tcmd := \u0026cobra.Command{\n\t\tUse: \"json-map\",\n\t\tRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Fprintln(cmd.OutOrStdout(), m)\n\t\t},\n\t}\n\n\tfs := cmd.Flags()\n\tvalue := anyflag.NewValue[map[string]interface{}](nil, \u0026m, parseJSONMap)\n\n\tfs.VarP(value, \"map\", \"\", \"map\")\n\n\treturn cmd\n}\n\nfunc main() {\n\tnewCommand().Execute()\n}\n```\n\nMore examples can be found in [examples](examples) directory.\n\n## License\n\nThis project is based on [spf13/pflag](https://github.com/spf13/pflag) licensed under the BSD 3-Clause \"New\" or \"Revised\" License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmatczuk%2Fanyflag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmatczuk%2Fanyflag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmatczuk%2Fanyflag/lists"}