github.com/lheiskan/zebrapack@v4.1.1-0.20181107023619-e955d028f9bf+incompatible/cfg/config.go (about)

     1  package cfg
     2  
     3  import (
     4  	"flag"
     5  )
     6  
     7  type ZebraConfig struct {
     8  	Out        string
     9  	GoFile     string
    10  	Encode     bool
    11  	Marshal    bool
    12  	Tests      bool
    13  	Unexported bool
    14  
    15  	WriteSchema string
    16  	GenSchemaId bool
    17  
    18  	// for back-compatibity, generate msgpack2
    19  	// encoders instead of ZebraPack
    20  	UseMsgp2 bool
    21  
    22  	ReadStringsFast       bool
    23  	SchemaToGo            string
    24  	NoEmbeddedSchema      bool
    25  	NoEmbeddedStructNames bool
    26  
    27  	MethodPrefix string
    28  	NoLoad       bool
    29  }
    30  
    31  // call DefineFlags before myflags.Parse()
    32  func (c *ZebraConfig) DefineFlags(fs *flag.FlagSet) {
    33  	fs.StringVar(&c.Out, "o", "", "output file (default is {input_file}_gen.go")
    34  	fs.StringVar(&c.GoFile, "file", "", "input file (or directory); default is $GOFILE, which is set by the `go generate` command.")
    35  	fs.BoolVar(&c.Encode, "io", true, "create Encode and Decode methods")
    36  	fs.BoolVar(&c.Marshal, "marshal", true, "create Marshal and Unmarshal methods")
    37  	fs.BoolVar(&c.Tests, "tests", true, "create tests and benchmarks")
    38  	fs.BoolVar(&c.Unexported, "unexported", false, "also process unexported types")
    39  
    40  	fs.StringVar(&c.WriteSchema, "write-schema", "", "write schema (in msgpack2 format) to this file; - for stdout")
    41  	fs.BoolVar(&c.GenSchemaId, "genid", false, "generate a fresh random zebraSchemaId64 value to include in your Go source schema")
    42  	fs.BoolVar(&c.UseMsgp2, "msgp", false, "generate msgpack2 serializers instead of ZebraPack; for backward compatiblity and serializing the zebra.go schema itself.")
    43  	fs.BoolVar(&c.ReadStringsFast, "fast-strings", false, "for speed when reading a string in a message that won't be reused, this flag means we'll use unsafe to cast the string header and avoid allocation.")
    44  	fs.StringVar(&c.SchemaToGo, "schema-to-go", "", "(standalone functionality) path to schema in msgpack2 format; we will convert it to Go, write the Go on stdout, and exit immediately")
    45  	fs.BoolVar(&c.NoEmbeddedSchema, "no-embedded-schema", false, "don't embed the schema in the generated files")
    46  	fs.BoolVar(&c.NoEmbeddedStructNames, "no-structnames-onwire", false, "don't embed the name of the struct in the serialized zebrapack. Skipping the embedded struct names saves time and space and matches what protocol buffers/thrift/capnproto/msgpack do. You must know the type on the wire you expect; or embed a type tag in one universal wrapper struct. Embedded struct names are a feature of ZebraPack to help with dynamic language bindings.")
    47  	fs.StringVar(&c.MethodPrefix, "method-prefix", "", "(optional) prefix that will be pre-prended to the front of generated method names; useful when you need to avoid namespace collisions, but the generated tests will break/the msgp package interfaces won't be satisfied.")
    48  
    49  	fs.BoolVar(&c.NoLoad, "no-load", false, "don't use the Go loader, instead parse without full type checking and constant resolution; really only useful if you can't compile your source just now. With -no-load, as in msgp, we can't resolve the use of named constants from other packages.")
    50  }
    51  
    52  // call c.ValidateConfig() after myflags.Parse()
    53  func (c *ZebraConfig) ValidateConfig() error {
    54  	return nil
    55  }