{"id":16714227,"url":"https://github.com/flier/go-bitflags","last_synced_at":"2025-03-28T11:24:47.902Z","repository":{"id":57651239,"uuid":"448964938","full_name":"flier/go-bitflags","owner":"flier","description":"Bitflags is a tool to automate generate code which behave like a set of bitflags","archived":false,"fork":false,"pushed_at":"2024-06-10T05:32:46.000Z","size":349,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-02T11:44:18.776Z","etag":null,"topics":[],"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/flier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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-01-17T16:19:50.000Z","updated_at":"2024-02-20T03:05:55.000Z","dependencies_parsed_at":"2024-02-20T04:23:31.340Z","dependency_job_id":"cc7f0216-eef4-4cce-b558-70d70f665500","html_url":"https://github.com/flier/go-bitflags","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/flier%2Fgo-bitflags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fgo-bitflags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fgo-bitflags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fgo-bitflags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flier","download_url":"https://codeload.github.com/flier/go-bitflags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246019060,"owners_count":20710506,"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":[],"created_at":"2024-10-12T20:49:56.218Z","updated_at":"2025-03-28T11:24:47.883Z","avatar_url":"https://github.com/flier.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-bitflags\n\n[![Go](https://github.com/flier/go-bitflags/actions/workflows/go.yml/badge.svg)](https://github.com/flier/go-bitflags/actions/workflows/go.yml)\n[![Report Card](https://goreportcard.com/badge/flier/go-bitflags)](https://goreportcard.com/report/flier/go-bitflags)\n[![GoDoc](https://pkg.go.dev/badge/flier/go-bitflags.svg)](https://pkg.go.dev/flier/go-bitflags)\n\nBitflags is a tool to automate the creation of methods that satisfy the\n`Bitflags` interface. Given the name of a (signed or unsigned) integer\ntype T that has constants defined, bitflags will create a new self-contained\nGo source file implementing\n\n    func (t T) Name() string\n\n    func (t T) String() string\n\n    func (t T) Contains(f T) bool\n\n    func (t T) \u003cFlag Name\u003e() bool\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\n## Installation\n\n    # Go 1.18+\n    go install github.com/flier/go-bitflags/cmd/bitflags@latest\n\n    # Go version \u003c 1.18\n    go get -u github.com/flier/go-bitflags/cmd/bitflags@latest\n\n## Usage\n\n`Bitflags` works best with constants that are consecutive values such as\ncreated using `iota`, but creates good code regardless. In the future it might\nalso provide custom support for constant sets that are bit patterns.\n\nFor example, given this snippet,\n\n```go\npackage painkiller\n\ntype Pill int\n\nconst (\n    Placebo Pill = 1 \u003c\u003c iota\n    Aspirin\n    Ibuprofen\n    Paracetamol\n    Acetaminophen = Paracetamol\n)\n```\n\nrunning this command\n\n    bitflags -type=Pill\n\nin the same directory will create the file pill_bitflags.go, in package\npainkiller, containing a definition\n\n``` go\n// Name of a single flag bit, e.g. Placebo\nfunc (Pill) Name() string\n\n// All flag bits that have been set, such as Placebo|Ibuprofen\nfunc (Pill) String() string\n\n// Whether the flag bit is set\nfunc (Pill) Contains(Pill) bool\n\nfunc (Pill) Placebo() bool\nfunc (Pill) Aspirin() bool\nfunc (Pill) Ibuprofen() bool\nfunc (Pill) Paracetamol() bool\nfunc (Pill) Acetaminophen() bool\n```\n\nThat method will translate the value of a Pill constant to the string\nrepresentation of the respective constant name, so that the call\n`fmt.Print(painkiller.Aspirin|painkiller.Paracetamol)` will print the string\n`Aspirin|Paracetamol`.\n\nTypically this process would be run using go generate, like this:\n\n    //go:generate bitflags --type=Pill\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.\nOtherwise, the arguments must name a single directory holding a Go package\nor a set of Go source 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_bitflags.go`,\nwhere t is the lower-cased name of the first type listed. It can be\noverridden with the -output flag.\n\nThe `--line-comment` flag tells bitflags to generate the text of any line\ncomment, trimmed of leading spaces, instead of the constant name. For\ninstance, if the constants above had a Pill prefix, one could write\n\n    PillAspirin // Aspirin\n\nto suppress it in the output.\n\nThe `--trim-prefix` flag tell bitflags to trim the 'prefix' from the generated constant names.\n\nThe `--tag` flag tells bitflags the list of build tags to apply.\n\n## Golang version\n\n`bitflags` is currently compatible with golang version from 1.16+.\n\n## Credits\n\nThe design of Bitflags was inspired by the [Stringer](https://pkg.go.dev/golang.org/x/tools/cmd/stringer) and [bitflags](https://github.com/bitflags/bitflags) crate, thanks to their great work.\n\n## License\n\nThis project is licensed under either of Apache-2.0 License ([LICENSE-APACHE](LICENSE-APACHE)) or MIT license ([LICENSE-MIT](LICENSE-MIT)) at your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in Futures by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflier%2Fgo-bitflags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflier%2Fgo-bitflags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflier%2Fgo-bitflags/lists"}