mweibel / fmarshal

marshals a struct type into a slice of CLI arguments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fmarshal

GoDoc build

go get github.com/mweibel/fmarshal

Package fmarshal marshals a struct type into a slice of CLI arguments.

Note: This package does not do any shell escaping. It just quotes flag values if quote is true.

Example:

type Args struct {
  Debug   bool   `flag:"--debug"`
  Level   string `flag:"--level"`
  Numeric int    `flag:"-n"`
  Omit    string `flag:"-omit,omitempty"`
}

a := Args{
  Debug: true,
  Level: "info",
  Numeric: 42
}
fmt.Println(strings.Join(MarshalFlag(a, true), " "))
// Output: --debug=true --level=info -n 42

About

marshals a struct type into a slice of CLI arguments.

License:MIT License


Languages

Language:Go 100.0%