{"id":13713568,"url":"https://github.com/igrmk/yamlenums","last_synced_at":"2025-08-01T16:40:40.410Z","repository":{"id":57546076,"uuid":"266928488","full_name":"igrmk/yamlenums","owner":"igrmk","description":"This tool is similar to golang.org/x/tools/cmd/stringer but generates MarshalYAML and UnmarshalYAML methods","archived":false,"fork":false,"pushed_at":"2023-12-26T08:21:32.000Z","size":5119,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-03T23:27:26.748Z","etag":null,"topics":["code-generator","go","golang","yaml"],"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/igrmk.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":"2020-05-26T02:43:56.000Z","updated_at":"2023-12-26T08:29:24.000Z","dependencies_parsed_at":"2024-06-20T17:18:25.099Z","dependency_job_id":"56810307-eb79-403d-abc9-a833c7a0bfec","html_url":"https://github.com/igrmk/yamlenums","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/igrmk%2Fyamlenums","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrmk%2Fyamlenums/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrmk%2Fyamlenums/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrmk%2Fyamlenums/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igrmk","download_url":"https://codeload.github.com/igrmk/yamlenums/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243532517,"owners_count":20306151,"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":["code-generator","go","golang","yaml"],"created_at":"2024-08-02T23:01:39.445Z","updated_at":"2025-03-14T05:32:06.066Z","avatar_url":"https://github.com/igrmk.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# yamlenums\n\n[![Build Status](https://api.travis-ci.com/igrmk/yamlenums.svg)](https://app.travis-ci.com/github/igrmk/yamlenums)\n[![GoReportCard](https://goreportcard.com/badge/igrmk/yamlenums)](https://goreportcard.com/report/igrmk/yamlenums)\n\nyamlenums is a tool to automate the creation of methods that satisfy the\n`yaml.Marshaler` and `yaml.Unmarshaler` interfaces.\nGiven the name of a (signed or unsigned) integer type T that has constants\ndefined, yamlenums will create a new self-contained Go source file implementing\n\n```\nfunc (t T) MarshalYAML() ([]byte, error)\nfunc (t *T) UnmarshalYAML(unmarshal func(v interface{}) error) error\n```\n\nThe file is created in the same package and directory as the package that\ndefines T. It has helpful defaults designed for use with go generate.\n\nyamlenums is a copy and a small rework of https://github.com/campoy/jsonenums.\n\njsonenums is a simple implementation of a concept and the code might not be the\nmost performant or beautiful to read.\n\nFor example, given this snippet,\n\n```Go\npackage painkiller\n\ntype Pill int\n\nconst (\n\tPlacebo Pill = iota\n\tAspirin\n\tIbuprofen\n\tParacetamol\n\tAcetaminophen = Paracetamol\n)\n```\n\nrunning this command\n\n```\nyamlenums -type=Pill\n```\n\nin the same directory will create the file `pill_yamlenums.go`, in package\n`painkiller`, containing a definition of\n\n```\nfunc (r Pill) MarshalYAML() ([]byte, error)\nfunc (r *Pill) UnmarshalYAML(unmarshal func(v interface{}) error) error\n```\n\n`MarshalYAML` will translate the value of a `Pill` constant to the `[]byte`\nrepresentation of the respective constant name, so that the call\n`yaml.Marshal(painkiller.Aspirin)` will return the bytes `[]byte(\"\\\"Aspirin\\\"\")`.\n\n`UnmarshalYAML` performs the opposite operation;\nit unmarshals underlying bytes to a string, given the string\nrepresentation of a `Pill` constant it will change the receiver to equal the\ncorresponding constant. So given the string `\"Aspirin\"` the receiver will\nchange to `Aspirin` and the returned error will be `nil`.\n\nTypically this process would be run using go generate, like this:\n\n```\n//go:generate yamlenums -type=Pill\n```\n\nIf multiple constants have the same value, the lexically first matching name\nwill be used (in the example, Acetaminophen will print as \"Paracetamol\").\n\nWith no arguments, it processes the package in the current directory. Otherwise,\nthe arguments must name a single directory holding a Go package or a set of Go\nsource files that represent a single Go package.\n\nThe `-type` flag accepts a comma-separated list of types so a single run can\ngenerate methods for multiple types. The default output file is t_yamlenums.go,\nwhere t is the lower-cased name of the first type listed. The suffix can be\noverridden with the `-suffix` flag and a prefix may be added with the `-prefix` \nflag.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrmk%2Fyamlenums","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figrmk%2Fyamlenums","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrmk%2Fyamlenums/lists"}