finish generation of flag types for altsrc package
rename package to fg (flag generator)
This commit is contained in:
parent
32ddef5ca7
commit
16c7a60528
@ -25,10 +25,10 @@ type FlagType struct {
|
||||
ParserCast string `json:"parser_cast"`
|
||||
}
|
||||
|
||||
var cliFlagTemplate = `// Code generated by fg; DO NOT EDIT.
|
||||
var flagTemplate = `// Code generated by fg; DO NOT EDIT.
|
||||
|
||||
package {{ .PackageName }}
|
||||
|
||||
{{ if eq .PackageName "cli" }}
|
||||
import (
|
||||
"flag"
|
||||
"strconv"
|
||||
@ -93,7 +93,42 @@ func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextTyp
|
||||
}
|
||||
return {{ $flag.ContextDefault }}
|
||||
}
|
||||
{{- end }}`
|
||||
{{- end }}
|
||||
{{ else }}
|
||||
import (
|
||||
"flag"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
{{ range $i, $flag := .Flags }}
|
||||
// {{ $flag.Name }}Flag is the flag type that wraps cli.{{ $flag.Name }}Flag to allow
|
||||
// for other values to be specified
|
||||
type {{ $flag.Name }}Flag struct {
|
||||
cli.{{ $flag.Name }}Flag
|
||||
set *flag.FlagSet
|
||||
}
|
||||
|
||||
// New{{ $flag.Name }}Flag creates a new {{ $flag.Name }}Flag
|
||||
func New{{ $flag.Name }}Flag(fl cli.{{ $flag.Name }}Flag) *{{ $flag.Name }}Flag {
|
||||
return &{{ $flag.Name }}Flag{ {{ $flag.Name }}Flag: fl, set: nil }
|
||||
}
|
||||
|
||||
// Apply saves the flagSet for later usage calls, then calls
|
||||
// the wrapped {{ $flag.Name }}Flag.Apply
|
||||
func (f *{{ $flag.Name }}Flag) Apply(set *flag.FlagSet) {
|
||||
f.set = set
|
||||
f.{{ $flag.Name }}Flag.Apply(set)
|
||||
}
|
||||
|
||||
// ApplyWithError saves the flagSet for later usage calls, then calls
|
||||
// the wrapped {{ $flag.Name }}Flag.ApplyWithError
|
||||
func (f *{{ $flag.Name }}Flag) ApplyWithError(set *flag.FlagSet) error {
|
||||
f.set = set
|
||||
return f.{{ $flag.Name }}Flag.ApplyWithError(set)
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
`
|
||||
|
||||
func main() {
|
||||
var packageName, inputPath, outputPath string
|
||||
@ -125,6 +160,8 @@ func main() {
|
||||
|
||||
app.Action = func(c *cli.Context) error {
|
||||
var info CliFlagInfo
|
||||
var tpl *template.Template
|
||||
|
||||
info.PackageName = packageName
|
||||
|
||||
inFile, err := os.Open(inputPath)
|
||||
@ -141,7 +178,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
tpl := template.Must(template.New("").Parse(cliFlagTemplate))
|
||||
tpl = template.Must(template.New("").Parse(flagTemplate))
|
||||
|
||||
outFile, err := os.Create(outputPath)
|
||||
if err != nil {
|
Loading…
Reference in New Issue
Block a user