Skip to content

Commit 0abe832

Browse files
committed
note in the readme and flag help description that trimprefix accepts lists
1 parent 870b5b9 commit 0abe832

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ This was again forked here as (https://github.com/dmarkham/enumer) picking up wh
77

88

99
```
10-
$ ./enumer --help
10+
$ enumer --help
1111
Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).
12-
Usage of ./enumer:
12+
Usage of enumer:
1313
Enumer [flags] -type T [directory]
1414
Enumer [flags] -type T files... # Must be a single package
1515
For more information, see:
@@ -34,11 +34,11 @@ Flags:
3434
-transform string
3535
enum item name transformation method. Default: noop (default "noop")
3636
-trimprefix string
37-
transform each item name by removing a prefix. Default: ""
37+
transform each item name by removing a prefix or comma separated list of prefixes. Default: ""
3838
-type string
3939
comma-separated list of type names; must be set
4040
-values
41-
if true, alternative string values method will be generated. Default: false
41+
if true, alternative string values method will be generated. Default: false
4242
-yaml
4343
if true, yaml marshaling methods will be generated. Default: false
4444
```
@@ -208,7 +208,8 @@ Possible transform values are listed above in the [transformers](#transformers)
208208
The default value for `transform` flag is `noop` which means no transformation will be performed.
209209

210210
If a prefix is provided via the `trimprefix` flag, it will be trimmed from the start of each name (before
211-
it is transformed). If a name doesn't have the prefix it will be passed unchanged.
211+
it is transformed). You can trim multiple prefixes by passing a comma separated list.
212+
If a name doesn't have the prefix it will be passed unchanged.
212213

213214
If a prefix is provided via the `addprefix` flag, it will be added to the start of each name (after trimming and after transforming).
214215

stringer.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var (
5353
altValuesFunc = flag.Bool("values", false, "if true, alternative string values method will be generated. Default: false")
5454
output = flag.String("output", "", "output file name; default srcdir/<type>_string.go")
5555
transformMethod = flag.String("transform", "noop", "enum item name transformation method. Default: noop")
56-
trimPrefix = flag.String("trimprefix", "", "transform each item name by removing a prefix. Default: \"\"")
56+
trimPrefix = flag.String("trimprefix", "", "transform each item name by removing a prefix or comma separated list of prefixes. Default: \"\"")
5757
addPrefix = flag.String("addprefix", "", "transform each item name by adding a prefix. Default: \"\"")
5858
linecomment = flag.Bool("linecomment", false, "use line comment text as printed text when present")
5959
)
@@ -774,9 +774,9 @@ func (g *Generator) buildOneRun(runs [][]Value, typeName string) {
774774
}
775775

776776
// Arguments to format are:
777-
// [1]: type name
778-
// [2]: size of index element (8 for uint8 etc.)
779-
// [3]: less than zero check (for signed types)
777+
// [1]: type name
778+
// [2]: size of index element (8 for uint8 etc.)
779+
// [3]: less than zero check (for signed types)
780780
const stringOneRun = `func (i %[1]s) String() string {
781781
if %[3]si >= %[1]s(len(_%[1]sIndex)-1) {
782782
return fmt.Sprintf("%[1]s(%%d)", i)
@@ -786,10 +786,10 @@ const stringOneRun = `func (i %[1]s) String() string {
786786
`
787787

788788
// Arguments to format are:
789-
// [1]: type name
790-
// [2]: lowest defined value for type, as a string
791-
// [3]: size of index element (8 for uint8 etc.)
792-
// [4]: less than zero check (for signed types)
789+
// [1]: type name
790+
// [2]: lowest defined value for type, as a string
791+
// [3]: size of index element (8 for uint8 etc.)
792+
// [4]: less than zero check (for signed types)
793793
const stringOneRunWithOffset = `func (i %[1]s) String() string {
794794
i -= %[2]s
795795
if %[4]si >= %[1]s(len(_%[1]sIndex)-1) {

0 commit comments

Comments
 (0)