From ae561ba734fe42a9b2e9aa6fcb4cc5d942521cd7 Mon Sep 17 00:00:00 2001 From: Dan Markham Date: Tue, 23 Apr 2019 21:21:16 -0700 Subject: [PATCH] Adding in the Usage --- README.md | 37 ++++++++++++++++++++++++++++++++++--- stringer.go | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2533dfe..7560c57 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,40 @@ maintained by [Álvaro López Espinosa](https://github.com/alvaroloes/enumer). This was again forked here as (https://github.com/dmarkham/enumer) picking up where Álvaro left off. +``` +$ ./enumer --help +Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type). +Usage of ./enumer: + Enumer [flags] -type T [directory] + Enumer [flags] -type T files... # Must be a single package +For more information, see: + http://godoc.org/github.com/dmarkham/enumer +Flags: + -addprefix string + transform each item name by adding a prefix. Default: "" + -comment value + comments to include in generated code, can repeat. Default: "" + -json + if true, json marshaling methods will be generated. Default: false + -linecomment + use line comment text as printed text when present + -output string + output file name; default srcdir/_string.go + -sql + if true, the Scanner and Valuer interface will be implemented. + -text + if true, text marshaling methods will be generated. Default: false + -transform string + enum item name transformation method. Default: noop (default "noop") + -trimprefix string + transform each item name by removing a prefix. Default: "" + -type string + comma-separated list of type names; must be set + -yaml + if true, yaml marshaling methods will be generated. Default: false +``` + + ## Generated functions and methods When Enumer is applied to a type, it will generate: @@ -157,9 +191,6 @@ name := MyTypeValue.String() // name => "my_type_value" ## How to use -The usage of Enumer is the same as Stringer, so you can refer to the [Stringer docs](https://godoc.org/golang.org/x/tools/cmd/stringer) -for more information. - There are four boolean flags: `json`, `text`, `yaml` and `sql`. You can use any combination of them (i.e. `enumer -type=Pill -json -text`), For enum string representation transformation the `transform` and `trimprefix` flags diff --git a/stringer.go b/stringer.go index a419444..9475072 100644 --- a/stringer.go +++ b/stringer.go @@ -64,7 +64,7 @@ func init() { // Usage is a replacement usage function for the flags package. func Usage() { - _, _ = fmt.Fprintf(os.Stderr, "Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).") + _, _ = fmt.Fprintf(os.Stderr, "Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).\n") _, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) _, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T [directory]\n") _, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T files... # Must be a single package\n")