attr: flag test methods (#177)

Adds a method to the Attribute type to test for each flag in the textflag.h header.
This commit is contained in:
Michael McLoughlin
2021-04-11 13:25:13 -07:00
committed by GitHub
parent c5faaae583
commit e9f28cafb8
3 changed files with 70 additions and 0 deletions

View File

@@ -197,4 +197,10 @@ func PrintFlagAttributes(w io.Writer, fs []Flag) {
fmt.Fprintf(w, "\t%s: %q,\n", f.Name, f.Name)
}
fmt.Fprintf(w, "}\n")
// Flag test methods.
for _, f := range fs {
fmt.Fprintf(w, "\n// %s reports whether the %s flag is set.\n", f.Name, f.Name)
fmt.Fprintf(w, "func (a Attribute) %s() bool { return (a & %s) != 0 }\n", f.Name, f.Name)
}
}