From e01e3c540c7aea9e4e9740d002bd212491c2fe00 Mon Sep 17 00:00:00 2001 From: mingrammer Date: Wed, 6 Mar 2019 23:51:22 +0900 Subject: [PATCH 01/31] Fix the unaligned indents for the commands that have no categories --- app_test.go | 6 +++--- help.go | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app_test.go b/app_test.go index ad49464..69d1418 100644 --- a/app_test.go +++ b/app_test.go @@ -136,8 +136,8 @@ func ExampleApp_Run_appHelp() { // Oliver Allen // // COMMANDS: - // describeit, d use it to see a description - // help, h Shows a list of commands or help for one command + // describeit, d use it to see a description + // help, h Shows a list of commands or help for one command // // GLOBAL OPTIONS: // --name value a name to say (default: "bob") @@ -190,7 +190,7 @@ func ExampleApp_Run_noAction() { // [global options] command [command options] [arguments...] // // COMMANDS: - // help, h Shows a list of commands or help for one command + // help, h Shows a list of commands or help for one command // // GLOBAL OPTIONS: // --help, -h show help diff --git a/help.go b/help.go index 65874fa..126cc7c 100644 --- a/help.go +++ b/help.go @@ -30,8 +30,9 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: COMMANDS:{{range .VisibleCategories}}{{if .Name}} - {{.Name}}:{{end}}{{range .VisibleCommands}} - {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + {{.Name}}:{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} GLOBAL OPTIONS: {{range $index, $option := .VisibleFlags}}{{if $index}} @@ -71,9 +72,11 @@ USAGE: {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} COMMANDS:{{range .VisibleCategories}}{{if .Name}} - {{.Name}}:{{end}}{{range .VisibleCommands}} - {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}} -{{end}}{{if .VisibleFlags}} + + {{.Name}}:{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + OPTIONS: {{range .VisibleFlags}}{{.}} {{end}}{{end}} From 9766be8d3e11e71a2a4bb5c235fc6961278df983 Mon Sep 17 00:00:00 2001 From: mingrammer Date: Thu, 7 Mar 2019 00:04:18 +0900 Subject: [PATCH 02/31] get latest changes from master --- .gitignore | 1 + README.md | 2 +- altsrc/flag.go | 2 +- altsrc/flag_generated.go | 2 +- altsrc/flag_test.go | 2 +- altsrc/input_source_context.go | 2 +- altsrc/json_command_test.go | 2 +- altsrc/json_source_context.go | 2 +- altsrc/map_input_source.go | 2 +- altsrc/toml_command_test.go | 2 +- altsrc/toml_file_loader.go | 2 +- altsrc/yaml_command_test.go | 2 +- altsrc/yaml_file_loader.go | 2 +- flaggen/main.go | 28 ++++++++++++++++++++++++++++ go.mod | 8 ++++++++ go.sum | 6 ++++++ help.go | 6 ++---- 17 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 flaggen/main.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/.gitignore b/.gitignore index faf70c4..7a7e2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.coverprofile node_modules/ +vendor \ No newline at end of file diff --git a/README.md b/README.md index 6eb2996..9904334 100644 --- a/README.md +++ b/README.md @@ -874,7 +874,7 @@ Will include: ``` COMMANDS: - noop + noop Template actions: add diff --git a/altsrc/flag.go b/altsrc/flag.go index 84ef009..376733a 100644 --- a/altsrc/flag.go +++ b/altsrc/flag.go @@ -6,7 +6,7 @@ import ( "strings" "syscall" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) // FlagInputSourceExtension is an extension interface of cli.Flag that diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go index 0aeb0b0..08170ca 100644 --- a/altsrc/flag_generated.go +++ b/altsrc/flag_generated.go @@ -3,7 +3,7 @@ package altsrc import ( "flag" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) // WARNING: This file is generated! diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index cd18294..5f293bb 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) type testApplyInputSource struct { diff --git a/altsrc/input_source_context.go b/altsrc/input_source_context.go index 276dcda..8ea7e92 100644 --- a/altsrc/input_source_context.go +++ b/altsrc/input_source_context.go @@ -3,7 +3,7 @@ package altsrc import ( "time" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) // InputSourceContext is an interface used to allow diff --git a/altsrc/json_command_test.go b/altsrc/json_command_test.go index 1f9af36..f24cae6 100644 --- a/altsrc/json_command_test.go +++ b/altsrc/json_command_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) const ( diff --git a/altsrc/json_source_context.go b/altsrc/json_source_context.go index 47ce82c..a5b2b0d 100644 --- a/altsrc/json_source_context.go +++ b/altsrc/json_source_context.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) // NewJSONSourceFromFlagFunc returns a func that takes a cli.Context diff --git a/altsrc/map_input_source.go b/altsrc/map_input_source.go index a111eee..e8cb060 100644 --- a/altsrc/map_input_source.go +++ b/altsrc/map_input_source.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) // MapInputSource implements InputSourceContext to return diff --git a/altsrc/toml_command_test.go b/altsrc/toml_command_test.go index a5053d4..1d91d56 100644 --- a/altsrc/toml_command_test.go +++ b/altsrc/toml_command_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) func TestCommandTomFileTest(t *testing.T) { diff --git a/altsrc/toml_file_loader.go b/altsrc/toml_file_loader.go index 87bb9d9..127693a 100644 --- a/altsrc/toml_file_loader.go +++ b/altsrc/toml_file_loader.go @@ -10,7 +10,7 @@ import ( "reflect" "github.com/BurntSushi/toml" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) type tomlMap struct { diff --git a/altsrc/yaml_command_test.go b/altsrc/yaml_command_test.go index 9d3f431..31f78ce 100644 --- a/altsrc/yaml_command_test.go +++ b/altsrc/yaml_command_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" ) func TestCommandYamlFileTest(t *testing.T) { diff --git a/altsrc/yaml_file_loader.go b/altsrc/yaml_file_loader.go index 202469f..2177c75 100644 --- a/altsrc/yaml_file_loader.go +++ b/altsrc/yaml_file_loader.go @@ -14,7 +14,7 @@ import ( "runtime" "strings" - "gopkg.in/urfave/cli.v1" + "github.com/urfave/cli" "gopkg.in/yaml.v2" ) diff --git a/flaggen/main.go b/flaggen/main.go new file mode 100644 index 0000000..02af0d8 --- /dev/null +++ b/flaggen/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "github.com/urfave/cli" + "log" + "os" +) + +func main() { + app := cli.NewApp() + + app.Name = "flaggen" + app.Usage = "Generate flag type code!" + + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "package, p", + Value: "cli", + Usage: "`Name of the package` for which the flag types will be generated", + }, + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } + +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d5b55c4 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/urfave/cli + +go 1.12 + +require ( + github.com/BurntSushi/toml v0.3.1 + gopkg.in/yaml.v2 v2.2.2 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a2ea702 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/help.go b/help.go index 126cc7c..d611971 100644 --- a/help.go +++ b/help.go @@ -240,10 +240,8 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc m funcMap := template.FuncMap{ "join": strings.Join, } - if customFunc != nil { - for key, value := range customFunc { - funcMap[key] = value - } + for key, value := range customFunc { + funcMap[key] = value } w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) From 32ddef5ca7f20a9aa0e7b80484e59d1653e856e4 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sat, 3 Aug 2019 21:48:48 +0530 Subject: [PATCH 03/31] finish generation of flag types for cli package --- flaggen/flag_generated.gotpl | 0 flaggen/main.go | 147 +++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 flaggen/flag_generated.gotpl diff --git a/flaggen/flag_generated.gotpl b/flaggen/flag_generated.gotpl new file mode 100644 index 0000000..e69de29 diff --git a/flaggen/main.go b/flaggen/main.go index 02af0d8..cbaba90 100644 --- a/flaggen/main.go +++ b/flaggen/main.go @@ -1,28 +1,165 @@ package main import ( + "encoding/json" "github.com/urfave/cli" "log" "os" + "text/template" ) +type CliFlagInfo struct { + PackageName string + Flags []FlagType +} + +type FlagType struct { + Name string `json:"name"` + Type string `json:"type"` + Value bool `json:"value"` + Destination bool `json:"dest"` + Doctail string `json:"doctail"` + ContextDefault string `json:"context_default"` + ContextType string `json:"context_type"` + Parser string `json:"parser"` + ParserCast string `json:"parser_cast"` +} + +var cliFlagTemplate = `// Code generated by fg; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "flag" + "strconv" + "time" +) +{{ range $i, $flag := .Flags }} +// {{ $flag.Name }}Flag is a flag with type {{ $flag.Type }}{{ $flag.Doctail }} +type {{ $flag.Name }}Flag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + {{- if eq $flag.Value true }} + Value {{ $flag.Type }} + {{- end }} + {{- if eq $flag.Destination true }} + Destination *{{ $flag.Type }} + {{- end }} +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f {{ $flag.Name }}Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f {{ $flag.Name }}Flag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f {{ $flag.Name }}Flag) IsRequired() bool { + return f.Required +} + +// {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns +// {{ $flag.ContextDefault }} if not found +func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { + return lookup{{ $flag.Name }}(name, c.flagSet) +} + +// Global{{ $flag.Name }} looks up the value of a global {{ $flag.Name }}Flag, returns +// {{ $flag.ContextDefault }} if not found +func (c *Context) Global{{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookup{{ $flag.Name }}(name, fs) + } + return {{ $flag.ContextDefault }} +} + +func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { + f := set.Lookup(name) + if f != nil { + {{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }} + if err != nil { + return {{ $flag.ContextDefault }} + } + {{ if ne .ParserCast "" }}return {{ $flag.ParserCast }}{{ else }}return parsed{{ end }} + } + return {{ $flag.ContextDefault }} +} +{{- end }}` + func main() { + var packageName, inputPath, outputPath string + app := cli.NewApp() - app.Name = "flaggen" + app.Name = "fg" app.Usage = "Generate flag type code!" + app.Version = "v0.1.0" app.Flags = []cli.Flag{ cli.StringFlag{ - Name: "package, p", - Value: "cli", - Usage: "`Name of the package` for which the flag types will be generated", + Name: "package, p", + Value: "cli", + Usage: "`PACKAGE` for which the flag types will be generated", + Destination: &packageName, + }, + cli.StringFlag{ + Name: "input, i", + Usage: "path to the `INPUT JSON FILE` which defines each type to be generated", + Destination: &inputPath, + }, + cli.StringFlag{ + Name: "output, o", + Usage: "path to the `OUTPUT GO FILE` which will contain the flag types", + Destination: &outputPath, }, } + app.Action = func(c *cli.Context) error { + var info CliFlagInfo + info.PackageName = packageName + + inFile, err := os.Open(inputPath) + if err != nil { + log.Fatal(err) + } + + defer inFile.Close() + + decoder := json.NewDecoder(inFile) + + err = decoder.Decode(&info.Flags) + if err != nil { + log.Fatal(err) + } + + tpl := template.Must(template.New("").Parse(cliFlagTemplate)) + + outFile, err := os.Create(outputPath) + if err != nil { + log.Fatal(err) + } + + defer outFile.Close() + + err = tpl.Execute(outFile, info) + if err != nil { + log.Fatal(err) + } + + return nil + } + err := app.Run(os.Args) if err != nil { log.Fatal(err) } - } From 16c7a60528bc5f7d98030e09630a38f3d8fc9ddc Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sat, 3 Aug 2019 22:14:58 +0530 Subject: [PATCH 04/31] finish generation of flag types for altsrc package rename package to fg (flag generator) --- {flaggen => fg}/main.go | 45 ++++++++++++++++++++++++++++++++---- flaggen/flag_generated.gotpl | 0 2 files changed, 41 insertions(+), 4 deletions(-) rename {flaggen => fg}/main.go (76%) delete mode 100644 flaggen/flag_generated.gotpl diff --git a/flaggen/main.go b/fg/main.go similarity index 76% rename from flaggen/main.go rename to fg/main.go index cbaba90..ce5e389 100644 --- a/flaggen/main.go +++ b/fg/main.go @@ -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 { diff --git a/flaggen/flag_generated.gotpl b/flaggen/flag_generated.gotpl deleted file mode 100644 index e69de29..0000000 From c133a5aeb16e0978e3c29f8446ddf02922b7e150 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sat, 3 Aug 2019 22:15:43 +0530 Subject: [PATCH 05/31] add explicit true/false choices for value and dest keys due to go default false for bool types --- flag-types.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/flag-types.json b/flag-types.json index 1223107..3306025 100644 --- a/flag-types.json +++ b/flag-types.json @@ -3,6 +3,7 @@ "name": "Bool", "type": "bool", "value": false, + "dest": true, "context_default": "false", "parser": "strconv.ParseBool(f.Value.String())" }, @@ -10,6 +11,7 @@ "name": "BoolT", "type": "bool", "value": false, + "dest": true, "doctail": " that is true by default", "context_default": "false", "parser": "strconv.ParseBool(f.Value.String())" @@ -17,6 +19,8 @@ { "name": "Duration", "type": "time.Duration", + "value": true, + "dest": true, "doctail": " (see https://golang.org/pkg/time/#ParseDuration)", "context_default": "0", "parser": "time.ParseDuration(f.Value.String())" @@ -24,12 +28,15 @@ { "name": "Float64", "type": "float64", + "value": true, + "dest": true, "context_default": "0", "parser": "strconv.ParseFloat(f.Value.String(), 64)" }, { "name": "Generic", "type": "Generic", + "value": true, "dest": false, "context_default": "nil", "context_type": "interface{}" @@ -37,12 +44,16 @@ { "name": "Int64", "type": "int64", + "value": true, + "dest": true, "context_default": "0", "parser": "strconv.ParseInt(f.Value.String(), 0, 64)" }, { "name": "Int", "type": "int", + "value": true, + "dest": true, "context_default": "0", "parser": "strconv.ParseInt(f.Value.String(), 0, 64)", "parser_cast": "int(parsed)" @@ -50,6 +61,7 @@ { "name": "IntSlice", "type": "*IntSlice", + "value": true, "dest": false, "context_default": "nil", "context_type": "[]int", @@ -58,6 +70,7 @@ { "name": "Int64Slice", "type": "*Int64Slice", + "value": true, "dest": false, "context_default": "nil", "context_type": "[]int64", @@ -66,12 +79,15 @@ { "name": "String", "type": "string", + "value": true, + "dest": true, "context_default": "\"\"", "parser": "f.Value.String(), error(nil)" }, { "name": "StringSlice", "type": "*StringSlice", + "value": true, "dest": false, "context_default": "nil", "context_type": "[]string", @@ -80,12 +96,16 @@ { "name": "Uint64", "type": "uint64", + "value": true, + "dest": true, "context_default": "0", "parser": "strconv.ParseUint(f.Value.String(), 0, 64)" }, { "name": "Uint", "type": "uint", + "value": true, + "dest": true, "context_default": "0", "parser": "strconv.ParseUint(f.Value.String(), 0, 64)", "parser_cast": "uint(parsed)" From add69c7d4fbef52ac8541c2f7dfa465fdd9be2c3 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sat, 3 Aug 2019 22:16:25 +0530 Subject: [PATCH 06/31] updated flag types generated courtesy fg cli --- altsrc/flag_generated.go | 109 +++++++++++++++++++-------------------- flag_generated.go | 30 +++++------ 2 files changed, 69 insertions(+), 70 deletions(-) diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go index 08170ca..0c45914 100644 --- a/altsrc/flag_generated.go +++ b/altsrc/flag_generated.go @@ -1,13 +1,12 @@ +// Code generated by fg; DO NOT EDIT. + package altsrc import ( "flag" - "github.com/urfave/cli" ) -// WARNING: This file is generated! - // BoolFlag is the flag type that wraps cli.BoolFlag to allow // for other values to be specified type BoolFlag struct { @@ -20,15 +19,15 @@ func NewBoolFlag(fl cli.BoolFlag) *BoolFlag { return &BoolFlag{BoolFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped BoolFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped BoolFlag.Apply func (f *BoolFlag) Apply(set *flag.FlagSet) { f.set = set f.BoolFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped BoolFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped BoolFlag.ApplyWithError func (f *BoolFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.BoolFlag.ApplyWithError(set) @@ -46,15 +45,15 @@ func NewBoolTFlag(fl cli.BoolTFlag) *BoolTFlag { return &BoolTFlag{BoolTFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped BoolTFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped BoolTFlag.Apply func (f *BoolTFlag) Apply(set *flag.FlagSet) { f.set = set f.BoolTFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped BoolTFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped BoolTFlag.ApplyWithError func (f *BoolTFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.BoolTFlag.ApplyWithError(set) @@ -72,15 +71,15 @@ func NewDurationFlag(fl cli.DurationFlag) *DurationFlag { return &DurationFlag{DurationFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped DurationFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped DurationFlag.Apply func (f *DurationFlag) Apply(set *flag.FlagSet) { f.set = set f.DurationFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped DurationFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped DurationFlag.ApplyWithError func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.DurationFlag.ApplyWithError(set) @@ -98,15 +97,15 @@ func NewFloat64Flag(fl cli.Float64Flag) *Float64Flag { return &Float64Flag{Float64Flag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped Float64Flag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Float64Flag.Apply func (f *Float64Flag) Apply(set *flag.FlagSet) { f.set = set f.Float64Flag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped Float64Flag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Float64Flag.ApplyWithError func (f *Float64Flag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.Float64Flag.ApplyWithError(set) @@ -124,15 +123,15 @@ func NewGenericFlag(fl cli.GenericFlag) *GenericFlag { return &GenericFlag{GenericFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped GenericFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped GenericFlag.Apply func (f *GenericFlag) Apply(set *flag.FlagSet) { f.set = set f.GenericFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped GenericFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped GenericFlag.ApplyWithError func (f *GenericFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.GenericFlag.ApplyWithError(set) @@ -150,15 +149,15 @@ func NewInt64Flag(fl cli.Int64Flag) *Int64Flag { return &Int64Flag{Int64Flag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped Int64Flag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Int64Flag.Apply func (f *Int64Flag) Apply(set *flag.FlagSet) { f.set = set f.Int64Flag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped Int64Flag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Int64Flag.ApplyWithError func (f *Int64Flag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.Int64Flag.ApplyWithError(set) @@ -176,15 +175,15 @@ func NewIntFlag(fl cli.IntFlag) *IntFlag { return &IntFlag{IntFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped IntFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped IntFlag.Apply func (f *IntFlag) Apply(set *flag.FlagSet) { f.set = set f.IntFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped IntFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped IntFlag.ApplyWithError func (f *IntFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.IntFlag.ApplyWithError(set) @@ -202,15 +201,15 @@ func NewIntSliceFlag(fl cli.IntSliceFlag) *IntSliceFlag { return &IntSliceFlag{IntSliceFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped IntSliceFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped IntSliceFlag.Apply func (f *IntSliceFlag) Apply(set *flag.FlagSet) { f.set = set f.IntSliceFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped IntSliceFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped IntSliceFlag.ApplyWithError func (f *IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.IntSliceFlag.ApplyWithError(set) @@ -228,15 +227,15 @@ func NewInt64SliceFlag(fl cli.Int64SliceFlag) *Int64SliceFlag { return &Int64SliceFlag{Int64SliceFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped Int64SliceFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Int64SliceFlag.Apply func (f *Int64SliceFlag) Apply(set *flag.FlagSet) { f.set = set f.Int64SliceFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped Int64SliceFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Int64SliceFlag.ApplyWithError func (f *Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.Int64SliceFlag.ApplyWithError(set) @@ -254,15 +253,15 @@ func NewStringFlag(fl cli.StringFlag) *StringFlag { return &StringFlag{StringFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped StringFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped StringFlag.Apply func (f *StringFlag) Apply(set *flag.FlagSet) { f.set = set f.StringFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped StringFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped StringFlag.ApplyWithError func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.StringFlag.ApplyWithError(set) @@ -280,15 +279,15 @@ func NewStringSliceFlag(fl cli.StringSliceFlag) *StringSliceFlag { return &StringSliceFlag{StringSliceFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped StringSliceFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped StringSliceFlag.Apply func (f *StringSliceFlag) Apply(set *flag.FlagSet) { f.set = set f.StringSliceFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped StringSliceFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped StringSliceFlag.ApplyWithError func (f *StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.StringSliceFlag.ApplyWithError(set) @@ -306,15 +305,15 @@ func NewUint64Flag(fl cli.Uint64Flag) *Uint64Flag { return &Uint64Flag{Uint64Flag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped Uint64Flag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Uint64Flag.Apply func (f *Uint64Flag) Apply(set *flag.FlagSet) { f.set = set f.Uint64Flag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped Uint64Flag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Uint64Flag.ApplyWithError func (f *Uint64Flag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.Uint64Flag.ApplyWithError(set) @@ -332,15 +331,15 @@ func NewUintFlag(fl cli.UintFlag) *UintFlag { return &UintFlag{UintFlag: fl, set: nil} } -// Apply saves the flagSet for later usage calls, then calls the -// wrapped UintFlag.Apply +// Apply saves the flagSet for later usage calls, then calls +// the wrapped UintFlag.Apply func (f *UintFlag) Apply(set *flag.FlagSet) { f.set = set f.UintFlag.Apply(set) } -// ApplyWithError saves the flagSet for later usage calls, then calls the -// wrapped UintFlag.ApplyWithError +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped UintFlag.ApplyWithError func (f *UintFlag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.UintFlag.ApplyWithError(set) diff --git a/flag_generated.go b/flag_generated.go index a3e4d6e..f106d23 100644 --- a/flag_generated.go +++ b/flag_generated.go @@ -1,3 +1,5 @@ +// Code generated by fg; DO NOT EDIT. + package cli import ( @@ -6,8 +8,6 @@ import ( "time" ) -// WARNING: This file is generated! - // BoolFlag is a flag with type bool type BoolFlag struct { Name string @@ -30,7 +30,7 @@ func (f BoolFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f BoolFlag) IsRequired() bool { return f.Required } @@ -84,7 +84,7 @@ func (f BoolTFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f BoolTFlag) IsRequired() bool { return f.Required } @@ -139,7 +139,7 @@ func (f DurationFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f DurationFlag) IsRequired() bool { return f.Required } @@ -194,7 +194,7 @@ func (f Float64Flag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f Float64Flag) IsRequired() bool { return f.Required } @@ -248,7 +248,7 @@ func (f GenericFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f GenericFlag) IsRequired() bool { return f.Required } @@ -303,7 +303,7 @@ func (f Int64Flag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f Int64Flag) IsRequired() bool { return f.Required } @@ -358,7 +358,7 @@ func (f IntFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f IntFlag) IsRequired() bool { return f.Required } @@ -412,7 +412,7 @@ func (f IntSliceFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f IntSliceFlag) IsRequired() bool { return f.Required } @@ -466,7 +466,7 @@ func (f Int64SliceFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f Int64SliceFlag) IsRequired() bool { return f.Required } @@ -521,7 +521,7 @@ func (f StringFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f StringFlag) IsRequired() bool { return f.Required } @@ -575,7 +575,7 @@ func (f StringSliceFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f StringSliceFlag) IsRequired() bool { return f.Required } @@ -630,7 +630,7 @@ func (f Uint64Flag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f Uint64Flag) IsRequired() bool { return f.Required } @@ -685,7 +685,7 @@ func (f UintFlag) GetName() string { return f.Name } -// IsRequired returns the whether or not the flag is required +// IsRequired returns whether or not the flag is required func (f UintFlag) IsRequired() bool { return f.Required } From d209be324522a802f8056094f8bb89b4562ca9a3 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sat, 3 Aug 2019 22:32:36 +0530 Subject: [PATCH 07/31] update go generate command test file generation --- altsrc/altsrc.go | 2 +- cli.go | 2 +- generate-flag-types | 262 -------------------------------------------- 3 files changed, 2 insertions(+), 264 deletions(-) delete mode 100755 generate-flag-types diff --git a/altsrc/altsrc.go b/altsrc/altsrc.go index ac34bf6..b81c99a 100644 --- a/altsrc/altsrc.go +++ b/altsrc/altsrc.go @@ -1,3 +1,3 @@ package altsrc -//go:generate python ../generate-flag-types altsrc -i ../flag-types.json -o flag_generated.go +//go:generate fg -p altsrc -i ../flag-types.json -o flag_generated.go diff --git a/cli.go b/cli.go index 90c07eb..e71e142 100644 --- a/cli.go +++ b/cli.go @@ -19,4 +19,4 @@ // } package cli -//go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go +//go:generate fg -p cli -i flag-types.json -o flag_generated.go diff --git a/generate-flag-types b/generate-flag-types deleted file mode 100755 index e0b5aa1..0000000 --- a/generate-flag-types +++ /dev/null @@ -1,262 +0,0 @@ -#!/usr/bin/env python -""" -The flag types that ship with the cli library have many things in common, and -so we can take advantage of the `go generate` command to create much of the -source code from a list of definitions. These definitions attempt to cover -the parts that vary between flag types, and should evolve as needed. - -An example of the minimum definition needed is: - - { - "name": "SomeType", - "type": "sometype", - "context_default": "nil" - } - -In this example, the code generated for the `cli` package will include a type -named `SomeTypeFlag` that is expected to wrap a value of type `sometype`. -Fetching values by name via `*cli.Context` will default to a value of `nil`. - -A more complete, albeit somewhat redundant, example showing all available -definition keys is: - - { - "name": "VeryMuchType", - "type": "*VeryMuchType", - "value": true, - "dest": false, - "doctail": " which really only wraps a []float64, oh well!", - "context_type": "[]float64", - "context_default": "nil", - "parser": "parseVeryMuchType(f.Value.String())", - "parser_cast": "[]float64(parsed)" - } - -The meaning of each field is as follows: - - name (string) - The type "name", which will be suffixed with - `Flag` when generating the type definition - for `cli` and the wrapper type for `altsrc` - type (string) - The type that the generated `Flag` type for `cli` - is expected to "contain" as its `.Value` member - value (bool) - Should the generated `cli` type have a `Value` - member? - dest (bool) - Should the generated `cli` type support a - destination pointer? - doctail (string) - Additional docs for the `cli` flag type comment - context_type (string) - The literal type used in the `*cli.Context` - reader func signature - context_default (string) - The literal value used as the default by the - `*cli.Context` reader funcs when no value is - present - parser (string) - Literal code used to parse the flag `f`, - expected to have a return signature of - (value, error) - parser_cast (string) - Literal code used to cast the `parsed` value - returned from the `parser` code -""" - -from __future__ import print_function, unicode_literals - -import argparse -import json -import os -import subprocess -import sys -import tempfile -import textwrap - - -class _FancyFormatter(argparse.ArgumentDefaultsHelpFormatter, - argparse.RawDescriptionHelpFormatter): - pass - - -def main(sysargs=sys.argv[:]): - parser = argparse.ArgumentParser( - description='Generate flag type code!', - formatter_class=_FancyFormatter) - parser.add_argument( - 'package', - type=str, default='cli', choices=_WRITEFUNCS.keys(), - help='Package for which flag types will be generated' - ) - parser.add_argument( - '-i', '--in-json', - type=argparse.FileType('r'), - default=sys.stdin, - help='Input JSON file which defines each type to be generated' - ) - parser.add_argument( - '-o', '--out-go', - type=argparse.FileType('w'), - default=sys.stdout, - help='Output file/stream to which generated source will be written' - ) - parser.epilog = __doc__ - - args = parser.parse_args(sysargs[1:]) - _generate_flag_types(_WRITEFUNCS[args.package], args.out_go, args.in_json) - return 0 - - -def _generate_flag_types(writefunc, output_go, input_json): - types = json.load(input_json) - - tmp = tempfile.NamedTemporaryFile(suffix='.go', delete=False) - writefunc(tmp, types) - tmp.close() - - new_content = subprocess.check_output( - ['goimports', tmp.name] - ).decode('utf-8') - - print(new_content, file=output_go, end='') - output_go.flush() - os.remove(tmp.name) - - -def _set_typedef_defaults(typedef): - typedef.setdefault('doctail', '') - typedef.setdefault('context_type', typedef['type']) - typedef.setdefault('dest', True) - typedef.setdefault('value', True) - typedef.setdefault('parser', 'f.Value, error(nil)') - typedef.setdefault('parser_cast', 'parsed') - - -def _write_cli_flag_types(outfile, types): - _fwrite(outfile, """\ - package cli - - // WARNING: This file is generated! - - """) - - for typedef in types: - _set_typedef_defaults(typedef) - - _fwrite(outfile, """\ - // {name}Flag is a flag with type {type}{doctail} - type {name}Flag struct {{ - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - """.format(**typedef)) - - if typedef['value']: - _fwrite(outfile, """\ - Value {type} - """.format(**typedef)) - - if typedef['dest']: - _fwrite(outfile, """\ - Destination *{type} - """.format(**typedef)) - - _fwrite(outfile, "\n}\n\n") - - _fwrite(outfile, """\ - // String returns a readable representation of this value - // (for usage defaults) - func (f {name}Flag) String() string {{ - return FlagStringer(f) - }} - - // GetName returns the name of the flag - func (f {name}Flag) GetName() string {{ - return f.Name - }} - - // IsRequired returns the whether or not the flag is required - func (f {name}Flag) IsRequired() bool {{ - return f.Required - }} - - // {name} looks up the value of a local {name}Flag, returns - // {context_default} if not found - func (c *Context) {name}(name string) {context_type} {{ - return lookup{name}(name, c.flagSet) - }} - - // Global{name} looks up the value of a global {name}Flag, returns - // {context_default} if not found - func (c *Context) Global{name}(name string) {context_type} {{ - if fs := lookupGlobalFlagSet(name, c); fs != nil {{ - return lookup{name}(name, fs) - }} - return {context_default} - }} - - func lookup{name}(name string, set *flag.FlagSet) {context_type} {{ - f := set.Lookup(name) - if f != nil {{ - parsed, err := {parser} - if err != nil {{ - return {context_default} - }} - return {parser_cast} - }} - return {context_default} - }} - """.format(**typedef)) - - -def _write_altsrc_flag_types(outfile, types): - _fwrite(outfile, """\ - package altsrc - - import ( - "gopkg.in/urfave/cli.v1" - ) - - // WARNING: This file is generated! - - """) - - for typedef in types: - _set_typedef_defaults(typedef) - - _fwrite(outfile, """\ - // {name}Flag is the flag type that wraps cli.{name}Flag to allow - // for other values to be specified - type {name}Flag struct {{ - cli.{name}Flag - set *flag.FlagSet - }} - - // New{name}Flag creates a new {name}Flag - func New{name}Flag(fl cli.{name}Flag) *{name}Flag {{ - return &{name}Flag{{{name}Flag: fl, set: nil}} - }} - - // Apply saves the flagSet for later usage calls, then calls the - // wrapped {name}Flag.Apply - func (f *{name}Flag) Apply(set *flag.FlagSet) {{ - f.set = set - f.{name}Flag.Apply(set) - }} - - // ApplyWithError saves the flagSet for later usage calls, then calls the - // wrapped {name}Flag.ApplyWithError - func (f *{name}Flag) ApplyWithError(set *flag.FlagSet) error {{ - f.set = set - return f.{name}Flag.ApplyWithError(set) - }} - """.format(**typedef)) - - -def _fwrite(outfile, text): - print(textwrap.dedent(text), end='', file=outfile) - - -_WRITEFUNCS = { - 'cli': _write_cli_flag_types, - 'altsrc': _write_altsrc_flag_types -} - -if __name__ == '__main__': - sys.exit(main()) From d1ded77768d33ce64657686558884e69cbb5bce4 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 08:45:29 +0530 Subject: [PATCH 08/31] rename utility from fg > flag-generator --- {fg => flag-generator}/main.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {fg => flag-generator}/main.go (100%) diff --git a/fg/main.go b/flag-generator/main.go similarity index 100% rename from fg/main.go rename to flag-generator/main.go From 065fe9e9af992d82126929c157edb16b1a1f06ab Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 10:05:44 +0530 Subject: [PATCH 09/31] change structure to embed source json and template files restructure code to have defaults in place of choices --- flag-generator/.gitignore | 1 + flag-generator/fs_vfsdata.go | 214 +++++++++++++++++ flag-generator/go.mod | 9 + flag-generator/go.sum | 9 + flag-generator/main.go | 215 +++++++----------- .../source/flag-types.json | 0 .../templates/altsrc_flags_generated.gotpl | 36 +++ .../templates/cli_flags_generated.gotpl | 69 ++++++ 8 files changed, 426 insertions(+), 127 deletions(-) create mode 100644 flag-generator/.gitignore create mode 100644 flag-generator/fs_vfsdata.go create mode 100644 flag-generator/go.mod create mode 100644 flag-generator/go.sum rename flag-types.json => flag-generator/source/flag-types.json (100%) create mode 100644 flag-generator/templates/altsrc_flags_generated.gotpl create mode 100644 flag-generator/templates/cli_flags_generated.gotpl diff --git a/flag-generator/.gitignore b/flag-generator/.gitignore new file mode 100644 index 0000000..5657f6e --- /dev/null +++ b/flag-generator/.gitignore @@ -0,0 +1 @@ +vendor \ No newline at end of file diff --git a/flag-generator/fs_vfsdata.go b/flag-generator/fs_vfsdata.go new file mode 100644 index 0000000..2122fcf --- /dev/null +++ b/flag-generator/fs_vfsdata.go @@ -0,0 +1,214 @@ +// Code generated by vfsgen; DO NOT EDIT. + +package main + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "io/ioutil" + "net/http" + "os" + pathpkg "path" + "time" +) + +// fs statically implements the virtual filesystem provided to vfsgen. +var fs = func() http.FileSystem { + fs := vfsgen۰FS{ + "/": &vfsgen۰DirInfo{ + name: "/", + modTime: time.Time{}, + }, + "/source": &vfsgen۰DirInfo{ + name: "source", + modTime: time.Time{}, + }, + "/source/flag-types.json": &vfsgen۰CompressedFileInfo{ + name: "flag-types.json", + modTime: time.Time{}, + uncompressedSize: 2559, + + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x94\xc1\x6e\x9c\x30\x10\x86\xef\x3c\xc5\xc8\xbd\x40\xb5\x82\x1c\x56\x7b\xd8\x63\x55\xb5\xda\x5b\xa5\x34\xbd\x24\x51\xe4\x80\x21\x56\x1d\x1b\xd9\x43\xd4\x28\xca\xbb\x57\xf6\x2e\xbb\x60\x0c\x62\x5b\x2d\xb9\xfe\x23\x98\xef\x9b\xb1\xe6\x36\x02\x78\x8b\x00\x00\x88\xa4\xcf\x8c\x6c\x81\x7c\x51\x4a\x90\xd5\x3e\xc3\xd7\xda\x65\x8f\x9d\xec\x85\x8a\xc6\x86\x25\x15\x86\x1d\xb2\x82\x19\x24\x5b\x40\xdd\xb4\x49\xae\x24\xb2\x3f\xf8\x50\xb0\x92\x36\xc2\x16\x89\xfb\xa0\xfd\x4b\x4d\xb5\x61\xda\xc6\x06\x75\xae\xe4\x4b\xfa\xc3\x26\xb6\x79\x5c\xa6\xbf\x6c\x8f\xf4\x1a\x35\x97\x55\x9c\x24\x24\x02\x78\x5f\x85\x51\x7f\xfe\x3f\x6b\xa1\x72\xa4\x5c\xd8\x8f\x01\x9f\x28\x02\x37\xae\x0c\x8f\xaf\xd0\xf2\x2f\xa9\xf5\xb5\xd1\x14\xb9\x92\xbe\x19\xf2\x67\x96\xfa\xc5\x56\xb1\xeb\x33\x69\x18\x1b\xc6\xe0\x09\xb1\x36\xdb\x2c\xab\x94\xa0\xb2\x4a\x95\xae\xb2\xfa\x77\x95\xd9\x0e\xd9\x27\x87\xdc\xf6\x49\x26\xd4\xaf\x86\xda\x8e\xb1\xf7\x83\xf9\xde\xdf\x84\xa2\xb8\x59\xfb\xda\x65\x3f\x9e\x25\x3c\x0f\xb6\xb7\x23\xd7\x7d\x00\xbb\x82\xcd\x7a\x14\xf8\x3b\x93\x4c\xf3\xdc\x07\xf6\xe2\x71\xe0\xee\xb3\x0c\x10\x4b\x2e\xfc\xe1\xb7\x2d\xb8\x44\xa6\x4b\x9a\xb3\xb7\xf7\x31\xb8\x9d\x0c\xcc\x92\xcb\x05\x26\xb9\x93\xa1\x39\x5e\x4d\x8e\x72\x27\x31\xc0\xfa\xa1\xa4\xbd\x4f\x1f\x72\xea\xfa\x59\xaa\xd8\x45\xc5\x94\xcb\xb5\xe0\x39\xf3\x85\x3e\xfb\x85\x4b\xbc\x8c\xdb\xfb\xce\xdc\x4e\xda\x47\xcd\xf8\x48\x91\x24\xfb\xc8\x2a\x33\xad\x95\x8e\x25\x17\x53\x52\x9b\xf5\xa8\x96\x57\xba\x98\xd8\xe9\xf1\x8e\xa9\x1d\x48\xce\x93\xdb\xef\xde\x17\x33\xbd\xf4\x5f\xdf\xe0\x1d\xb9\x23\x43\xe8\xe1\xab\x9b\x4b\x19\xde\x41\xa0\x76\x99\x25\xf4\x87\x12\xdc\x42\x87\xe5\xbc\x35\xdc\xf0\xd0\xcd\x6a\x16\x39\x5a\xb6\xf7\xd9\x57\xeb\x86\x0f\xcf\x56\xb3\xc0\xdd\x9a\x86\x0d\x1f\xae\xc6\xbf\x5c\xd1\x7d\xf4\x37\x00\x00\xff\xff\x66\x52\x85\x44\xff\x09\x00\x00"), + }, + "/templates": &vfsgen۰DirInfo{ + name: "templates", + modTime: time.Time{}, + }, + "/templates/altsrc_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ + name: "altsrc_flags_generated.gotpl", + modTime: time.Time{}, + uncompressedSize: 1064, + + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x41\x6b\xdc\x30\x10\x85\xcf\xd1\xaf\x78\x2c\xa1\xac\xc3\xd6\xbe\x6f\xc9\xa1\x34\x29\xf4\xb2\x29\x24\xd0\xb3\xd6\x1e\xd9\xa2\x5a\xdb\x48\xe3\x5d\x16\xe1\xff\x5e\x46\x0e\xe9\x96\x6a\x4b\x2f\xb9\xc9\x1a\xbd\xf7\xe6\x9b\x71\x55\xe1\xcb\xd0\x10\x5a\xea\xc9\x6b\xa6\x06\xfb\x33\x4c\xfb\x09\x0f\x4f\xd8\x3d\xbd\xe0\xf1\xe1\xdb\x4b\xa9\xd4\xa8\xeb\x9f\xba\x25\xc4\x88\xf2\xfb\x72\xde\xe9\x03\x61\x9e\x95\xb2\x87\x71\xf0\x8c\xb5\xba\x59\x19\xa7\xdb\x95\x02\x80\x55\x6b\xb9\x9b\xf6\x65\x3d\x1c\xaa\xc9\x1b\x7d\xa4\xaa\x76\x76\xa5\x0a\xa5\x62\x84\xd7\x7d\x4b\xb8\xb5\x1b\xdc\x8a\x04\xdb\x7b\x94\x5f\x9d\x6e\x83\x18\x56\x95\xc4\xa4\x42\xf9\x1a\x22\x35\xd8\x00\xee\x08\x49\xc0\xe7\x91\xc0\x9d\x66\x9c\xbc\x1e\x03\x6a\x67\xcb\xac\x88\x07\x68\xe7\x86\x93\xb8\x9a\xc1\x63\xe0\x8e\x3c\x8e\xda\x4d\x14\xa4\xb8\x27\x84\x91\x6a\x6b\x2c\x35\x2a\xb9\x66\x6d\x02\xfb\xa9\x66\xc4\xc4\x76\x2d\x2c\x15\x03\x31\xee\x52\x45\xae\x9e\x89\xd5\xac\x24\x7c\x47\xa7\xac\x73\xed\x49\x33\x05\x68\xf4\x74\xca\x86\x2b\x33\xf5\xf5\x35\xfd\xda\xb8\xab\xfd\x14\xb8\xcb\x46\x2e\x14\x9e\x78\xf2\x3d\x3e\xe4\x9e\xc4\x6c\x23\x5b\x18\xb7\x11\xc0\x2d\x7a\xeb\x30\xbf\x92\x7d\x1e\x47\x77\x46\xd0\x47\xfa\xbd\xa0\x67\xe2\x34\x6e\xa7\x99\x3c\xa6\x20\xff\x4e\xad\x9d\x0b\x1b\x79\xd2\x2f\x67\x11\x8b\x40\x56\x38\x52\x93\xcd\x2c\x93\xfb\x32\x82\xb5\xc9\x03\x15\x4b\x0b\xeb\xbf\x46\x5f\x20\xaa\x1b\x53\xca\xfd\xbd\xf4\x2d\x1f\xd7\x43\x44\x5f\x5c\x32\xfd\xb0\xdc\x3d\x7a\x3f\xf8\xf7\x85\x7b\x8b\xf9\x2f\xca\xb7\xd7\x39\x5c\x4a\xdd\x2e\xfb\xbd\xe4\xbe\xd8\xf7\xbf\x26\xf0\x87\xb7\x8c\x22\xc6\x8f\xa0\xbe\xc1\x3c\xff\x0a\x00\x00\xff\xff\x3c\x32\xe5\x42\x28\x04\x00\x00"), + }, + "/templates/cli_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ + name: "cli_flags_generated.gotpl", + modTime: time.Time{}, + uncompressedSize: 2234, + + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\x41\x4f\xeb\x38\x10\x3e\x37\xbf\x62\xb6\xe2\x90\xa0\x6e\x7b\x5f\xc4\x89\xc2\x2e\xd2\x0a\xd0\x83\xc7\xdd\x4d\xc6\xa9\x85\xb1\x8b\xed\xc0\x43\x55\xfe\xfb\xd3\x8c\x9d\xb4\x4d\x0b\xf4\xf2\xe8\xc9\x9e\xf9\xf2\xcd\x37\xdf\x8c\xea\xd9\x0c\x2e\x6c\x85\x50\xa3\x41\x27\x02\x56\xb0\x78\x07\x59\x9f\xc1\xfc\x16\x6e\x6e\x1f\xe0\x72\x7e\xfd\x30\xcd\xb2\x95\x28\x9f\x44\x8d\xb0\x5e\xc3\xf4\x2e\x9e\x6f\xc4\x33\x42\xdb\x66\x99\x7a\x5e\x59\x17\x20\xcf\x46\x63\xa9\x45\x3d\xce\x46\x63\x1f\x5c\x69\xcd\x2b\x1d\x83\x7a\xc6\x71\x56\x64\xeb\x35\x38\x61\x6a\x84\x13\x35\x81\x13\x02\xc2\x3f\xe7\x30\xbd\xd2\xa2\xf6\x44\x33\x9b\x11\x39\x27\xa6\x89\x9a\x72\xa0\x3c\x08\x60\xf8\x9b\x0a\x4b\x08\xef\x2b\xdc\x00\x1f\xe8\xd6\xb6\xfd\x7d\x6e\xcb\x20\x94\x26\xbe\x5d\xe0\x36\xa3\x0f\xae\x29\x03\xac\x33\x00\x00\x4e\xa4\x9f\x0f\x4e\x99\x9a\xc3\x3f\x3d\x75\xbb\x17\xbe\x34\xaf\x8f\xc2\xed\x85\xaf\x94\xc6\x3b\x11\x96\x83\xf0\x0f\x7c\x69\x94\xc3\x8a\xce\x0b\x6b\x35\x07\xff\x53\x55\x85\x26\x52\xf4\xc1\xf5\xfa\x6f\x50\x12\xf0\x25\xc9\x7d\x14\xba\x41\x08\xae\x61\x87\x47\x7c\x1d\x8d\x86\x6d\x67\x23\xfa\x0e\x4d\xd5\x9f\xb7\x39\xe6\xe8\x83\x32\x22\x28\x6b\x36\x4c\x5b\xc1\xd1\xe9\xa7\x7c\x6d\x46\x23\xb9\xe7\x6e\xc0\x61\x68\x9c\xa1\x49\x38\x14\x95\x58\x68\x04\x87\x2b\x87\x1e\x4d\x88\x15\xac\x84\xb0\x54\x1e\x5e\x49\x2a\x7d\x99\x4b\xeb\xa0\x61\x1b\x2b\x94\xa2\xd1\xc1\x17\x99\x6c\x4c\x09\xb9\x3c\x38\x97\x22\x15\xcb\x8b\xe4\x61\x9a\x50\xac\x0d\x04\x89\x00\x74\xb9\x2c\x92\xbe\x7f\x31\x30\x45\x27\x30\x2c\x11\x0c\x05\x58\x0f\xf2\xe2\x7c\x51\x35\x51\x7c\x50\x56\x32\x38\x55\xbb\xf6\xfd\x48\xbb\x82\x6f\x4b\x0c\x4b\x74\x60\x1d\x18\x1b\xfa\x9a\xb4\xb6\x2e\x61\xbf\xa8\xbf\x21\xcd\x0b\xde\x88\xa1\x80\x2e\x9d\x44\x0c\x59\x40\x5b\xfb\xe4\xa1\x59\x71\x71\xf6\x9f\xba\x17\xa0\x6d\x29\xf4\xc1\xa2\x93\x4e\xfe\x0e\xdf\x85\x35\x01\x7f\x85\x79\x9c\x16\x31\x2b\xc9\x4d\x49\xdb\x98\xae\x8b\x12\x4e\x13\xae\xd8\xa3\xce\xd9\xf9\xe8\x22\x67\xe9\x7b\x84\x8e\x98\xb7\x6c\x3c\x26\xe2\x61\xcd\xb4\x80\x14\x47\xed\x71\x07\xb2\xc9\x75\xbb\xb9\x6b\x10\xb5\xdf\xac\x0e\x6a\x99\x40\x39\xa5\xe0\x3d\x86\x7e\x61\xb4\x5d\x08\x7d\xb4\x87\x35\xc3\xff\xa4\x89\x87\x05\x7d\xb3\x95\x4a\x82\xf4\xf4\x7f\x1c\xcd\x8c\x9a\xae\xa2\x73\x9d\x93\xc5\x19\x61\xfe\x3a\x07\xa3\xba\x15\x3d\x76\x0a\xd2\x17\x8c\x6f\xb7\xe7\xf6\xb1\x65\x34\x2a\x36\xea\x13\xd2\xe4\xcd\x04\x3c\x06\x38\xe5\x74\xd2\xfb\x0d\x76\x49\xb2\xca\x63\x98\xfe\xcf\x02\x59\x50\xd1\x1b\xb9\xef\xd1\x46\xd0\x9d\x70\x1e\x5d\xd4\xb2\xa2\x73\x35\x01\x74\x8e\xf8\xfa\xb2\x09\xc3\xcf\x5a\xd2\x34\x80\xca\xf8\x40\xf0\xdd\xba\xdc\x28\x5d\x10\x36\xfe\x71\x77\x45\xe9\x2d\x70\x6e\x5f\xcc\x71\x23\xe8\x90\xed\x87\x4d\x5c\x08\x1f\x62\x23\x43\xb6\xad\xfc\x76\x13\x09\x16\x7b\xd9\xd5\x7b\xfc\x62\x6c\x66\xf1\x3b\x00\x00\xff\xff\x59\x27\xb0\x6d\xba\x08\x00\x00"), + }, + } + fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ + fs["/source"].(os.FileInfo), + fs["/templates"].(os.FileInfo), + } + fs["/source"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ + fs["/source/flag-types.json"].(os.FileInfo), + } + fs["/templates"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ + fs["/templates/altsrc_flags_generated.gotpl"].(os.FileInfo), + fs["/templates/cli_flags_generated.gotpl"].(os.FileInfo), + } + + return fs +}() + +type vfsgen۰FS map[string]interface{} + +func (fs vfsgen۰FS) Open(path string) (http.File, error) { + path = pathpkg.Clean("/" + path) + f, ok := fs[path] + if !ok { + return nil, &os.PathError{Op: "open", Path: path, Err: os.ErrNotExist} + } + + switch f := f.(type) { + case *vfsgen۰CompressedFileInfo: + gr, err := gzip.NewReader(bytes.NewReader(f.compressedContent)) + if err != nil { + // This should never happen because we generate the gzip bytes such that they are always valid. + panic("unexpected error reading own gzip compressed bytes: " + err.Error()) + } + return &vfsgen۰CompressedFile{ + vfsgen۰CompressedFileInfo: f, + gr: gr, + }, nil + case *vfsgen۰DirInfo: + return &vfsgen۰Dir{ + vfsgen۰DirInfo: f, + }, nil + default: + // This should never happen because we generate only the above types. + panic(fmt.Sprintf("unexpected type %T", f)) + } +} + +// vfsgen۰CompressedFileInfo is a static definition of a gzip compressed file. +type vfsgen۰CompressedFileInfo struct { + name string + modTime time.Time + compressedContent []byte + uncompressedSize int64 +} + +func (f *vfsgen۰CompressedFileInfo) Readdir(count int) ([]os.FileInfo, error) { + return nil, fmt.Errorf("cannot Readdir from file %s", f.name) +} +func (f *vfsgen۰CompressedFileInfo) Stat() (os.FileInfo, error) { return f, nil } + +func (f *vfsgen۰CompressedFileInfo) GzipBytes() []byte { + return f.compressedContent +} + +func (f *vfsgen۰CompressedFileInfo) Name() string { return f.name } +func (f *vfsgen۰CompressedFileInfo) Size() int64 { return f.uncompressedSize } +func (f *vfsgen۰CompressedFileInfo) Mode() os.FileMode { return 0444 } +func (f *vfsgen۰CompressedFileInfo) ModTime() time.Time { return f.modTime } +func (f *vfsgen۰CompressedFileInfo) IsDir() bool { return false } +func (f *vfsgen۰CompressedFileInfo) Sys() interface{} { return nil } + +// vfsgen۰CompressedFile is an opened compressedFile instance. +type vfsgen۰CompressedFile struct { + *vfsgen۰CompressedFileInfo + gr *gzip.Reader + grPos int64 // Actual gr uncompressed position. + seekPos int64 // Seek uncompressed position. +} + +func (f *vfsgen۰CompressedFile) Read(p []byte) (n int, err error) { + if f.grPos > f.seekPos { + // Rewind to beginning. + err = f.gr.Reset(bytes.NewReader(f.compressedContent)) + if err != nil { + return 0, err + } + f.grPos = 0 + } + if f.grPos < f.seekPos { + // Fast-forward. + _, err = io.CopyN(ioutil.Discard, f.gr, f.seekPos-f.grPos) + if err != nil { + return 0, err + } + f.grPos = f.seekPos + } + n, err = f.gr.Read(p) + f.grPos += int64(n) + f.seekPos = f.grPos + return n, err +} +func (f *vfsgen۰CompressedFile) Seek(offset int64, whence int) (int64, error) { + switch whence { + case io.SeekStart: + f.seekPos = 0 + offset + case io.SeekCurrent: + f.seekPos += offset + case io.SeekEnd: + f.seekPos = f.uncompressedSize + offset + default: + panic(fmt.Errorf("invalid whence value: %v", whence)) + } + return f.seekPos, nil +} +func (f *vfsgen۰CompressedFile) Close() error { + return f.gr.Close() +} + +// vfsgen۰DirInfo is a static definition of a directory. +type vfsgen۰DirInfo struct { + name string + modTime time.Time + entries []os.FileInfo +} + +func (d *vfsgen۰DirInfo) Read([]byte) (int, error) { + return 0, fmt.Errorf("cannot Read from directory %s", d.name) +} +func (d *vfsgen۰DirInfo) Close() error { return nil } +func (d *vfsgen۰DirInfo) Stat() (os.FileInfo, error) { return d, nil } + +func (d *vfsgen۰DirInfo) Name() string { return d.name } +func (d *vfsgen۰DirInfo) Size() int64 { return 0 } +func (d *vfsgen۰DirInfo) Mode() os.FileMode { return 0755 | os.ModeDir } +func (d *vfsgen۰DirInfo) ModTime() time.Time { return d.modTime } +func (d *vfsgen۰DirInfo) IsDir() bool { return true } +func (d *vfsgen۰DirInfo) Sys() interface{} { return nil } + +// vfsgen۰Dir is an opened dir instance. +type vfsgen۰Dir struct { + *vfsgen۰DirInfo + pos int // Position within entries for Seek and Readdir. +} + +func (d *vfsgen۰Dir) Seek(offset int64, whence int) (int64, error) { + if offset == 0 && whence == io.SeekStart { + d.pos = 0 + return 0, nil + } + return 0, fmt.Errorf("unsupported Seek in directory %s", d.name) +} + +func (d *vfsgen۰Dir) Readdir(count int) ([]os.FileInfo, error) { + if d.pos >= len(d.entries) && count > 0 { + return nil, io.EOF + } + if count <= 0 || count > len(d.entries)-d.pos { + count = len(d.entries) - d.pos + } + e := d.entries[d.pos : d.pos+count] + d.pos += count + return e, nil +} diff --git a/flag-generator/go.mod b/flag-generator/go.mod new file mode 100644 index 0000000..c93d180 --- /dev/null +++ b/flag-generator/go.mod @@ -0,0 +1,9 @@ +module github.com/urfave/cli/flag-generator + +go 1.12 + +require ( + github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 + github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd + github.com/urfave/cli v1.21.0 +) diff --git a/flag-generator/go.sum b/flag-generator/go.sum new file mode 100644 index 0000000..e68bf88 --- /dev/null +++ b/flag-generator/go.sum @@ -0,0 +1,9 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= +github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0= +github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= +github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE= +github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/flag-generator/main.go b/flag-generator/main.go index ce5e389..1f6d5b6 100644 --- a/flag-generator/main.go +++ b/flag-generator/main.go @@ -2,10 +2,16 @@ package main import ( "encoding/json" + "fmt" + "github.com/shurcooL/httpfs/union" + "github.com/shurcooL/vfsgen" "github.com/urfave/cli" + "io/ioutil" "log" + "net/http" "os" "text/template" + "time" ) type CliFlagInfo struct { @@ -25,178 +31,133 @@ type FlagType struct { ParserCast string `json:"parser_cast"` } -var flagTemplate = `// Code generated by fg; DO NOT EDIT. - -package {{ .PackageName }} -{{ if eq .PackageName "cli" }} -import ( - "flag" - "strconv" - "time" -) -{{ range $i, $flag := .Flags }} -// {{ $flag.Name }}Flag is a flag with type {{ $flag.Type }}{{ $flag.Doctail }} -type {{ $flag.Name }}Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - {{- if eq $flag.Value true }} - Value {{ $flag.Type }} - {{- end }} - {{- if eq $flag.Destination true }} - Destination *{{ $flag.Type }} - {{- end }} +// zeroModTimeFileSystem is an http.FileSystem wrapper. +// It exposes a filesystem exactly like Source, except +// all file modification times are changed to zero. +// See https://github.com/shurcooL/vfsgen/pull/40#issuecomment-355416103 +type zeroModTimeFileSystem struct { + Source http.FileSystem } -// String returns a readable representation of this value -// (for usage defaults) -func (f {{ $flag.Name }}Flag) String() string { - return FlagStringer(f) +func (fs zeroModTimeFileSystem) Open(name string) (http.File, error) { + f, err := fs.Source.Open(name) + return file{f}, err } -// GetName returns the name of the flag -func (f {{ $flag.Name }}Flag) GetName() string { - return f.Name +type file struct { + http.File } -// IsRequired returns whether or not the flag is required -func (f {{ $flag.Name }}Flag) IsRequired() bool { - return f.Required +func (f file) Stat() (os.FileInfo, error) { + fi, err := f.File.Stat() + return fileInfo{fi}, err } -// {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns -// {{ $flag.ContextDefault }} if not found -func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { - return lookup{{ $flag.Name }}(name, c.flagSet) +type fileInfo struct { + os.FileInfo } -// Global{{ $flag.Name }} looks up the value of a global {{ $flag.Name }}Flag, returns -// {{ $flag.ContextDefault }} if not found -func (c *Context) Global{{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookup{{ $flag.Name }}(name, fs) - } - return {{ $flag.ContextDefault }} -} +func (fi fileInfo) ModTime() time.Time { return time.Time{} } -func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { - f := set.Lookup(name) - if f != nil { - {{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }} - if err != nil { - return {{ $flag.ContextDefault }} - } - {{ if ne .ParserCast "" }}return {{ $flag.ParserCast }}{{ else }}return parsed{{ end }} - } - return {{ $flag.ContextDefault }} -} -{{- end }} -{{ else }} -import ( - "flag" - "github.com/urfave/cli" -) +func main() { + app := cli.NewApp() -{{ 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 -} + app.Name = "fg" + app.Usage = "Generate flag type code!" + app.Version = "v0.1.0" -// 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 } -} + app.Action = ActionFunc -// 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) -} + err := GenerateAssets() + if err != nil { + log.Fatal(err) + } -// 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) + err = app.Run(os.Args) + if err != nil { + log.Fatal(err) + } } -{{- end }} -{{- end }} -` -func main() { - var packageName, inputPath, outputPath string +func GenerateAssets() error { + fs := zeroModTimeFileSystem{ + Source: union.New(map[string]http.FileSystem{ + "/templates": http.Dir("templates"), + "/source": http.Dir("source"), + }), + } - app := cli.NewApp() + return vfsgen.Generate(fs, vfsgen.Options{ + PackageName: "main", + VariableName: "fs", + }) +} - app.Name = "fg" - app.Usage = "Generate flag type code!" - app.Version = "v0.1.0" +func ActionFunc(_ *cli.Context) error { + var info CliFlagInfo + var tpl *template.Template - app.Flags = []cli.Flag{ - cli.StringFlag{ - Name: "package, p", - Value: "cli", - Usage: "`PACKAGE` for which the flag types will be generated", - Destination: &packageName, - }, - cli.StringFlag{ - Name: "input, i", - Usage: "path to the `INPUT JSON FILE` which defines each type to be generated", - Destination: &inputPath, - }, - cli.StringFlag{ - Name: "output, o", - Usage: "path to the `OUTPUT GO FILE` which will contain the flag types", - Destination: &outputPath, - }, + inFile, err := fs.Open("/source/flag-types.json") + if err != nil { + log.Fatal(err) } - app.Action = func(c *cli.Context) error { - var info CliFlagInfo - var tpl *template.Template + decoder := json.NewDecoder(inFile) + err = decoder.Decode(&info.Flags) + if err != nil { + log.Fatal(err) + } + err = inFile.Close() + if err != nil { + log.Fatal(err) + } + + for _, packageName := range []string{"cli", "altsrc"} { info.PackageName = packageName - inFile, err := os.Open(inputPath) + bytes, err := ReadTemplate(packageName) if err != nil { log.Fatal(err) } - defer inFile.Close() + tpl = template.Must(template.New("").Parse(string(bytes))) - decoder := json.NewDecoder(inFile) + var outFile *os.File - err = decoder.Decode(&info.Flags) + if packageName == "cli" { + outFile, err = os.Create("flag_generated.go") + } else { + outFile, err = os.Create("altsrc/flag_generated.go") + } if err != nil { log.Fatal(err) } - tpl = template.Must(template.New("").Parse(flagTemplate)) - - outFile, err := os.Create(outputPath) + err = tpl.Execute(outFile, info) if err != nil { log.Fatal(err) } - defer outFile.Close() - - err = tpl.Execute(outFile, info) + err = outFile.Close() if err != nil { log.Fatal(err) } + } + + return nil +} - return nil +func ReadTemplate(packageName string) ([]byte, error) { + templateFile, err := fs.Open(fmt.Sprintf("/templates/%s_flags_generated.gotpl", packageName)) + if err != nil { + return nil, err } - err := app.Run(os.Args) + templateFileBytes, err := ioutil.ReadAll(templateFile) if err != nil { - log.Fatal(err) + return nil, err } + + return templateFileBytes, nil } diff --git a/flag-types.json b/flag-generator/source/flag-types.json similarity index 100% rename from flag-types.json rename to flag-generator/source/flag-types.json diff --git a/flag-generator/templates/altsrc_flags_generated.gotpl b/flag-generator/templates/altsrc_flags_generated.gotpl new file mode 100644 index 0000000..54feb84 --- /dev/null +++ b/flag-generator/templates/altsrc_flags_generated.gotpl @@ -0,0 +1,36 @@ +// Code generated by fg; DO NOT EDIT. + +package {{ .PackageName }} + +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 }} \ No newline at end of file diff --git a/flag-generator/templates/cli_flags_generated.gotpl b/flag-generator/templates/cli_flags_generated.gotpl new file mode 100644 index 0000000..4f148c6 --- /dev/null +++ b/flag-generator/templates/cli_flags_generated.gotpl @@ -0,0 +1,69 @@ +// Code generated by fg; DO NOT EDIT. + +package {{ .PackageName }} + +import ( + "flag" + "strconv" + "time" +) +{{ range $i, $flag := .Flags }} +// {{ $flag.Name }}Flag is a flag with type {{ $flag.Type }}{{ $flag.Doctail }} +type {{ $flag.Name }}Flag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + {{- if eq $flag.Value true }} + Value {{ $flag.Type }} + {{- end }} + {{- if eq $flag.Destination true }} + Destination *{{ $flag.Type }} + {{- end }} +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f {{ $flag.Name }}Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f {{ $flag.Name }}Flag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f {{ $flag.Name }}Flag) IsRequired() bool { + return f.Required +} + +// {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns +// {{ $flag.ContextDefault }} if not found +func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { + return lookup{{ $flag.Name }}(name, c.flagSet) +} + +// Global{{ $flag.Name }} looks up the value of a global {{ $flag.Name }}Flag, returns +// {{ $flag.ContextDefault }} if not found +func (c *Context) Global{{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookup{{ $flag.Name }}(name, fs) + } + return {{ $flag.ContextDefault }} +} + +func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { + f := set.Lookup(name) + if f != nil { + {{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }} + if err != nil { + return {{ $flag.ContextDefault }} + } + {{ if ne .ParserCast "" }}return {{ $flag.ParserCast }}{{ else }}return parsed{{ end }} + } + return {{ $flag.ContextDefault }} +} +{{- end }} \ No newline at end of file From 2a084945a47235959c023291f87127ead86fc168 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 10:28:08 +0530 Subject: [PATCH 10/31] move around code change package to flag-gen to avoid conflict with flag-generator binary test code generation --- {flag-generator => flag-gen}/.gitignore | 0 flag-gen/assets_generate.go | 53 +++++++++++++++++ .../assets_vfsdata.go | 4 +- {flag-generator => flag-gen}/go.mod | 0 {flag-generator => flag-gen}/go.sum | 0 {flag-generator => flag-gen}/main.go | 59 ++----------------- .../source/flag-types.json | 0 .../templates/altsrc_flags_generated.gotpl | 0 .../templates/cli_flags_generated.gotpl | 0 9 files changed, 60 insertions(+), 56 deletions(-) rename {flag-generator => flag-gen}/.gitignore (100%) create mode 100644 flag-gen/assets_generate.go rename flag-generator/fs_vfsdata.go => flag-gen/assets_vfsdata.go (99%) rename {flag-generator => flag-gen}/go.mod (100%) rename {flag-generator => flag-gen}/go.sum (100%) rename {flag-generator => flag-gen}/main.go (59%) rename {flag-generator => flag-gen}/source/flag-types.json (100%) rename {flag-generator => flag-gen}/templates/altsrc_flags_generated.gotpl (100%) rename {flag-generator => flag-gen}/templates/cli_flags_generated.gotpl (100%) diff --git a/flag-generator/.gitignore b/flag-gen/.gitignore similarity index 100% rename from flag-generator/.gitignore rename to flag-gen/.gitignore diff --git a/flag-gen/assets_generate.go b/flag-gen/assets_generate.go new file mode 100644 index 0000000..b587253 --- /dev/null +++ b/flag-gen/assets_generate.go @@ -0,0 +1,53 @@ +// +build ignore + +package main + +import ( + "github.com/shurcooL/httpfs/union" + "github.com/shurcooL/vfsgen" + "log" + "net/http" + "os" + "time" +) + +// zeroModTimeFileSystem is an http.FileSystem wrapper. +// It exposes a filesystem exactly like Source, except +// all file modification times are changed to zero. +// See https://github.com/shurcooL/vfsgen/pull/40#issuecomment-355416103 +type zeroModTimeFileSystem struct { + Source http.FileSystem +} + +func (fs zeroModTimeFileSystem) Open(name string) (http.File, error) { + f, err := fs.Source.Open(name) + return file{f}, err +} + +type file struct { + http.File +} + +func (f file) Stat() (os.FileInfo, error) { + fi, err := f.File.Stat() + return fileInfo{fi}, err +} + +type fileInfo struct { + os.FileInfo +} + +func (fi fileInfo) ModTime() time.Time { return time.Time{} } + +func main() { + err := vfsgen.Generate(zeroModTimeFileSystem{ + Source: union.New(map[string]http.FileSystem{ + "/templates": http.Dir("templates"), + "/source": http.Dir("source"), + }), + }, vfsgen.Options{}) + + if err != nil { + log.Fatal(err) + } +} diff --git a/flag-generator/fs_vfsdata.go b/flag-gen/assets_vfsdata.go similarity index 99% rename from flag-generator/fs_vfsdata.go rename to flag-gen/assets_vfsdata.go index 2122fcf..d039e9f 100644 --- a/flag-generator/fs_vfsdata.go +++ b/flag-gen/assets_vfsdata.go @@ -14,8 +14,8 @@ import ( "time" ) -// fs statically implements the virtual filesystem provided to vfsgen. -var fs = func() http.FileSystem { +// assets statically implements the virtual filesystem provided to vfsgen. +var assets = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", diff --git a/flag-generator/go.mod b/flag-gen/go.mod similarity index 100% rename from flag-generator/go.mod rename to flag-gen/go.mod diff --git a/flag-generator/go.sum b/flag-gen/go.sum similarity index 100% rename from flag-generator/go.sum rename to flag-gen/go.sum diff --git a/flag-generator/main.go b/flag-gen/main.go similarity index 59% rename from flag-generator/main.go rename to flag-gen/main.go index 1f6d5b6..3e463ff 100644 --- a/flag-generator/main.go +++ b/flag-gen/main.go @@ -1,17 +1,15 @@ +//go:generate go run assets_generate.go + package main import ( "encoding/json" "fmt" - "github.com/shurcooL/httpfs/union" - "github.com/shurcooL/vfsgen" "github.com/urfave/cli" "io/ioutil" "log" - "net/http" "os" "text/template" - "time" ) type CliFlagInfo struct { @@ -31,34 +29,6 @@ type FlagType struct { ParserCast string `json:"parser_cast"` } -// zeroModTimeFileSystem is an http.FileSystem wrapper. -// It exposes a filesystem exactly like Source, except -// all file modification times are changed to zero. -// See https://github.com/shurcooL/vfsgen/pull/40#issuecomment-355416103 -type zeroModTimeFileSystem struct { - Source http.FileSystem -} - -func (fs zeroModTimeFileSystem) Open(name string) (http.File, error) { - f, err := fs.Source.Open(name) - return file{f}, err -} - -type file struct { - http.File -} - -func (f file) Stat() (os.FileInfo, error) { - fi, err := f.File.Stat() - return fileInfo{fi}, err -} - -type fileInfo struct { - os.FileInfo -} - -func (fi fileInfo) ModTime() time.Time { return time.Time{} } - func main() { app := cli.NewApp() @@ -68,36 +38,17 @@ func main() { app.Action = ActionFunc - err := GenerateAssets() - if err != nil { - log.Fatal(err) - } - - err = app.Run(os.Args) + err := app.Run(os.Args) if err != nil { log.Fatal(err) } } -func GenerateAssets() error { - fs := zeroModTimeFileSystem{ - Source: union.New(map[string]http.FileSystem{ - "/templates": http.Dir("templates"), - "/source": http.Dir("source"), - }), - } - - return vfsgen.Generate(fs, vfsgen.Options{ - PackageName: "main", - VariableName: "fs", - }) -} - func ActionFunc(_ *cli.Context) error { var info CliFlagInfo var tpl *template.Template - inFile, err := fs.Open("/source/flag-types.json") + inFile, err := assets.Open("/source/flag-types.json") if err != nil { log.Fatal(err) } @@ -149,7 +100,7 @@ func ActionFunc(_ *cli.Context) error { } func ReadTemplate(packageName string) ([]byte, error) { - templateFile, err := fs.Open(fmt.Sprintf("/templates/%s_flags_generated.gotpl", packageName)) + templateFile, err := assets.Open(fmt.Sprintf("/templates/%s_flags_generated.gotpl", packageName)) if err != nil { return nil, err } diff --git a/flag-generator/source/flag-types.json b/flag-gen/source/flag-types.json similarity index 100% rename from flag-generator/source/flag-types.json rename to flag-gen/source/flag-types.json diff --git a/flag-generator/templates/altsrc_flags_generated.gotpl b/flag-gen/templates/altsrc_flags_generated.gotpl similarity index 100% rename from flag-generator/templates/altsrc_flags_generated.gotpl rename to flag-gen/templates/altsrc_flags_generated.gotpl diff --git a/flag-generator/templates/cli_flags_generated.gotpl b/flag-gen/templates/cli_flags_generated.gotpl similarity index 100% rename from flag-generator/templates/cli_flags_generated.gotpl rename to flag-gen/templates/cli_flags_generated.gotpl From c676ed4caa76219414ad737584ec46b03e94cbf8 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 11:04:23 +0530 Subject: [PATCH 11/31] indentation fixes in template regeneration test --- altsrc/flag_generated.go | 1 - flag-gen/assets_vfsdata.go | 8 ++++---- flag-gen/templates/altsrc_flags_generated.gotpl | 3 +-- flag-gen/templates/cli_flags_generated.gotpl | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go index bf2c488..0c45914 100644 --- a/altsrc/flag_generated.go +++ b/altsrc/flag_generated.go @@ -4,7 +4,6 @@ package altsrc import ( "flag" - "github.com/urfave/cli" ) diff --git a/flag-gen/assets_vfsdata.go b/flag-gen/assets_vfsdata.go index d039e9f..4b89ce3 100644 --- a/flag-gen/assets_vfsdata.go +++ b/flag-gen/assets_vfsdata.go @@ -39,16 +39,16 @@ var assets = func() http.FileSystem { "/templates/altsrc_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "altsrc_flags_generated.gotpl", modTime: time.Time{}, - uncompressedSize: 1064, + uncompressedSize: 1063, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x41\x6b\xdc\x30\x10\x85\xcf\xd1\xaf\x78\x2c\xa1\xac\xc3\xd6\xbe\x6f\xc9\xa1\x34\x29\xf4\xb2\x29\x24\xd0\xb3\xd6\x1e\xd9\xa2\x5a\xdb\x48\xe3\x5d\x16\xe1\xff\x5e\x46\x0e\xe9\x96\x6a\x4b\x2f\xb9\xc9\x1a\xbd\xf7\xe6\x9b\x71\x55\xe1\xcb\xd0\x10\x5a\xea\xc9\x6b\xa6\x06\xfb\x33\x4c\xfb\x09\x0f\x4f\xd8\x3d\xbd\xe0\xf1\xe1\xdb\x4b\xa9\xd4\xa8\xeb\x9f\xba\x25\xc4\x88\xf2\xfb\x72\xde\xe9\x03\x61\x9e\x95\xb2\x87\x71\xf0\x8c\xb5\xba\x59\x19\xa7\xdb\x95\x02\x80\x55\x6b\xb9\x9b\xf6\x65\x3d\x1c\xaa\xc9\x1b\x7d\xa4\xaa\x76\x76\xa5\x0a\xa5\x62\x84\xd7\x7d\x4b\xb8\xb5\x1b\xdc\x8a\x04\xdb\x7b\x94\x5f\x9d\x6e\x83\x18\x56\x95\xc4\xa4\x42\xf9\x1a\x22\x35\xd8\x00\xee\x08\x49\xc0\xe7\x91\xc0\x9d\x66\x9c\xbc\x1e\x03\x6a\x67\xcb\xac\x88\x07\x68\xe7\x86\x93\xb8\x9a\xc1\x63\xe0\x8e\x3c\x8e\xda\x4d\x14\xa4\xb8\x27\x84\x91\x6a\x6b\x2c\x35\x2a\xb9\x66\x6d\x02\xfb\xa9\x66\xc4\xc4\x76\x2d\x2c\x15\x03\x31\xee\x52\x45\xae\x9e\x89\xd5\xac\x24\x7c\x47\xa7\xac\x73\xed\x49\x33\x05\x68\xf4\x74\xca\x86\x2b\x33\xf5\xf5\x35\xfd\xda\xb8\xab\xfd\x14\xb8\xcb\x46\x2e\x14\x9e\x78\xf2\x3d\x3e\xe4\x9e\xc4\x6c\x23\x5b\x18\xb7\x11\xc0\x2d\x7a\xeb\x30\xbf\x92\x7d\x1e\x47\x77\x46\xd0\x47\xfa\xbd\xa0\x67\xe2\x34\x6e\xa7\x99\x3c\xa6\x20\xff\x4e\xad\x9d\x0b\x1b\x79\xd2\x2f\x67\x11\x8b\x40\x56\x38\x52\x93\xcd\x2c\x93\xfb\x32\x82\xb5\xc9\x03\x15\x4b\x0b\xeb\xbf\x46\x5f\x20\xaa\x1b\x53\xca\xfd\xbd\xf4\x2d\x1f\xd7\x43\x44\x5f\x5c\x32\xfd\xb0\xdc\x3d\x7a\x3f\xf8\xf7\x85\x7b\x8b\xf9\x2f\xca\xb7\xd7\x39\x5c\x4a\xdd\x2e\xfb\xbd\xe4\xbe\xd8\xf7\xbf\x26\xf0\x87\xb7\x8c\x22\xc6\x8f\xa0\xbe\xc1\x3c\xff\x0a\x00\x00\xff\xff\x3c\x32\xe5\x42\x28\x04\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x41\x8b\xdb\x30\x10\x85\xcf\xab\x5f\xf1\x08\x4b\x89\x97\x60\xdf\x53\xf6\x50\xba\x5b\xe8\x25\x5b\xd8\x85\x9e\x15\x7b\x64\x8b\x2a\xb6\x91\xc6\x09\x41\xf8\xbf\x97\x91\x97\x34\xa5\x4a\xe9\xa5\x37\x59\xa3\xf7\xde\x7c\x33\xae\x2a\x7c\x1e\x1a\x42\x4b\x3d\x79\xcd\xd4\x60\x7f\x86\x69\x3f\xe2\xe9\x05\xbb\x97\x37\x3c\x3f\x7d\x7d\x2b\x95\x1a\x75\xfd\x43\xb7\x84\x18\x51\x7e\x5b\xce\x3b\x7d\x20\xcc\xb3\x52\xf6\x30\x0e\x9e\xb1\x56\x77\x2b\xe3\x74\xbb\x52\x00\xb0\x6a\x2d\x77\xd3\xbe\xac\x87\x43\x35\x79\xa3\x8f\x54\xd5\xce\xae\x54\xa1\x54\x8c\xf0\xba\x6f\x09\xf7\x76\x83\x7b\x91\x60\xfb\x88\xf2\x8b\xd3\x6d\x10\xc3\xaa\x92\x98\x54\x28\xdf\x43\xa4\x06\x1b\xc0\x1d\x21\x09\xf8\x3c\x12\xb8\xd3\x8c\x93\xd7\x63\x40\xed\x6c\x99\x15\xf1\x00\xed\xdc\x70\x12\x57\x33\x78\x0c\xdc\x91\xc7\x51\xbb\x89\x82\x14\xf7\x84\x30\x52\x6d\x8d\xa5\x46\x25\xd7\xac\x4d\x60\x3f\xd5\x8c\x98\xd8\x6e\x85\xa5\x62\x20\xc6\x43\xaa\xc8\xd5\x2b\xb1\x9a\x95\x84\xef\xe8\x94\x75\xae\x3d\x69\xa6\x00\x8d\x9e\x4e\xd9\x70\x65\xa6\xbe\xbe\xa5\x5f\x1b\x77\xb3\x9f\x02\x0f\xd9\xc8\x85\xc2\x13\x4f\xbe\xc7\x87\xdc\x93\x98\x6d\x64\x0b\xe3\x36\x02\xb8\x45\x6f\x1d\xe6\x77\xb2\x4f\xe3\xe8\xce\x08\xfa\x48\xbf\x16\xf4\x4a\x9c\xc6\xed\x34\x93\xc7\x14\xe4\xdf\xa9\xb5\x73\x61\x23\x4f\xfa\xe5\x2c\x62\x11\xc8\x0a\x47\x6a\xb2\x99\x65\x72\x5f\x46\xb0\x36\x79\xa0\x62\x69\x61\xfd\xc7\xe8\x0b\x44\x75\x67\x4a\xb9\x7f\x94\xbe\xe5\xe3\x76\x88\xe8\x8b\x6b\xa6\xef\x96\xbb\x67\xef\x07\xff\x7f\xe1\x2e\x31\xff\x44\x79\x79\x9d\xc3\xa5\xd4\xed\xb2\xdf\x6b\xee\xab\x7d\xff\x6d\x02\xbf\x79\xcb\x28\x62\x04\xf5\x0d\xe6\xf9\x67\x00\x00\x00\xff\xff\x1d\x0d\x69\x06\x27\x04\x00\x00"), }, "/templates/cli_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "cli_flags_generated.gotpl", modTime: time.Time{}, - uncompressedSize: 2234, + uncompressedSize: 2230, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\x41\x4f\xeb\x38\x10\x3e\x37\xbf\x62\xb6\xe2\x90\xa0\x6e\x7b\x5f\xc4\x89\xc2\x2e\xd2\x0a\xd0\x83\xc7\xdd\x4d\xc6\xa9\x85\xb1\x8b\xed\xc0\x43\x55\xfe\xfb\xd3\x8c\x9d\xb4\x4d\x0b\xf4\xf2\xe8\xc9\x9e\xf9\xf2\xcd\x37\xdf\x8c\xea\xd9\x0c\x2e\x6c\x85\x50\xa3\x41\x27\x02\x56\xb0\x78\x07\x59\x9f\xc1\xfc\x16\x6e\x6e\x1f\xe0\x72\x7e\xfd\x30\xcd\xb2\x95\x28\x9f\x44\x8d\xb0\x5e\xc3\xf4\x2e\x9e\x6f\xc4\x33\x42\xdb\x66\x99\x7a\x5e\x59\x17\x20\xcf\x46\x63\xa9\x45\x3d\xce\x46\x63\x1f\x5c\x69\xcd\x2b\x1d\x83\x7a\xc6\x71\x56\x64\xeb\x35\x38\x61\x6a\x84\x13\x35\x81\x13\x02\xc2\x3f\xe7\x30\xbd\xd2\xa2\xf6\x44\x33\x9b\x11\x39\x27\xa6\x89\x9a\x72\xa0\x3c\x08\x60\xf8\x9b\x0a\x4b\x08\xef\x2b\xdc\x00\x1f\xe8\xd6\xb6\xfd\x7d\x6e\xcb\x20\x94\x26\xbe\x5d\xe0\x36\xa3\x0f\xae\x29\x03\xac\x33\x00\x00\x4e\xa4\x9f\x0f\x4e\x99\x9a\xc3\x3f\x3d\x75\xbb\x17\xbe\x34\xaf\x8f\xc2\xed\x85\xaf\x94\xc6\x3b\x11\x96\x83\xf0\x0f\x7c\x69\x94\xc3\x8a\xce\x0b\x6b\x35\x07\xff\x53\x55\x85\x26\x52\xf4\xc1\xf5\xfa\x6f\x50\x12\xf0\x25\xc9\x7d\x14\xba\x41\x08\xae\x61\x87\x47\x7c\x1d\x8d\x86\x6d\x67\x23\xfa\x0e\x4d\xd5\x9f\xb7\x39\xe6\xe8\x83\x32\x22\x28\x6b\x36\x4c\x5b\xc1\xd1\xe9\xa7\x7c\x6d\x46\x23\xb9\xe7\x6e\xc0\x61\x68\x9c\xa1\x49\x38\x14\x95\x58\x68\x04\x87\x2b\x87\x1e\x4d\x88\x15\xac\x84\xb0\x54\x1e\x5e\x49\x2a\x7d\x99\x4b\xeb\xa0\x61\x1b\x2b\x94\xa2\xd1\xc1\x17\x99\x6c\x4c\x09\xb9\x3c\x38\x97\x22\x15\xcb\x8b\xe4\x61\x9a\x50\xac\x0d\x04\x89\x00\x74\xb9\x2c\x92\xbe\x7f\x31\x30\x45\x27\x30\x2c\x11\x0c\x05\x58\x0f\xf2\xe2\x7c\x51\x35\x51\x7c\x50\x56\x32\x38\x55\xbb\xf6\xfd\x48\xbb\x82\x6f\x4b\x0c\x4b\x74\x60\x1d\x18\x1b\xfa\x9a\xb4\xb6\x2e\x61\xbf\xa8\xbf\x21\xcd\x0b\xde\x88\xa1\x80\x2e\x9d\x44\x0c\x59\x40\x5b\xfb\xe4\xa1\x59\x71\x71\xf6\x9f\xba\x17\xa0\x6d\x29\xf4\xc1\xa2\x93\x4e\xfe\x0e\xdf\x85\x35\x01\x7f\x85\x79\x9c\x16\x31\x2b\xc9\x4d\x49\xdb\x98\xae\x8b\x12\x4e\x13\xae\xd8\xa3\xce\xd9\xf9\xe8\x22\x67\xe9\x7b\x84\x8e\x98\xb7\x6c\x3c\x26\xe2\x61\xcd\xb4\x80\x14\x47\xed\x71\x07\xb2\xc9\x75\xbb\xb9\x6b\x10\xb5\xdf\xac\x0e\x6a\x99\x40\x39\xa5\xe0\x3d\x86\x7e\x61\xb4\x5d\x08\x7d\xb4\x87\x35\xc3\xff\xa4\x89\x87\x05\x7d\xb3\x95\x4a\x82\xf4\xf4\x7f\x1c\xcd\x8c\x9a\xae\xa2\x73\x9d\x93\xc5\x19\x61\xfe\x3a\x07\xa3\xba\x15\x3d\x76\x0a\xd2\x17\x8c\x6f\xb7\xe7\xf6\xb1\x65\x34\x2a\x36\xea\x13\xd2\xe4\xcd\x04\x3c\x06\x38\xe5\x74\xd2\xfb\x0d\x76\x49\xb2\xca\x63\x98\xfe\xcf\x02\x59\x50\xd1\x1b\xb9\xef\xd1\x46\xd0\x9d\x70\x1e\x5d\xd4\xb2\xa2\x73\x35\x01\x74\x8e\xf8\xfa\xb2\x09\xc3\xcf\x5a\xd2\x34\x80\xca\xf8\x40\xf0\xdd\xba\xdc\x28\x5d\x10\x36\xfe\x71\x77\x45\xe9\x2d\x70\x6e\x5f\xcc\x71\x23\xe8\x90\xed\x87\x4d\x5c\x08\x1f\x62\x23\x43\xb6\xad\xfc\x76\x13\x09\x16\x7b\xd9\xd5\x7b\xfc\x62\x6c\x66\xf1\x3b\x00\x00\xff\xff\x59\x27\xb0\x6d\xba\x08\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\x41\x4f\xeb\x38\x10\x3e\x37\xbf\x62\xb6\xe2\x90\xa0\x6e\x7b\x5f\xc4\x89\xc2\x2e\xd2\x0a\xd0\x83\xc7\xdd\x4d\xc6\xa9\x85\xb1\x8b\xed\xc0\x43\x51\xff\xfb\xd3\x8c\x9d\xb4\x4d\x0b\xf4\xc2\xeb\xc9\x9e\xf9\xfc\xcd\x37\xdf\x8c\x9a\xd9\x0c\x2e\x6c\x85\x50\xa3\x41\x27\x02\x56\xb0\x78\x07\x59\x9f\xc1\xfc\x16\x6e\x6e\x1f\xe0\x72\x7e\xfd\x30\xcd\xb2\x95\x28\x9f\x44\x8d\xd0\xb6\x30\xbd\x8b\xe7\x1b\xf1\x8c\xb0\x5e\x67\x99\x7a\x5e\x59\x17\x20\xcf\x46\x63\xa9\x45\x3d\xce\x46\x63\x1f\x5c\x69\xcd\x2b\x1d\x83\x7a\xc6\x71\x56\x64\x6d\x0b\x4e\x98\x1a\xe1\x44\x4d\xe0\x84\x80\xf0\xcf\x39\x4c\xaf\xb4\xa8\x3d\xd1\xcc\x66\x44\xce\x89\x69\xa2\xa6\x1c\x28\x0f\x02\x18\xfe\xa6\xc2\x12\xc2\xfb\x0a\x37\xc0\x07\xba\xad\xd7\xfd\x7d\x6e\xcb\x20\x94\x26\xbe\x5d\xe0\x36\xa3\x0f\xae\x29\x03\xb4\x19\x00\x00\x27\xd2\xcf\x07\xa7\x4c\xcd\xe1\x9f\x9e\xba\xdd\x0b\x5f\x9a\xd7\x47\xe1\xf6\xc2\x57\x4a\xe3\x9d\x08\xcb\x41\xf8\x07\xbe\x34\xca\x61\x45\xe7\x85\xb5\x9a\x83\xff\xa9\xaa\x42\x13\x29\xfa\x60\xdb\xfe\x0d\x4a\x02\xbe\x24\xb9\x8f\x42\x37\x08\xc1\x35\xec\xf0\x88\xaf\xa3\xd1\xb0\xed\x6c\x44\xef\xd0\x54\xfd\x79\x9b\x63\x8e\x3e\x28\x23\x82\xb2\x66\xc3\xb4\x15\x1c\x9d\x7e\xca\xb7\xce\x68\x24\xf7\xdc\x0d\x38\x0c\x8d\x33\x34\x09\x87\xa2\x12\x0b\x8d\xe0\x70\xe5\xd0\xa3\x09\xb1\x82\x95\x10\x96\xca\xc3\x2b\x49\xa5\x97\xb9\xb4\x0e\x1a\xb6\xb1\x42\x29\x1a\x1d\x7c\x91\xc9\xc6\x94\x90\xcb\x83\x73\x29\x52\xb1\xbc\x48\x1e\xa6\x09\xc5\xda\x40\x90\x08\x40\x97\xcb\x22\xe9\xfb\x17\x03\x53\x74\x02\xc3\x12\xc1\x50\x80\xf5\x20\x2f\xce\x17\x55\x13\xc5\x07\x65\x25\x83\x53\xb5\x6b\xdf\x8f\xb4\x2b\xf8\xb6\xc4\xb0\x44\x07\xd6\x81\xb1\xa1\xaf\x49\x6b\xeb\x12\xf6\x8b\xfa\x1b\xd2\xbc\xe0\x8d\x18\x0a\xe8\xd2\x49\xc4\x90\x05\xb4\xb5\x4f\x1e\x9a\x15\x17\x67\xff\xa9\x7b\x01\xda\x96\x42\x1f\x2c\x3a\xe9\xe4\xef\xf0\x5d\x58\x13\xf0\x57\x98\xc7\x69\x11\xb3\x92\xdc\x94\xb4\x8d\xe9\xba\x28\xe1\x34\xe1\x8a\x3d\xea\x9c\x9d\x8f\x2e\x16\x6d\xcb\xcf\x11\x3a\x5e\x5e\xb2\xf1\x98\x78\x87\x25\xd3\xfe\x51\x1c\xb5\xc7\x1d\xc8\x26\xd7\xad\xe6\xae\x3f\xd4\x7d\xb3\x3a\x28\x65\x02\xe5\x94\x82\xf7\x18\xfa\x7d\xd1\x76\x21\xf4\xd1\x16\xd6\x0c\xff\x4e\x0f\x0f\x0b\xfa\xb3\x4e\x2a\x09\xd2\xd3\xbf\x71\xf4\x32\x4a\xba\x8a\xc6\x75\x46\x16\x67\x84\xf9\xeb\x1c\x8c\xea\x16\xf4\xd8\x21\x48\x5f\x30\x7e\xbd\x3d\xb6\x8f\x1d\xa3\x49\xb1\x4f\x9f\x90\x26\x6b\x26\xe0\x31\xc0\x29\xa7\x93\xde\xef\x77\x4b\x92\x53\x1e\xc3\xf4\x7f\xd6\xc7\x7a\x8a\xde\xc7\x7d\x8b\x36\x82\xee\x84\xf3\xe8\xa2\x96\x15\x9d\xab\x09\xa0\x73\xc4\xd7\x97\x4d\x18\xfe\xa6\x25\x4d\x03\xa8\x8c\x5f\x07\xbe\x5b\x97\x1b\xa5\xa9\xe7\xf4\xaf\xdd\x15\xa5\x0f\x81\x73\xfb\x62\x8e\x9b\x40\x87\x5c\x7f\xd8\xc4\x85\xf0\x21\x36\x32\x64\xdb\xca\x6f\x37\x91\x60\xb1\x97\x5d\xbd\xc7\xef\x45\xff\xee\x77\x00\x00\x00\xff\xff\x4d\xaf\x90\xd0\xb6\x08\x00\x00"), }, } fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ diff --git a/flag-gen/templates/altsrc_flags_generated.gotpl b/flag-gen/templates/altsrc_flags_generated.gotpl index 54feb84..e89eb8e 100644 --- a/flag-gen/templates/altsrc_flags_generated.gotpl +++ b/flag-gen/templates/altsrc_flags_generated.gotpl @@ -6,7 +6,6 @@ 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 @@ -33,4 +32,4 @@ func (f *{{ $flag.Name }}Flag) ApplyWithError(set *flag.FlagSet) error { f.set = set return f.{{ $flag.Name }}Flag.ApplyWithError(set) } -{{- end }} \ No newline at end of file +{{ end }} \ No newline at end of file diff --git a/flag-gen/templates/cli_flags_generated.gotpl b/flag-gen/templates/cli_flags_generated.gotpl index 4f148c6..3a6ca7c 100644 --- a/flag-gen/templates/cli_flags_generated.gotpl +++ b/flag-gen/templates/cli_flags_generated.gotpl @@ -42,20 +42,20 @@ func (f {{ $flag.Name }}Flag) IsRequired() bool { // {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns // {{ $flag.ContextDefault }} if not found -func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { +func (c *Context) {{ $flag.Name }}(name string){{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { return lookup{{ $flag.Name }}(name, c.flagSet) } // Global{{ $flag.Name }} looks up the value of a global {{ $flag.Name }}Flag, returns // {{ $flag.ContextDefault }} if not found -func (c *Context) Global{{ $flag.Name }}(name string) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { +func (c *Context) Global{{ $flag.Name }}(name string){{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { if fs := lookupGlobalFlagSet(name, c); fs != nil { return lookup{{ $flag.Name }}(name, fs) } return {{ $flag.ContextDefault }} } -func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { +func lookup{{ $flag.Name }}(name string, set *flag.FlagSet){{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { f := set.Lookup(name) if f != nil { {{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }} @@ -66,4 +66,4 @@ func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextTyp } return {{ $flag.ContextDefault }} } -{{- end }} \ No newline at end of file +{{ end }} \ No newline at end of file From 86e10211dea0c2b369610aabea1c987888bbb01a Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 11:05:50 +0530 Subject: [PATCH 12/31] remove redundant go generate from altsrc update go generate in cli package to generate both files regeneration test --- altsrc/altsrc.go | 3 - altsrc/flag_generated.go | 346 ------------------- cli.go | 2 +- flag_generated.go | 718 --------------------------------------- 4 files changed, 1 insertion(+), 1068 deletions(-) delete mode 100644 altsrc/altsrc.go delete mode 100644 altsrc/flag_generated.go delete mode 100644 flag_generated.go diff --git a/altsrc/altsrc.go b/altsrc/altsrc.go deleted file mode 100644 index b81c99a..0000000 --- a/altsrc/altsrc.go +++ /dev/null @@ -1,3 +0,0 @@ -package altsrc - -//go:generate fg -p altsrc -i ../flag-types.json -o flag_generated.go diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go deleted file mode 100644 index 0c45914..0000000 --- a/altsrc/flag_generated.go +++ /dev/null @@ -1,346 +0,0 @@ -// Code generated by fg; DO NOT EDIT. - -package altsrc - -import ( - "flag" - "github.com/urfave/cli" -) - -// BoolFlag is the flag type that wraps cli.BoolFlag to allow -// for other values to be specified -type BoolFlag struct { - cli.BoolFlag - set *flag.FlagSet -} - -// NewBoolFlag creates a new BoolFlag -func NewBoolFlag(fl cli.BoolFlag) *BoolFlag { - return &BoolFlag{BoolFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped BoolFlag.Apply -func (f *BoolFlag) Apply(set *flag.FlagSet) { - f.set = set - f.BoolFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped BoolFlag.ApplyWithError -func (f *BoolFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.BoolFlag.ApplyWithError(set) -} - -// BoolTFlag is the flag type that wraps cli.BoolTFlag to allow -// for other values to be specified -type BoolTFlag struct { - cli.BoolTFlag - set *flag.FlagSet -} - -// NewBoolTFlag creates a new BoolTFlag -func NewBoolTFlag(fl cli.BoolTFlag) *BoolTFlag { - return &BoolTFlag{BoolTFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped BoolTFlag.Apply -func (f *BoolTFlag) Apply(set *flag.FlagSet) { - f.set = set - f.BoolTFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped BoolTFlag.ApplyWithError -func (f *BoolTFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.BoolTFlag.ApplyWithError(set) -} - -// DurationFlag is the flag type that wraps cli.DurationFlag to allow -// for other values to be specified -type DurationFlag struct { - cli.DurationFlag - set *flag.FlagSet -} - -// NewDurationFlag creates a new DurationFlag -func NewDurationFlag(fl cli.DurationFlag) *DurationFlag { - return &DurationFlag{DurationFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped DurationFlag.Apply -func (f *DurationFlag) Apply(set *flag.FlagSet) { - f.set = set - f.DurationFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped DurationFlag.ApplyWithError -func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.DurationFlag.ApplyWithError(set) -} - -// Float64Flag is the flag type that wraps cli.Float64Flag to allow -// for other values to be specified -type Float64Flag struct { - cli.Float64Flag - set *flag.FlagSet -} - -// NewFloat64Flag creates a new Float64Flag -func NewFloat64Flag(fl cli.Float64Flag) *Float64Flag { - return &Float64Flag{Float64Flag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped Float64Flag.Apply -func (f *Float64Flag) Apply(set *flag.FlagSet) { - f.set = set - f.Float64Flag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped Float64Flag.ApplyWithError -func (f *Float64Flag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.Float64Flag.ApplyWithError(set) -} - -// GenericFlag is the flag type that wraps cli.GenericFlag to allow -// for other values to be specified -type GenericFlag struct { - cli.GenericFlag - set *flag.FlagSet -} - -// NewGenericFlag creates a new GenericFlag -func NewGenericFlag(fl cli.GenericFlag) *GenericFlag { - return &GenericFlag{GenericFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped GenericFlag.Apply -func (f *GenericFlag) Apply(set *flag.FlagSet) { - f.set = set - f.GenericFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped GenericFlag.ApplyWithError -func (f *GenericFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.GenericFlag.ApplyWithError(set) -} - -// Int64Flag is the flag type that wraps cli.Int64Flag to allow -// for other values to be specified -type Int64Flag struct { - cli.Int64Flag - set *flag.FlagSet -} - -// NewInt64Flag creates a new Int64Flag -func NewInt64Flag(fl cli.Int64Flag) *Int64Flag { - return &Int64Flag{Int64Flag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped Int64Flag.Apply -func (f *Int64Flag) Apply(set *flag.FlagSet) { - f.set = set - f.Int64Flag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped Int64Flag.ApplyWithError -func (f *Int64Flag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.Int64Flag.ApplyWithError(set) -} - -// IntFlag is the flag type that wraps cli.IntFlag to allow -// for other values to be specified -type IntFlag struct { - cli.IntFlag - set *flag.FlagSet -} - -// NewIntFlag creates a new IntFlag -func NewIntFlag(fl cli.IntFlag) *IntFlag { - return &IntFlag{IntFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped IntFlag.Apply -func (f *IntFlag) Apply(set *flag.FlagSet) { - f.set = set - f.IntFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped IntFlag.ApplyWithError -func (f *IntFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.IntFlag.ApplyWithError(set) -} - -// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow -// for other values to be specified -type IntSliceFlag struct { - cli.IntSliceFlag - set *flag.FlagSet -} - -// NewIntSliceFlag creates a new IntSliceFlag -func NewIntSliceFlag(fl cli.IntSliceFlag) *IntSliceFlag { - return &IntSliceFlag{IntSliceFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped IntSliceFlag.Apply -func (f *IntSliceFlag) Apply(set *flag.FlagSet) { - f.set = set - f.IntSliceFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped IntSliceFlag.ApplyWithError -func (f *IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.IntSliceFlag.ApplyWithError(set) -} - -// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow -// for other values to be specified -type Int64SliceFlag struct { - cli.Int64SliceFlag - set *flag.FlagSet -} - -// NewInt64SliceFlag creates a new Int64SliceFlag -func NewInt64SliceFlag(fl cli.Int64SliceFlag) *Int64SliceFlag { - return &Int64SliceFlag{Int64SliceFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped Int64SliceFlag.Apply -func (f *Int64SliceFlag) Apply(set *flag.FlagSet) { - f.set = set - f.Int64SliceFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped Int64SliceFlag.ApplyWithError -func (f *Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.Int64SliceFlag.ApplyWithError(set) -} - -// StringFlag is the flag type that wraps cli.StringFlag to allow -// for other values to be specified -type StringFlag struct { - cli.StringFlag - set *flag.FlagSet -} - -// NewStringFlag creates a new StringFlag -func NewStringFlag(fl cli.StringFlag) *StringFlag { - return &StringFlag{StringFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped StringFlag.Apply -func (f *StringFlag) Apply(set *flag.FlagSet) { - f.set = set - f.StringFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped StringFlag.ApplyWithError -func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.StringFlag.ApplyWithError(set) -} - -// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow -// for other values to be specified -type StringSliceFlag struct { - cli.StringSliceFlag - set *flag.FlagSet -} - -// NewStringSliceFlag creates a new StringSliceFlag -func NewStringSliceFlag(fl cli.StringSliceFlag) *StringSliceFlag { - return &StringSliceFlag{StringSliceFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped StringSliceFlag.Apply -func (f *StringSliceFlag) Apply(set *flag.FlagSet) { - f.set = set - f.StringSliceFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped StringSliceFlag.ApplyWithError -func (f *StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.StringSliceFlag.ApplyWithError(set) -} - -// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow -// for other values to be specified -type Uint64Flag struct { - cli.Uint64Flag - set *flag.FlagSet -} - -// NewUint64Flag creates a new Uint64Flag -func NewUint64Flag(fl cli.Uint64Flag) *Uint64Flag { - return &Uint64Flag{Uint64Flag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped Uint64Flag.Apply -func (f *Uint64Flag) Apply(set *flag.FlagSet) { - f.set = set - f.Uint64Flag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped Uint64Flag.ApplyWithError -func (f *Uint64Flag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.Uint64Flag.ApplyWithError(set) -} - -// UintFlag is the flag type that wraps cli.UintFlag to allow -// for other values to be specified -type UintFlag struct { - cli.UintFlag - set *flag.FlagSet -} - -// NewUintFlag creates a new UintFlag -func NewUintFlag(fl cli.UintFlag) *UintFlag { - return &UintFlag{UintFlag: fl, set: nil} -} - -// Apply saves the flagSet for later usage calls, then calls -// the wrapped UintFlag.Apply -func (f *UintFlag) Apply(set *flag.FlagSet) { - f.set = set - f.UintFlag.Apply(set) -} - -// ApplyWithError saves the flagSet for later usage calls, then calls -// the wrapped UintFlag.ApplyWithError -func (f *UintFlag) ApplyWithError(set *flag.FlagSet) error { - f.set = set - return f.UintFlag.ApplyWithError(set) -} diff --git a/cli.go b/cli.go index e71e142..80d4357 100644 --- a/cli.go +++ b/cli.go @@ -19,4 +19,4 @@ // } package cli -//go:generate fg -p cli -i flag-types.json -o flag_generated.go +//go:generate flag-generator diff --git a/flag_generated.go b/flag_generated.go deleted file mode 100644 index f106d23..0000000 --- a/flag_generated.go +++ /dev/null @@ -1,718 +0,0 @@ -// Code generated by fg; DO NOT EDIT. - -package cli - -import ( - "flag" - "strconv" - "time" -) - -// BoolFlag is a flag with type bool -type BoolFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Destination *bool -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f BoolFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f BoolFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f BoolFlag) IsRequired() bool { - return f.Required -} - -// Bool looks up the value of a local BoolFlag, returns -// false if not found -func (c *Context) Bool(name string) bool { - return lookupBool(name, c.flagSet) -} - -// GlobalBool looks up the value of a global BoolFlag, returns -// false if not found -func (c *Context) GlobalBool(name string) bool { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupBool(name, fs) - } - return false -} - -func lookupBool(name string, set *flag.FlagSet) bool { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseBool(f.Value.String()) - if err != nil { - return false - } - return parsed - } - return false -} - -// BoolTFlag is a flag with type bool that is true by default -type BoolTFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Destination *bool -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f BoolTFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f BoolTFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f BoolTFlag) IsRequired() bool { - return f.Required -} - -// BoolT looks up the value of a local BoolTFlag, returns -// false if not found -func (c *Context) BoolT(name string) bool { - return lookupBoolT(name, c.flagSet) -} - -// GlobalBoolT looks up the value of a global BoolTFlag, returns -// false if not found -func (c *Context) GlobalBoolT(name string) bool { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupBoolT(name, fs) - } - return false -} - -func lookupBoolT(name string, set *flag.FlagSet) bool { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseBool(f.Value.String()) - if err != nil { - return false - } - return parsed - } - return false -} - -// DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) -type DurationFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value time.Duration - Destination *time.Duration -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f DurationFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f DurationFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f DurationFlag) IsRequired() bool { - return f.Required -} - -// Duration looks up the value of a local DurationFlag, returns -// 0 if not found -func (c *Context) Duration(name string) time.Duration { - return lookupDuration(name, c.flagSet) -} - -// GlobalDuration looks up the value of a global DurationFlag, returns -// 0 if not found -func (c *Context) GlobalDuration(name string) time.Duration { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupDuration(name, fs) - } - return 0 -} - -func lookupDuration(name string, set *flag.FlagSet) time.Duration { - f := set.Lookup(name) - if f != nil { - parsed, err := time.ParseDuration(f.Value.String()) - if err != nil { - return 0 - } - return parsed - } - return 0 -} - -// Float64Flag is a flag with type float64 -type Float64Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value float64 - Destination *float64 -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f Float64Flag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f Float64Flag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f Float64Flag) IsRequired() bool { - return f.Required -} - -// Float64 looks up the value of a local Float64Flag, returns -// 0 if not found -func (c *Context) Float64(name string) float64 { - return lookupFloat64(name, c.flagSet) -} - -// GlobalFloat64 looks up the value of a global Float64Flag, returns -// 0 if not found -func (c *Context) GlobalFloat64(name string) float64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupFloat64(name, fs) - } - return 0 -} - -func lookupFloat64(name string, set *flag.FlagSet) float64 { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseFloat(f.Value.String(), 64) - if err != nil { - return 0 - } - return parsed - } - return 0 -} - -// GenericFlag is a flag with type Generic -type GenericFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value Generic -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f GenericFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f GenericFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f GenericFlag) IsRequired() bool { - return f.Required -} - -// Generic looks up the value of a local GenericFlag, returns -// nil if not found -func (c *Context) Generic(name string) interface{} { - return lookupGeneric(name, c.flagSet) -} - -// GlobalGeneric looks up the value of a global GenericFlag, returns -// nil if not found -func (c *Context) GlobalGeneric(name string) interface{} { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupGeneric(name, fs) - } - return nil -} - -func lookupGeneric(name string, set *flag.FlagSet) interface{} { - f := set.Lookup(name) - if f != nil { - parsed, err := f.Value, error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} - -// Int64Flag is a flag with type int64 -type Int64Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value int64 - Destination *int64 -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f Int64Flag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f Int64Flag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f Int64Flag) IsRequired() bool { - return f.Required -} - -// Int64 looks up the value of a local Int64Flag, returns -// 0 if not found -func (c *Context) Int64(name string) int64 { - return lookupInt64(name, c.flagSet) -} - -// GlobalInt64 looks up the value of a global Int64Flag, returns -// 0 if not found -func (c *Context) GlobalInt64(name string) int64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupInt64(name, fs) - } - return 0 -} - -func lookupInt64(name string, set *flag.FlagSet) int64 { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return parsed - } - return 0 -} - -// IntFlag is a flag with type int -type IntFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value int - Destination *int -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f IntFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f IntFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f IntFlag) IsRequired() bool { - return f.Required -} - -// Int looks up the value of a local IntFlag, returns -// 0 if not found -func (c *Context) Int(name string) int { - return lookupInt(name, c.flagSet) -} - -// GlobalInt looks up the value of a global IntFlag, returns -// 0 if not found -func (c *Context) GlobalInt(name string) int { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupInt(name, fs) - } - return 0 -} - -func lookupInt(name string, set *flag.FlagSet) int { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return int(parsed) - } - return 0 -} - -// IntSliceFlag is a flag with type *IntSlice -type IntSliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *IntSlice -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f IntSliceFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f IntSliceFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f IntSliceFlag) IsRequired() bool { - return f.Required -} - -// IntSlice looks up the value of a local IntSliceFlag, returns -// nil if not found -func (c *Context) IntSlice(name string) []int { - return lookupIntSlice(name, c.flagSet) -} - -// GlobalIntSlice looks up the value of a global IntSliceFlag, returns -// nil if not found -func (c *Context) GlobalIntSlice(name string) []int { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupIntSlice(name, fs) - } - return nil -} - -func lookupIntSlice(name string, set *flag.FlagSet) []int { - f := set.Lookup(name) - if f != nil { - parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} - -// Int64SliceFlag is a flag with type *Int64Slice -type Int64SliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *Int64Slice -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f Int64SliceFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f Int64SliceFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f Int64SliceFlag) IsRequired() bool { - return f.Required -} - -// Int64Slice looks up the value of a local Int64SliceFlag, returns -// nil if not found -func (c *Context) Int64Slice(name string) []int64 { - return lookupInt64Slice(name, c.flagSet) -} - -// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns -// nil if not found -func (c *Context) GlobalInt64Slice(name string) []int64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupInt64Slice(name, fs) - } - return nil -} - -func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { - f := set.Lookup(name) - if f != nil { - parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} - -// StringFlag is a flag with type string -type StringFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value string - Destination *string -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f StringFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f StringFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f StringFlag) IsRequired() bool { - return f.Required -} - -// String looks up the value of a local StringFlag, returns -// "" if not found -func (c *Context) String(name string) string { - return lookupString(name, c.flagSet) -} - -// GlobalString looks up the value of a global StringFlag, returns -// "" if not found -func (c *Context) GlobalString(name string) string { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupString(name, fs) - } - return "" -} - -func lookupString(name string, set *flag.FlagSet) string { - f := set.Lookup(name) - if f != nil { - parsed, err := f.Value.String(), error(nil) - if err != nil { - return "" - } - return parsed - } - return "" -} - -// StringSliceFlag is a flag with type *StringSlice -type StringSliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *StringSlice -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f StringSliceFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f StringSliceFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f StringSliceFlag) IsRequired() bool { - return f.Required -} - -// StringSlice looks up the value of a local StringSliceFlag, returns -// nil if not found -func (c *Context) StringSlice(name string) []string { - return lookupStringSlice(name, c.flagSet) -} - -// GlobalStringSlice looks up the value of a global StringSliceFlag, returns -// nil if not found -func (c *Context) GlobalStringSlice(name string) []string { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupStringSlice(name, fs) - } - return nil -} - -func lookupStringSlice(name string, set *flag.FlagSet) []string { - f := set.Lookup(name) - if f != nil { - parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} - -// Uint64Flag is a flag with type uint64 -type Uint64Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value uint64 - Destination *uint64 -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f Uint64Flag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f Uint64Flag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f Uint64Flag) IsRequired() bool { - return f.Required -} - -// Uint64 looks up the value of a local Uint64Flag, returns -// 0 if not found -func (c *Context) Uint64(name string) uint64 { - return lookupUint64(name, c.flagSet) -} - -// GlobalUint64 looks up the value of a global Uint64Flag, returns -// 0 if not found -func (c *Context) GlobalUint64(name string) uint64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupUint64(name, fs) - } - return 0 -} - -func lookupUint64(name string, set *flag.FlagSet) uint64 { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return parsed - } - return 0 -} - -// UintFlag is a flag with type uint -type UintFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value uint - Destination *uint -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f UintFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f UintFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f UintFlag) IsRequired() bool { - return f.Required -} - -// Uint looks up the value of a local UintFlag, returns -// 0 if not found -func (c *Context) Uint(name string) uint { - return lookupUint(name, c.flagSet) -} - -// GlobalUint looks up the value of a global UintFlag, returns -// 0 if not found -func (c *Context) GlobalUint(name string) uint { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupUint(name, fs) - } - return 0 -} - -func lookupUint(name string, set *flag.FlagSet) uint { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return uint(parsed) - } - return 0 -} From 04948f21526ed8343ae9697600e284962d8972be Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 11:06:19 +0530 Subject: [PATCH 13/31] generate test with go generate --- altsrc/flag_generated.go | 346 +++++++++++++++++++ flag_generated.go | 718 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 1064 insertions(+) create mode 100644 altsrc/flag_generated.go create mode 100644 flag_generated.go diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go new file mode 100644 index 0000000..0c45914 --- /dev/null +++ b/altsrc/flag_generated.go @@ -0,0 +1,346 @@ +// Code generated by fg; DO NOT EDIT. + +package altsrc + +import ( + "flag" + "github.com/urfave/cli" +) + +// BoolFlag is the flag type that wraps cli.BoolFlag to allow +// for other values to be specified +type BoolFlag struct { + cli.BoolFlag + set *flag.FlagSet +} + +// NewBoolFlag creates a new BoolFlag +func NewBoolFlag(fl cli.BoolFlag) *BoolFlag { + return &BoolFlag{BoolFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped BoolFlag.Apply +func (f *BoolFlag) Apply(set *flag.FlagSet) { + f.set = set + f.BoolFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped BoolFlag.ApplyWithError +func (f *BoolFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.BoolFlag.ApplyWithError(set) +} + +// BoolTFlag is the flag type that wraps cli.BoolTFlag to allow +// for other values to be specified +type BoolTFlag struct { + cli.BoolTFlag + set *flag.FlagSet +} + +// NewBoolTFlag creates a new BoolTFlag +func NewBoolTFlag(fl cli.BoolTFlag) *BoolTFlag { + return &BoolTFlag{BoolTFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped BoolTFlag.Apply +func (f *BoolTFlag) Apply(set *flag.FlagSet) { + f.set = set + f.BoolTFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped BoolTFlag.ApplyWithError +func (f *BoolTFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.BoolTFlag.ApplyWithError(set) +} + +// DurationFlag is the flag type that wraps cli.DurationFlag to allow +// for other values to be specified +type DurationFlag struct { + cli.DurationFlag + set *flag.FlagSet +} + +// NewDurationFlag creates a new DurationFlag +func NewDurationFlag(fl cli.DurationFlag) *DurationFlag { + return &DurationFlag{DurationFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped DurationFlag.Apply +func (f *DurationFlag) Apply(set *flag.FlagSet) { + f.set = set + f.DurationFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped DurationFlag.ApplyWithError +func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.DurationFlag.ApplyWithError(set) +} + +// Float64Flag is the flag type that wraps cli.Float64Flag to allow +// for other values to be specified +type Float64Flag struct { + cli.Float64Flag + set *flag.FlagSet +} + +// NewFloat64Flag creates a new Float64Flag +func NewFloat64Flag(fl cli.Float64Flag) *Float64Flag { + return &Float64Flag{Float64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Float64Flag.Apply +func (f *Float64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Float64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Float64Flag.ApplyWithError +func (f *Float64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Float64Flag.ApplyWithError(set) +} + +// GenericFlag is the flag type that wraps cli.GenericFlag to allow +// for other values to be specified +type GenericFlag struct { + cli.GenericFlag + set *flag.FlagSet +} + +// NewGenericFlag creates a new GenericFlag +func NewGenericFlag(fl cli.GenericFlag) *GenericFlag { + return &GenericFlag{GenericFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped GenericFlag.Apply +func (f *GenericFlag) Apply(set *flag.FlagSet) { + f.set = set + f.GenericFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped GenericFlag.ApplyWithError +func (f *GenericFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.GenericFlag.ApplyWithError(set) +} + +// Int64Flag is the flag type that wraps cli.Int64Flag to allow +// for other values to be specified +type Int64Flag struct { + cli.Int64Flag + set *flag.FlagSet +} + +// NewInt64Flag creates a new Int64Flag +func NewInt64Flag(fl cli.Int64Flag) *Int64Flag { + return &Int64Flag{Int64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Int64Flag.Apply +func (f *Int64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Int64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Int64Flag.ApplyWithError +func (f *Int64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Int64Flag.ApplyWithError(set) +} + +// IntFlag is the flag type that wraps cli.IntFlag to allow +// for other values to be specified +type IntFlag struct { + cli.IntFlag + set *flag.FlagSet +} + +// NewIntFlag creates a new IntFlag +func NewIntFlag(fl cli.IntFlag) *IntFlag { + return &IntFlag{IntFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped IntFlag.Apply +func (f *IntFlag) Apply(set *flag.FlagSet) { + f.set = set + f.IntFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped IntFlag.ApplyWithError +func (f *IntFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.IntFlag.ApplyWithError(set) +} + +// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow +// for other values to be specified +type IntSliceFlag struct { + cli.IntSliceFlag + set *flag.FlagSet +} + +// NewIntSliceFlag creates a new IntSliceFlag +func NewIntSliceFlag(fl cli.IntSliceFlag) *IntSliceFlag { + return &IntSliceFlag{IntSliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped IntSliceFlag.Apply +func (f *IntSliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.IntSliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped IntSliceFlag.ApplyWithError +func (f *IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.IntSliceFlag.ApplyWithError(set) +} + +// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow +// for other values to be specified +type Int64SliceFlag struct { + cli.Int64SliceFlag + set *flag.FlagSet +} + +// NewInt64SliceFlag creates a new Int64SliceFlag +func NewInt64SliceFlag(fl cli.Int64SliceFlag) *Int64SliceFlag { + return &Int64SliceFlag{Int64SliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Int64SliceFlag.Apply +func (f *Int64SliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.Int64SliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Int64SliceFlag.ApplyWithError +func (f *Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Int64SliceFlag.ApplyWithError(set) +} + +// StringFlag is the flag type that wraps cli.StringFlag to allow +// for other values to be specified +type StringFlag struct { + cli.StringFlag + set *flag.FlagSet +} + +// NewStringFlag creates a new StringFlag +func NewStringFlag(fl cli.StringFlag) *StringFlag { + return &StringFlag{StringFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped StringFlag.Apply +func (f *StringFlag) Apply(set *flag.FlagSet) { + f.set = set + f.StringFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped StringFlag.ApplyWithError +func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.StringFlag.ApplyWithError(set) +} + +// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow +// for other values to be specified +type StringSliceFlag struct { + cli.StringSliceFlag + set *flag.FlagSet +} + +// NewStringSliceFlag creates a new StringSliceFlag +func NewStringSliceFlag(fl cli.StringSliceFlag) *StringSliceFlag { + return &StringSliceFlag{StringSliceFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped StringSliceFlag.Apply +func (f *StringSliceFlag) Apply(set *flag.FlagSet) { + f.set = set + f.StringSliceFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped StringSliceFlag.ApplyWithError +func (f *StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.StringSliceFlag.ApplyWithError(set) +} + +// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow +// for other values to be specified +type Uint64Flag struct { + cli.Uint64Flag + set *flag.FlagSet +} + +// NewUint64Flag creates a new Uint64Flag +func NewUint64Flag(fl cli.Uint64Flag) *Uint64Flag { + return &Uint64Flag{Uint64Flag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped Uint64Flag.Apply +func (f *Uint64Flag) Apply(set *flag.FlagSet) { + f.set = set + f.Uint64Flag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped Uint64Flag.ApplyWithError +func (f *Uint64Flag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.Uint64Flag.ApplyWithError(set) +} + +// UintFlag is the flag type that wraps cli.UintFlag to allow +// for other values to be specified +type UintFlag struct { + cli.UintFlag + set *flag.FlagSet +} + +// NewUintFlag creates a new UintFlag +func NewUintFlag(fl cli.UintFlag) *UintFlag { + return &UintFlag{UintFlag: fl, set: nil} +} + +// Apply saves the flagSet for later usage calls, then calls +// the wrapped UintFlag.Apply +func (f *UintFlag) Apply(set *flag.FlagSet) { + f.set = set + f.UintFlag.Apply(set) +} + +// ApplyWithError saves the flagSet for later usage calls, then calls +// the wrapped UintFlag.ApplyWithError +func (f *UintFlag) ApplyWithError(set *flag.FlagSet) error { + f.set = set + return f.UintFlag.ApplyWithError(set) +} diff --git a/flag_generated.go b/flag_generated.go new file mode 100644 index 0000000..f106d23 --- /dev/null +++ b/flag_generated.go @@ -0,0 +1,718 @@ +// Code generated by fg; DO NOT EDIT. + +package cli + +import ( + "flag" + "strconv" + "time" +) + +// BoolFlag is a flag with type bool +type BoolFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Destination *bool +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f BoolFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f BoolFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f BoolFlag) IsRequired() bool { + return f.Required +} + +// Bool looks up the value of a local BoolFlag, returns +// false if not found +func (c *Context) Bool(name string) bool { + return lookupBool(name, c.flagSet) +} + +// GlobalBool looks up the value of a global BoolFlag, returns +// false if not found +func (c *Context) GlobalBool(name string) bool { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupBool(name, fs) + } + return false +} + +func lookupBool(name string, set *flag.FlagSet) bool { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseBool(f.Value.String()) + if err != nil { + return false + } + return parsed + } + return false +} + +// BoolTFlag is a flag with type bool that is true by default +type BoolTFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Destination *bool +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f BoolTFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f BoolTFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f BoolTFlag) IsRequired() bool { + return f.Required +} + +// BoolT looks up the value of a local BoolTFlag, returns +// false if not found +func (c *Context) BoolT(name string) bool { + return lookupBoolT(name, c.flagSet) +} + +// GlobalBoolT looks up the value of a global BoolTFlag, returns +// false if not found +func (c *Context) GlobalBoolT(name string) bool { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupBoolT(name, fs) + } + return false +} + +func lookupBoolT(name string, set *flag.FlagSet) bool { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseBool(f.Value.String()) + if err != nil { + return false + } + return parsed + } + return false +} + +// DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) +type DurationFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value time.Duration + Destination *time.Duration +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f DurationFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f DurationFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f DurationFlag) IsRequired() bool { + return f.Required +} + +// Duration looks up the value of a local DurationFlag, returns +// 0 if not found +func (c *Context) Duration(name string) time.Duration { + return lookupDuration(name, c.flagSet) +} + +// GlobalDuration looks up the value of a global DurationFlag, returns +// 0 if not found +func (c *Context) GlobalDuration(name string) time.Duration { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupDuration(name, fs) + } + return 0 +} + +func lookupDuration(name string, set *flag.FlagSet) time.Duration { + f := set.Lookup(name) + if f != nil { + parsed, err := time.ParseDuration(f.Value.String()) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// Float64Flag is a flag with type float64 +type Float64Flag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value float64 + Destination *float64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Float64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Float64Flag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f Float64Flag) IsRequired() bool { + return f.Required +} + +// Float64 looks up the value of a local Float64Flag, returns +// 0 if not found +func (c *Context) Float64(name string) float64 { + return lookupFloat64(name, c.flagSet) +} + +// GlobalFloat64 looks up the value of a global Float64Flag, returns +// 0 if not found +func (c *Context) GlobalFloat64(name string) float64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupFloat64(name, fs) + } + return 0 +} + +func lookupFloat64(name string, set *flag.FlagSet) float64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseFloat(f.Value.String(), 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// GenericFlag is a flag with type Generic +type GenericFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value Generic +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f GenericFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f GenericFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f GenericFlag) IsRequired() bool { + return f.Required +} + +// Generic looks up the value of a local GenericFlag, returns +// nil if not found +func (c *Context) Generic(name string) interface{} { + return lookupGeneric(name, c.flagSet) +} + +// GlobalGeneric looks up the value of a global GenericFlag, returns +// nil if not found +func (c *Context) GlobalGeneric(name string) interface{} { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupGeneric(name, fs) + } + return nil +} + +func lookupGeneric(name string, set *flag.FlagSet) interface{} { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value, error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Int64Flag is a flag with type int64 +type Int64Flag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value int64 + Destination *int64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Int64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Int64Flag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f Int64Flag) IsRequired() bool { + return f.Required +} + +// Int64 looks up the value of a local Int64Flag, returns +// 0 if not found +func (c *Context) Int64(name string) int64 { + return lookupInt64(name, c.flagSet) +} + +// GlobalInt64 looks up the value of a global Int64Flag, returns +// 0 if not found +func (c *Context) GlobalInt64(name string) int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt64(name, fs) + } + return 0 +} + +func lookupInt64(name string, set *flag.FlagSet) int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// IntFlag is a flag with type int +type IntFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value int + Destination *int +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f IntFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f IntFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f IntFlag) IsRequired() bool { + return f.Required +} + +// Int looks up the value of a local IntFlag, returns +// 0 if not found +func (c *Context) Int(name string) int { + return lookupInt(name, c.flagSet) +} + +// GlobalInt looks up the value of a global IntFlag, returns +// 0 if not found +func (c *Context) GlobalInt(name string) int { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt(name, fs) + } + return 0 +} + +func lookupInt(name string, set *flag.FlagSet) int { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return int(parsed) + } + return 0 +} + +// IntSliceFlag is a flag with type *IntSlice +type IntSliceFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value *IntSlice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f IntSliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f IntSliceFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f IntSliceFlag) IsRequired() bool { + return f.Required +} + +// IntSlice looks up the value of a local IntSliceFlag, returns +// nil if not found +func (c *Context) IntSlice(name string) []int { + return lookupIntSlice(name, c.flagSet) +} + +// GlobalIntSlice looks up the value of a global IntSliceFlag, returns +// nil if not found +func (c *Context) GlobalIntSlice(name string) []int { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupIntSlice(name, fs) + } + return nil +} + +func lookupIntSlice(name string, set *flag.FlagSet) []int { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Int64SliceFlag is a flag with type *Int64Slice +type Int64SliceFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value *Int64Slice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Int64SliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Int64SliceFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f Int64SliceFlag) IsRequired() bool { + return f.Required +} + +// Int64Slice looks up the value of a local Int64SliceFlag, returns +// nil if not found +func (c *Context) Int64Slice(name string) []int64 { + return lookupInt64Slice(name, c.flagSet) +} + +// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns +// nil if not found +func (c *Context) GlobalInt64Slice(name string) []int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupInt64Slice(name, fs) + } + return nil +} + +func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// StringFlag is a flag with type string +type StringFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value string + Destination *string +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f StringFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f StringFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f StringFlag) IsRequired() bool { + return f.Required +} + +// String looks up the value of a local StringFlag, returns +// "" if not found +func (c *Context) String(name string) string { + return lookupString(name, c.flagSet) +} + +// GlobalString looks up the value of a global StringFlag, returns +// "" if not found +func (c *Context) GlobalString(name string) string { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupString(name, fs) + } + return "" +} + +func lookupString(name string, set *flag.FlagSet) string { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value.String(), error(nil) + if err != nil { + return "" + } + return parsed + } + return "" +} + +// StringSliceFlag is a flag with type *StringSlice +type StringSliceFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value *StringSlice +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f StringSliceFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f StringSliceFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f StringSliceFlag) IsRequired() bool { + return f.Required +} + +// StringSlice looks up the value of a local StringSliceFlag, returns +// nil if not found +func (c *Context) StringSlice(name string) []string { + return lookupStringSlice(name, c.flagSet) +} + +// GlobalStringSlice looks up the value of a global StringSliceFlag, returns +// nil if not found +func (c *Context) GlobalStringSlice(name string) []string { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupStringSlice(name, fs) + } + return nil +} + +func lookupStringSlice(name string, set *flag.FlagSet) []string { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} + +// Uint64Flag is a flag with type uint64 +type Uint64Flag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value uint64 + Destination *uint64 +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f Uint64Flag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f Uint64Flag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f Uint64Flag) IsRequired() bool { + return f.Required +} + +// Uint64 looks up the value of a local Uint64Flag, returns +// 0 if not found +func (c *Context) Uint64(name string) uint64 { + return lookupUint64(name, c.flagSet) +} + +// GlobalUint64 looks up the value of a global Uint64Flag, returns +// 0 if not found +func (c *Context) GlobalUint64(name string) uint64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupUint64(name, fs) + } + return 0 +} + +func lookupUint64(name string, set *flag.FlagSet) uint64 { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return parsed + } + return 0 +} + +// UintFlag is a flag with type uint +type UintFlag struct { + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value uint + Destination *uint +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f UintFlag) String() string { + return FlagStringer(f) +} + +// GetName returns the name of the flag +func (f UintFlag) GetName() string { + return f.Name +} + +// IsRequired returns whether or not the flag is required +func (f UintFlag) IsRequired() bool { + return f.Required +} + +// Uint looks up the value of a local UintFlag, returns +// 0 if not found +func (c *Context) Uint(name string) uint { + return lookupUint(name, c.flagSet) +} + +// GlobalUint looks up the value of a global UintFlag, returns +// 0 if not found +func (c *Context) GlobalUint(name string) uint { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookupUint(name, fs) + } + return 0 +} + +func lookupUint(name string, set *flag.FlagSet) uint { + f := set.Lookup(name) + if f != nil { + parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) + if err != nil { + return 0 + } + return uint(parsed) + } + return 0 +} From 826954c97919610e0f4086ab3bcc007ac3326184 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 11:09:34 +0530 Subject: [PATCH 14/31] update app name and remove version --- flag-gen/main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flag-gen/main.go b/flag-gen/main.go index 3e463ff..099a5ff 100644 --- a/flag-gen/main.go +++ b/flag-gen/main.go @@ -32,9 +32,8 @@ type FlagType struct { func main() { app := cli.NewApp() - app.Name = "fg" + app.Name = "flag-generator" app.Usage = "Generate flag type code!" - app.Version = "v0.1.0" app.Action = ActionFunc From b6bfbe97f8430a4dfe05791363719d61cb921793 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 12:16:07 +0530 Subject: [PATCH 15/31] update appveyor to go 1.11, add support for code coverage generation in tests --- .travis.yml | 28 ++++++++++++++++------------ appveyor.yml | 18 +++++++++--------- coverage.sh | 8 ++++++++ runtests | 4 ---- 4 files changed, 33 insertions(+), 25 deletions(-) create mode 100755 coverage.sh diff --git a/.travis.yml b/.travis.yml index 8bb0e9c..75d9ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,23 +5,27 @@ osx_image: xcode8.3 go: 1.11.x os: -- linux -- osx + - linux + - osx cache: directories: - - node_modules + - node_modules before_script: -- go get github.com/urfave/gfmrun/... || true -- go get golang.org/x/tools/cmd/goimports -- if [ ! -f node_modules/.bin/markdown-toc ] ; then + - go get github.com/urfave/gfmrun/... || true + - go get golang.org/x/tools/cmd/goimports + - if [ ! -f node_modules/.bin/markdown-toc ] ; then npm install markdown-toc ; - fi + fi script: -- ./runtests gen -- ./runtests vet -- ./runtests test -- ./runtests gfmrun -- ./runtests toc + - ./runtests gen + - ./runtests vet + - ./runtests test + - ./runtests gfmrun + - ./runtests toc + +after_success: + - ./coverage.sh + - bash <(curl -s https://codecov.io/bash) diff --git a/appveyor.yml b/appveyor.yml index 1e1489c..f841e61 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,19 +8,19 @@ clone_folder: c:\gopath\src\github.com\urfave\cli environment: GOPATH: C:\gopath - GOVERSION: 1.8.x + GOVERSION: 1.11.x PYTHON: C:\Python36-x64 PYTHON_VERSION: 3.6.x PYTHON_ARCH: 64 install: -- set PATH=%GOPATH%\bin;C:\go\bin;%PATH% -- go version -- go env -- go get github.com/urfave/gfmrun/... -- go get -v -t ./... + - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% + - go version + - go env + - go get github.com/urfave/gfmrun/... + - go get -v -t ./... build_script: -- python runtests vet -- python runtests test -- python runtests gfmrun + - python runtests vet + - python runtests test + - python runtests gfmrun diff --git a/coverage.sh b/coverage.sh new file mode 100755 index 0000000..03c720c --- /dev/null +++ b/coverage.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e +echo "" > coverage.txt + +for f in $(ls *.coverprofile); do + cat $f >> coverage.txt + rm $f +done \ No newline at end of file diff --git a/runtests b/runtests index ee22bde..80d225a 100755 --- a/runtests +++ b/runtests @@ -34,10 +34,6 @@ def main(sysargs=sys.argv[:]): def _test(): - if check_output('go version'.split()).split()[2] < 'go1.2': - _run('go test -v .') - return - coverprofiles = [] for subpackage in ['', 'altsrc']: coverprofile = 'cli.coverprofile' From 365557021fe254d059d0f7065bb0c94686208723 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 12:17:27 +0530 Subject: [PATCH 16/31] remove legacy version check code --- runtests | 9 --------- 1 file changed, 9 deletions(-) diff --git a/runtests b/runtests index 80d225a..b073dc2 100755 --- a/runtests +++ b/runtests @@ -53,10 +53,6 @@ def _test(): def _gfmrun(): - go_version = check_output('go version'.split()).split()[2] - if go_version < 'go1.3': - print('runtests: skip on {}'.format(go_version), file=sys.stderr) - return _run(['gfmrun', '-c', str(_gfmrun_count()), '-s', 'README.md']) @@ -70,11 +66,6 @@ def _toc(): def _gen(): - go_version = check_output('go version'.split()).split()[2] - if go_version < 'go1.5': - print('runtests: skip on {}'.format(go_version), file=sys.stderr) - return - _run('go generate ./...') _run('git diff --exit-code') From fb4cea5f30995b6caaa700ea789902af499d63b2 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 12:22:45 +0530 Subject: [PATCH 17/31] add new generation logic to travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 75d9ea3..ad53098 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ cache: - node_modules before_script: + - go get github.com/urfave/cli/flag-gen || true - go get github.com/urfave/gfmrun/... || true - go get golang.org/x/tools/cmd/goimports - if [ ! -f node_modules/.bin/markdown-toc ] ; then @@ -20,7 +21,7 @@ before_script: fi script: - - ./runtests gen + - go generate ./... - ./runtests vet - ./runtests test - ./runtests gfmrun From 4b0a4104630bddd01a7a6c5aa8a70dc94642ab52 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 12:26:48 +0530 Subject: [PATCH 18/31] fix travis build --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ad53098..33b8a1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ cache: before_script: - go get github.com/urfave/cli/flag-gen || true + - go get github.com/shurcooL/vfsgen || true + - go get github.com/shurcooL/httpfs/union || true - go get github.com/urfave/gfmrun/... || true - go get golang.org/x/tools/cmd/goimports - if [ ! -f node_modules/.bin/markdown-toc ] ; then @@ -21,7 +23,7 @@ before_script: fi script: - - go generate ./... + #- go generate ./... # to be uncommented after merge as we cannot compile the package which is not present in master - ./runtests vet - ./runtests test - ./runtests gfmrun From 8547458f1d93654348b3bbeccb6d04424d5eab3e Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 19:01:47 +0530 Subject: [PATCH 19/31] remove zero mod fs --- flag-gen/assets_generate.go | 42 ++++++------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/flag-gen/assets_generate.go b/flag-gen/assets_generate.go index b587253..c3847d6 100644 --- a/flag-gen/assets_generate.go +++ b/flag-gen/assets_generate.go @@ -7,45 +7,15 @@ import ( "github.com/shurcooL/vfsgen" "log" "net/http" - "os" - "time" ) -// zeroModTimeFileSystem is an http.FileSystem wrapper. -// It exposes a filesystem exactly like Source, except -// all file modification times are changed to zero. -// See https://github.com/shurcooL/vfsgen/pull/40#issuecomment-355416103 -type zeroModTimeFileSystem struct { - Source http.FileSystem -} - -func (fs zeroModTimeFileSystem) Open(name string) (http.File, error) { - f, err := fs.Source.Open(name) - return file{f}, err -} - -type file struct { - http.File -} - -func (f file) Stat() (os.FileInfo, error) { - fi, err := f.File.Stat() - return fileInfo{fi}, err -} - -type fileInfo struct { - os.FileInfo -} - -func (fi fileInfo) ModTime() time.Time { return time.Time{} } - func main() { - err := vfsgen.Generate(zeroModTimeFileSystem{ - Source: union.New(map[string]http.FileSystem{ - "/templates": http.Dir("templates"), - "/source": http.Dir("source"), - }), - }, vfsgen.Options{}) + fs := union.New(map[string]http.FileSystem{ + "/templates": http.Dir("templates"), + "/source": http.Dir("source"), + }) + + err := vfsgen.Generate(fs, vfsgen.Options{}) if err != nil { log.Fatal(err) From 58ae5eb590667b0115d3f82e03593d87e2924b1c Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 20:06:44 +0530 Subject: [PATCH 20/31] move entire build system to go --- .travis.yml | 12 ++- appveyor.yml | 12 +-- build/build.go | 179 +++++++++++++++++++++++++++++++++++++ cli.go | 2 +- coverage.sh | 8 -- flag-gen/assets_vfsdata.go | 14 +-- flag-gen/main.go | 4 +- go.mod | 2 + go.sum | 4 + 9 files changed, 206 insertions(+), 31 deletions(-) create mode 100644 build/build.go delete mode 100755 coverage.sh diff --git a/.travis.yml b/.travis.yml index 33b8a1f..20f3a58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ cache: - node_modules before_script: - - go get github.com/urfave/cli/flag-gen || true - go get github.com/shurcooL/vfsgen || true - go get github.com/shurcooL/httpfs/union || true - go get github.com/urfave/gfmrun/... || true @@ -23,12 +22,11 @@ before_script: fi script: - #- go generate ./... # to be uncommented after merge as we cannot compile the package which is not present in master - - ./runtests vet - - ./runtests test - - ./runtests gfmrun - - ./runtests toc + - go run build/build.go generate + - go run build/build.go vet + - go run build/build.go test + - go run build/build.go gfmrun + - go run build/build.go toc after_success: - - ./coverage.sh - bash <(curl -s https://codecov.io/bash) diff --git a/appveyor.yml b/appveyor.yml index f841e61..39c6aac 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,18 +9,18 @@ clone_folder: c:\gopath\src\github.com\urfave\cli environment: GOPATH: C:\gopath GOVERSION: 1.11.x - PYTHON: C:\Python36-x64 - PYTHON_VERSION: 3.6.x - PYTHON_ARCH: 64 install: - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% - go version - go env + - go get github.com/shurcooL/vfsgen + - go get github.com/shurcooL/httpfs/union - go get github.com/urfave/gfmrun/... - go get -v -t ./... build_script: - - python runtests vet - - python runtests test - - python runtests gfmrun + - go run build/build.go generate + - go rub build/build.go vet + - go rub build/build.go test + - go rub build/build.go gfmrun diff --git a/build/build.go b/build/build.go new file mode 100644 index 0000000..b83a8e0 --- /dev/null +++ b/build/build.go @@ -0,0 +1,179 @@ +package main + +import ( + "bufio" + "bytes" + "fmt" + "github.com/urfave/cli" + "io/ioutil" + "log" + "os" + "os/exec" + "strings" +) + +var packages []string + +func main() { + app := cli.NewApp() + + app.Name = "builder" + app.Usage = "Generates a new urfave/cli build!" + + app.Commands = cli.Commands{ + cli.Command{ + Name: "vet", + Action: VetActionFunc, + }, + cli.Command{ + Name: "test", + Action: TestActionFunc, + }, + cli.Command{ + Name: "gfmrun", + Action: GfmrunActionFunc, + }, + cli.Command{ + Name: "toc", + Action: TocActionFunc, + }, + cli.Command{ + Name: "generate", + Action: GenActionFunc, + }, + } + + packages = []string{"cli", "altsrc"} + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} + +func VetActionFunc(_ *cli.Context) error { + return exec.Command("go", "vet").Run() +} + +func TestActionFunc(c *cli.Context) error { + for _, pkg := range packages { + var packageName string + + if pkg == "cli" { + packageName = fmt.Sprintf("github.com/urfave/cli") + } else { + packageName = fmt.Sprintf("github.com/urfave/cli/%s", pkg) + } + + coverProfile := fmt.Sprintf("--coverprofile=%s.coverprofile", pkg) + + err := exec.Command( + "go", "test", "-v", coverProfile, packageName, + ).Run() + + if err != nil { + return err + } + } + + return testCleanup() +} + +func testCleanup() error { + var out bytes.Buffer + + for _, pkg := range packages { + file, err := os.Open(fmt.Sprintf("%s.coverprofile", pkg)) + if err != nil { + return err + } + + b, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + out.Write(b) + err = file.Close() + if err != nil { + return err + } + + err = os.Remove(fmt.Sprintf("%s.coverprofile", pkg)) + if err != nil { + return err + } + } + + outFile, err := os.Create("coverage.txt") + if err != nil { + return err + } + + _, err = out.WriteTo(outFile) + if err != nil { + return err + } + + err = outFile.Close() + if err != nil { + return err + } + + return nil +} + +func GfmrunActionFunc(_ *cli.Context) error { + file, err := os.Open("README.md") + if err != nil { + return err + } + + var counter int + scanner := bufio.NewScanner(file) + for scanner.Scan() { + if strings.Contains(scanner.Text(), "package main") { + counter++ + } + } + + err = scanner.Err() + if err != nil { + return err + } + + return exec.Command("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md").Run() +} + +func TocActionFunc(_ *cli.Context) error { + err := exec.Command("node_modules/.bin/markdown-toc", "-i", "README.md").Run() + if err != nil { + return err + } + + err = exec.Command("git", "diff", "--exit-code").Run() + if err != nil { + return err + } + + return nil +} + +func GenActionFunc(_ *cli.Context) error { + err := exec.Command("go", "generate", "flag-gen/main.go").Run() + if err != nil { + return err + } + + err = exec.Command("go", "generate", "cli.go").Run() + if err != nil { + return err + } + + err = exec.Command("git", "diff", "--exit-code").Run() + if err != nil { + return err + } + + return nil +} diff --git a/cli.go b/cli.go index 80d4357..4bd2508 100644 --- a/cli.go +++ b/cli.go @@ -19,4 +19,4 @@ // } package cli -//go:generate flag-generator +//go:generate go run flag-gen/main.go flag-gen/assets_vfsdata.go diff --git a/coverage.sh b/coverage.sh deleted file mode 100755 index 03c720c..0000000 --- a/coverage.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -e -echo "" > coverage.txt - -for f in $(ls *.coverprofile); do - cat $f >> coverage.txt - rm $f -done \ No newline at end of file diff --git a/flag-gen/assets_vfsdata.go b/flag-gen/assets_vfsdata.go index 4b89ce3..c98c71d 100644 --- a/flag-gen/assets_vfsdata.go +++ b/flag-gen/assets_vfsdata.go @@ -23,29 +23,29 @@ var assets = func() http.FileSystem { }, "/source": &vfsgen۰DirInfo{ name: "source", - modTime: time.Time{}, + modTime: time.Date(2019, 8, 4, 4, 7, 51, 386498815, time.UTC), }, "/source/flag-types.json": &vfsgen۰CompressedFileInfo{ name: "flag-types.json", - modTime: time.Time{}, + modTime: time.Date(2019, 8, 4, 2, 47, 4, 104288603, time.UTC), uncompressedSize: 2559, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x94\xc1\x6e\x9c\x30\x10\x86\xef\x3c\xc5\xc8\xbd\x40\xb5\x82\x1c\x56\x7b\xd8\x63\x55\xb5\xda\x5b\xa5\x34\xbd\x24\x51\xe4\x80\x21\x56\x1d\x1b\xd9\x43\xd4\x28\xca\xbb\x57\xf6\x2e\xbb\x60\x0c\x62\x5b\x2d\xb9\xfe\x23\x98\xef\x9b\xb1\xe6\x36\x02\x78\x8b\x00\x00\x88\xa4\xcf\x8c\x6c\x81\x7c\x51\x4a\x90\xd5\x3e\xc3\xd7\xda\x65\x8f\x9d\xec\x85\x8a\xc6\x86\x25\x15\x86\x1d\xb2\x82\x19\x24\x5b\x40\xdd\xb4\x49\xae\x24\xb2\x3f\xf8\x50\xb0\x92\x36\xc2\x16\x89\xfb\xa0\xfd\x4b\x4d\xb5\x61\xda\xc6\x06\x75\xae\xe4\x4b\xfa\xc3\x26\xb6\x79\x5c\xa6\xbf\x6c\x8f\xf4\x1a\x35\x97\x55\x9c\x24\x24\x02\x78\x5f\x85\x51\x7f\xfe\x3f\x6b\xa1\x72\xa4\x5c\xd8\x8f\x01\x9f\x28\x02\x37\xae\x0c\x8f\xaf\xd0\xf2\x2f\xa9\xf5\xb5\xd1\x14\xb9\x92\xbe\x19\xf2\x67\x96\xfa\xc5\x56\xb1\xeb\x33\x69\x18\x1b\xc6\xe0\x09\xb1\x36\xdb\x2c\xab\x94\xa0\xb2\x4a\x95\xae\xb2\xfa\x77\x95\xd9\x0e\xd9\x27\x87\xdc\xf6\x49\x26\xd4\xaf\x86\xda\x8e\xb1\xf7\x83\xf9\xde\xdf\x84\xa2\xb8\x59\xfb\xda\x65\x3f\x9e\x25\x3c\x0f\xb6\xb7\x23\xd7\x7d\x00\xbb\x82\xcd\x7a\x14\xf8\x3b\x93\x4c\xf3\xdc\x07\xf6\xe2\x71\xe0\xee\xb3\x0c\x10\x4b\x2e\xfc\xe1\xb7\x2d\xb8\x44\xa6\x4b\x9a\xb3\xb7\xf7\x31\xb8\x9d\x0c\xcc\x92\xcb\x05\x26\xb9\x93\xa1\x39\x5e\x4d\x8e\x72\x27\x31\xc0\xfa\xa1\xa4\xbd\x4f\x1f\x72\xea\xfa\x59\xaa\xd8\x45\xc5\x94\xcb\xb5\xe0\x39\xf3\x85\x3e\xfb\x85\x4b\xbc\x8c\xdb\xfb\xce\xdc\x4e\xda\x47\xcd\xf8\x48\x91\x24\xfb\xc8\x2a\x33\xad\x95\x8e\x25\x17\x53\x52\x9b\xf5\xa8\x96\x57\xba\x98\xd8\xe9\xf1\x8e\xa9\x1d\x48\xce\x93\xdb\xef\xde\x17\x33\xbd\xf4\x5f\xdf\xe0\x1d\xb9\x23\x43\xe8\xe1\xab\x9b\x4b\x19\xde\x41\xa0\x76\x99\x25\xf4\x87\x12\xdc\x42\x87\xe5\xbc\x35\xdc\xf0\xd0\xcd\x6a\x16\x39\x5a\xb6\xf7\xd9\x57\xeb\x86\x0f\xcf\x56\xb3\xc0\xdd\x9a\x86\x0d\x1f\xae\xc6\xbf\x5c\xd1\x7d\xf4\x37\x00\x00\xff\xff\x66\x52\x85\x44\xff\x09\x00\x00"), }, "/templates": &vfsgen۰DirInfo{ name: "templates", - modTime: time.Time{}, + modTime: time.Date(2019, 8, 4, 5, 32, 59, 292856915, time.UTC), }, "/templates/altsrc_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "altsrc_flags_generated.gotpl", - modTime: time.Time{}, - uncompressedSize: 1063, + modTime: time.Date(2019, 8, 4, 5, 32, 59, 176187795, time.UTC), + uncompressedSize: 1062, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x41\x8b\xdb\x30\x10\x85\xcf\xab\x5f\xf1\x08\x4b\x89\x97\x60\xdf\x53\xf6\x50\xba\x5b\xe8\x25\x5b\xd8\x85\x9e\x15\x7b\x64\x8b\x2a\xb6\x91\xc6\x09\x41\xf8\xbf\x97\x91\x97\x34\xa5\x4a\xe9\xa5\x37\x59\xa3\xf7\xde\x7c\x33\xae\x2a\x7c\x1e\x1a\x42\x4b\x3d\x79\xcd\xd4\x60\x7f\x86\x69\x3f\xe2\xe9\x05\xbb\x97\x37\x3c\x3f\x7d\x7d\x2b\x95\x1a\x75\xfd\x43\xb7\x84\x18\x51\x7e\x5b\xce\x3b\x7d\x20\xcc\xb3\x52\xf6\x30\x0e\x9e\xb1\x56\x77\x2b\xe3\x74\xbb\x52\x00\xb0\x6a\x2d\x77\xd3\xbe\xac\x87\x43\x35\x79\xa3\x8f\x54\xd5\xce\xae\x54\xa1\x54\x8c\xf0\xba\x6f\x09\xf7\x76\x83\x7b\x91\x60\xfb\x88\xf2\x8b\xd3\x6d\x10\xc3\xaa\x92\x98\x54\x28\xdf\x43\xa4\x06\x1b\xc0\x1d\x21\x09\xf8\x3c\x12\xb8\xd3\x8c\x93\xd7\x63\x40\xed\x6c\x99\x15\xf1\x00\xed\xdc\x70\x12\x57\x33\x78\x0c\xdc\x91\xc7\x51\xbb\x89\x82\x14\xf7\x84\x30\x52\x6d\x8d\xa5\x46\x25\xd7\xac\x4d\x60\x3f\xd5\x8c\x98\xd8\x6e\x85\xa5\x62\x20\xc6\x43\xaa\xc8\xd5\x2b\xb1\x9a\x95\x84\xef\xe8\x94\x75\xae\x3d\x69\xa6\x00\x8d\x9e\x4e\xd9\x70\x65\xa6\xbe\xbe\xa5\x5f\x1b\x77\xb3\x9f\x02\x0f\xd9\xc8\x85\xc2\x13\x4f\xbe\xc7\x87\xdc\x93\x98\x6d\x64\x0b\xe3\x36\x02\xb8\x45\x6f\x1d\xe6\x77\xb2\x4f\xe3\xe8\xce\x08\xfa\x48\xbf\x16\xf4\x4a\x9c\xc6\xed\x34\x93\xc7\x14\xe4\xdf\xa9\xb5\x73\x61\x23\x4f\xfa\xe5\x2c\x62\x11\xc8\x0a\x47\x6a\xb2\x99\x65\x72\x5f\x46\xb0\x36\x79\xa0\x62\x69\x61\xfd\xc7\xe8\x0b\x44\x75\x67\x4a\xb9\x7f\x94\xbe\xe5\xe3\x76\x88\xe8\x8b\x6b\xa6\xef\x96\xbb\x67\xef\x07\xff\x7f\xe1\x2e\x31\xff\x44\x79\x79\x9d\xc3\xa5\xd4\xed\xb2\xdf\x6b\xee\xab\x7d\xff\x6d\x02\xbf\x79\xcb\x28\x62\x04\xf5\x0d\xe6\xf9\x67\x00\x00\x00\xff\xff\x1d\x0d\x69\x06\x27\x04\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x41\x8b\xdb\x30\x10\x85\xcf\xab\x5f\xf1\x08\x4b\x89\x97\x60\xdf\x53\xf6\x50\xba\x5b\xe8\x25\x5b\xd8\x85\x9e\x15\x7b\x64\x8b\x2a\xb6\x91\xc6\x09\x41\xf8\xbf\x97\x91\x97\x34\xa5\x4a\xe9\xa5\x37\x59\xa3\xf7\xde\x7c\x33\xae\x2a\x7c\x1e\x1a\x42\x4b\x3d\x79\xcd\xd4\x60\x7f\x86\x69\x3f\xe2\xe9\x05\xbb\x97\x37\x3c\x3f\x7d\x7d\x2b\x95\x1a\x75\xfd\x43\xb7\x84\x18\x51\x7e\x5b\xce\x3b\x7d\x20\xcc\xb3\x52\xf6\x30\x0e\x9e\xb1\x56\x77\x2b\xe3\x74\xbb\x52\x00\xb0\x6a\x2d\x77\xd3\xbe\xac\x87\x43\x35\x79\xa3\x8f\x54\xd5\xce\xae\x54\xa1\x62\x84\xd7\x7d\x4b\xb8\xb7\x1b\xdc\x8b\x02\xdb\x47\x94\x5f\x9c\x6e\x83\xf8\x55\x95\xa4\xa4\x42\xf9\x9e\x21\x35\xd8\x00\xee\x08\x49\xc0\xe7\x91\xc0\x9d\x66\x9c\xbc\x1e\x03\x6a\x67\xcb\xac\x88\x07\x68\xe7\x86\x93\xb8\x9a\xc1\x63\xe0\x8e\x3c\x8e\xda\x4d\x14\xa4\xb8\x27\x84\x91\x6a\x6b\x2c\x35\x2a\xb9\x66\x6d\x02\xfb\xa9\x66\xc4\x84\x76\x2b\x2c\x15\x03\x31\x1e\x52\x45\xae\x5e\x89\xd5\xac\x24\x7c\x47\xa7\xac\x73\xed\x49\x33\x05\x68\xf4\x74\xca\x86\x2b\x33\xf5\xf5\x2d\xfd\xda\xb8\x9b\xfd\x14\x78\xc8\x46\x2e\x14\x9e\x78\xf2\x3d\x3e\xe4\x9e\xc4\x6c\x23\x5b\x18\xb7\x11\xc0\x2d\x7a\xeb\x30\xbf\x93\x7d\x1a\x47\x77\x46\xd0\x47\xfa\xb5\xa0\x57\xe2\x34\x6e\xa7\x99\x3c\xa6\x20\xbf\x4e\xad\x9d\x0b\x1b\x79\xd2\x2f\x67\x11\x8b\x40\x56\x38\x52\x93\xcd\x2c\x93\xfb\x32\x82\xb5\xc9\x03\x15\x4b\x0b\xeb\x3f\x46\x5f\x20\xaa\x3b\x53\xca\xfd\xa3\xf4\x2d\x1f\xb7\x43\x44\x5f\x5c\x33\x7d\xb7\xdc\x3d\x7b\x3f\xf8\xff\x0b\x77\x89\xf9\x27\xca\xcb\xeb\x1c\x2e\xa5\x6e\x97\xfd\x5e\x73\x5f\xed\xfb\x6f\x13\xf8\xcd\x5b\x46\x11\x23\xa8\x6f\x30\xcf\x3f\x03\x00\x00\xff\xff\xb0\x66\x7b\xfe\x26\x04\x00\x00"), }, "/templates/cli_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "cli_flags_generated.gotpl", - modTime: time.Time{}, + modTime: time.Date(2019, 8, 4, 5, 32, 38, 55742173, time.UTC), uncompressedSize: 2230, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\x41\x4f\xeb\x38\x10\x3e\x37\xbf\x62\xb6\xe2\x90\xa0\x6e\x7b\x5f\xc4\x89\xc2\x2e\xd2\x0a\xd0\x83\xc7\xdd\x4d\xc6\xa9\x85\xb1\x8b\xed\xc0\x43\x51\xff\xfb\xd3\x8c\x9d\xb4\x4d\x0b\xf4\xc2\xeb\xc9\x9e\xf9\xfc\xcd\x37\xdf\x8c\x9a\xd9\x0c\x2e\x6c\x85\x50\xa3\x41\x27\x02\x56\xb0\x78\x07\x59\x9f\xc1\xfc\x16\x6e\x6e\x1f\xe0\x72\x7e\xfd\x30\xcd\xb2\x95\x28\x9f\x44\x8d\xd0\xb6\x30\xbd\x8b\xe7\x1b\xf1\x8c\xb0\x5e\x67\x99\x7a\x5e\x59\x17\x20\xcf\x46\x63\xa9\x45\x3d\xce\x46\x63\x1f\x5c\x69\xcd\x2b\x1d\x83\x7a\xc6\x71\x56\x64\x6d\x0b\x4e\x98\x1a\xe1\x44\x4d\xe0\x84\x80\xf0\xcf\x39\x4c\xaf\xb4\xa8\x3d\xd1\xcc\x66\x44\xce\x89\x69\xa2\xa6\x1c\x28\x0f\x02\x18\xfe\xa6\xc2\x12\xc2\xfb\x0a\x37\xc0\x07\xba\xad\xd7\xfd\x7d\x6e\xcb\x20\x94\x26\xbe\x5d\xe0\x36\xa3\x0f\xae\x29\x03\xb4\x19\x00\x00\x27\xd2\xcf\x07\xa7\x4c\xcd\xe1\x9f\x9e\xba\xdd\x0b\x5f\x9a\xd7\x47\xe1\xf6\xc2\x57\x4a\xe3\x9d\x08\xcb\x41\xf8\x07\xbe\x34\xca\x61\x45\xe7\x85\xb5\x9a\x83\xff\xa9\xaa\x42\x13\x29\xfa\x60\xdb\xfe\x0d\x4a\x02\xbe\x24\xb9\x8f\x42\x37\x08\xc1\x35\xec\xf0\x88\xaf\xa3\xd1\xb0\xed\x6c\x44\xef\xd0\x54\xfd\x79\x9b\x63\x8e\x3e\x28\x23\x82\xb2\x66\xc3\xb4\x15\x1c\x9d\x7e\xca\xb7\xce\x68\x24\xf7\xdc\x0d\x38\x0c\x8d\x33\x34\x09\x87\xa2\x12\x0b\x8d\xe0\x70\xe5\xd0\xa3\x09\xb1\x82\x95\x10\x96\xca\xc3\x2b\x49\xa5\x97\xb9\xb4\x0e\x1a\xb6\xb1\x42\x29\x1a\x1d\x7c\x91\xc9\xc6\x94\x90\xcb\x83\x73\x29\x52\xb1\xbc\x48\x1e\xa6\x09\xc5\xda\x40\x90\x08\x40\x97\xcb\x22\xe9\xfb\x17\x03\x53\x74\x02\xc3\x12\xc1\x50\x80\xf5\x20\x2f\xce\x17\x55\x13\xc5\x07\x65\x25\x83\x53\xb5\x6b\xdf\x8f\xb4\x2b\xf8\xb6\xc4\xb0\x44\x07\xd6\x81\xb1\xa1\xaf\x49\x6b\xeb\x12\xf6\x8b\xfa\x1b\xd2\xbc\xe0\x8d\x18\x0a\xe8\xd2\x49\xc4\x90\x05\xb4\xb5\x4f\x1e\x9a\x15\x17\x67\xff\xa9\x7b\x01\xda\x96\x42\x1f\x2c\x3a\xe9\xe4\xef\xf0\x5d\x58\x13\xf0\x57\x98\xc7\x69\x11\xb3\x92\xdc\x94\xb4\x8d\xe9\xba\x28\xe1\x34\xe1\x8a\x3d\xea\x9c\x9d\x8f\x2e\x16\x6d\xcb\xcf\x11\x3a\x5e\x5e\xb2\xf1\x98\x78\x87\x25\xd3\xfe\x51\x1c\xb5\xc7\x1d\xc8\x26\xd7\xad\xe6\xae\x3f\xd4\x7d\xb3\x3a\x28\x65\x02\xe5\x94\x82\xf7\x18\xfa\x7d\xd1\x76\x21\xf4\xd1\x16\xd6\x0c\xff\x4e\x0f\x0f\x0b\xfa\xb3\x4e\x2a\x09\xd2\xd3\xbf\x71\xf4\x32\x4a\xba\x8a\xc6\x75\x46\x16\x67\x84\xf9\xeb\x1c\x8c\xea\x16\xf4\xd8\x21\x48\x5f\x30\x7e\xbd\x3d\xb6\x8f\x1d\xa3\x49\xb1\x4f\x9f\x90\x26\x6b\x26\xe0\x31\xc0\x29\xa7\x93\xde\xef\x77\x4b\x92\x53\x1e\xc3\xf4\x7f\xd6\xc7\x7a\x8a\xde\xc7\x7d\x8b\x36\x82\xee\x84\xf3\xe8\xa2\x96\x15\x9d\xab\x09\xa0\x73\xc4\xd7\x97\x4d\x18\xfe\xa6\x25\x4d\x03\xa8\x8c\x5f\x07\xbe\x5b\x97\x1b\xa5\xa9\xe7\xf4\xaf\xdd\x15\xa5\x0f\x81\x73\xfb\x62\x8e\x9b\x40\x87\x5c\x7f\xd8\xc4\x85\xf0\x21\x36\x32\x64\xdb\xca\x6f\x37\x91\x60\xb1\x97\x5d\xbd\xc7\xef\x45\xff\xee\x77\x00\x00\x00\xff\xff\x4d\xaf\x90\xd0\xb6\x08\x00\x00"), diff --git a/flag-gen/main.go b/flag-gen/main.go index 099a5ff..9caa94e 100644 --- a/flag-gen/main.go +++ b/flag-gen/main.go @@ -1,7 +1,7 @@ -//go:generate go run assets_generate.go - package main +//go:generate go run assets_generate.go + import ( "encoding/json" "fmt" diff --git a/go.mod b/go.mod index d5b55c4..31f39cc 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,7 @@ go 1.12 require ( github.com/BurntSushi/toml v0.3.1 + github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect + github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index a2ea702..f3cb3d0 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,9 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= +github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0= +github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= From 7a6f3d4394003447c99b223ce1c1e19e23b20124 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 20:23:32 +0530 Subject: [PATCH 21/31] fix tests --- altsrc/flag_generated.go | 26 +-- appveyor.yml | 6 +- flag-gen/assets_vfsdata.go | 14 +- .../templates/altsrc_flags_generated.gotpl | 12 +- flag-gen/templates/cli_flags_generated.gotpl | 56 ++--- flag_generated.go | 196 +++++++++--------- 6 files changed, 155 insertions(+), 155 deletions(-) diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go index 0c45914..e568872 100644 --- a/altsrc/flag_generated.go +++ b/altsrc/flag_generated.go @@ -16,7 +16,7 @@ type BoolFlag struct { // NewBoolFlag creates a new BoolFlag func NewBoolFlag(fl cli.BoolFlag) *BoolFlag { - return &BoolFlag{BoolFlag: fl, set: nil} + return &BoolFlag{ BoolFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -42,7 +42,7 @@ type BoolTFlag struct { // NewBoolTFlag creates a new BoolTFlag func NewBoolTFlag(fl cli.BoolTFlag) *BoolTFlag { - return &BoolTFlag{BoolTFlag: fl, set: nil} + return &BoolTFlag{ BoolTFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -68,7 +68,7 @@ type DurationFlag struct { // NewDurationFlag creates a new DurationFlag func NewDurationFlag(fl cli.DurationFlag) *DurationFlag { - return &DurationFlag{DurationFlag: fl, set: nil} + return &DurationFlag{ DurationFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -94,7 +94,7 @@ type Float64Flag struct { // NewFloat64Flag creates a new Float64Flag func NewFloat64Flag(fl cli.Float64Flag) *Float64Flag { - return &Float64Flag{Float64Flag: fl, set: nil} + return &Float64Flag{ Float64Flag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -120,7 +120,7 @@ type GenericFlag struct { // NewGenericFlag creates a new GenericFlag func NewGenericFlag(fl cli.GenericFlag) *GenericFlag { - return &GenericFlag{GenericFlag: fl, set: nil} + return &GenericFlag{ GenericFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -146,7 +146,7 @@ type Int64Flag struct { // NewInt64Flag creates a new Int64Flag func NewInt64Flag(fl cli.Int64Flag) *Int64Flag { - return &Int64Flag{Int64Flag: fl, set: nil} + return &Int64Flag{ Int64Flag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -172,7 +172,7 @@ type IntFlag struct { // NewIntFlag creates a new IntFlag func NewIntFlag(fl cli.IntFlag) *IntFlag { - return &IntFlag{IntFlag: fl, set: nil} + return &IntFlag{ IntFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -198,7 +198,7 @@ type IntSliceFlag struct { // NewIntSliceFlag creates a new IntSliceFlag func NewIntSliceFlag(fl cli.IntSliceFlag) *IntSliceFlag { - return &IntSliceFlag{IntSliceFlag: fl, set: nil} + return &IntSliceFlag{ IntSliceFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -224,7 +224,7 @@ type Int64SliceFlag struct { // NewInt64SliceFlag creates a new Int64SliceFlag func NewInt64SliceFlag(fl cli.Int64SliceFlag) *Int64SliceFlag { - return &Int64SliceFlag{Int64SliceFlag: fl, set: nil} + return &Int64SliceFlag{ Int64SliceFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -250,7 +250,7 @@ type StringFlag struct { // NewStringFlag creates a new StringFlag func NewStringFlag(fl cli.StringFlag) *StringFlag { - return &StringFlag{StringFlag: fl, set: nil} + return &StringFlag{ StringFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -276,7 +276,7 @@ type StringSliceFlag struct { // NewStringSliceFlag creates a new StringSliceFlag func NewStringSliceFlag(fl cli.StringSliceFlag) *StringSliceFlag { - return &StringSliceFlag{StringSliceFlag: fl, set: nil} + return &StringSliceFlag{ StringSliceFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -302,7 +302,7 @@ type Uint64Flag struct { // NewUint64Flag creates a new Uint64Flag func NewUint64Flag(fl cli.Uint64Flag) *Uint64Flag { - return &Uint64Flag{Uint64Flag: fl, set: nil} + return &Uint64Flag{ Uint64Flag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -328,7 +328,7 @@ type UintFlag struct { // NewUintFlag creates a new UintFlag func NewUintFlag(fl cli.UintFlag) *UintFlag { - return &UintFlag{UintFlag: fl, set: nil} + return &UintFlag{ UintFlag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls diff --git a/appveyor.yml b/appveyor.yml index 39c6aac..6e4806b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,6 +21,6 @@ install: build_script: - go run build/build.go generate - - go rub build/build.go vet - - go rub build/build.go test - - go rub build/build.go gfmrun + - go run build/build.go vet + - go run build/build.go test + - go run build/build.go gfmrun diff --git a/flag-gen/assets_vfsdata.go b/flag-gen/assets_vfsdata.go index c98c71d..f5fd185 100644 --- a/flag-gen/assets_vfsdata.go +++ b/flag-gen/assets_vfsdata.go @@ -34,21 +34,21 @@ var assets = func() http.FileSystem { }, "/templates": &vfsgen۰DirInfo{ name: "templates", - modTime: time.Date(2019, 8, 4, 5, 32, 59, 292856915, time.UTC), + modTime: time.Date(2019, 8, 4, 14, 51, 15, 358024804, time.UTC), }, "/templates/altsrc_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "altsrc_flags_generated.gotpl", - modTime: time.Date(2019, 8, 4, 5, 32, 59, 176187795, time.UTC), - uncompressedSize: 1062, + modTime: time.Date(2019, 8, 4, 14, 47, 17, 700754849, time.UTC), + uncompressedSize: 1044, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x41\x8b\xdb\x30\x10\x85\xcf\xab\x5f\xf1\x08\x4b\x89\x97\x60\xdf\x53\xf6\x50\xba\x5b\xe8\x25\x5b\xd8\x85\x9e\x15\x7b\x64\x8b\x2a\xb6\x91\xc6\x09\x41\xf8\xbf\x97\x91\x97\x34\xa5\x4a\xe9\xa5\x37\x59\xa3\xf7\xde\x7c\x33\xae\x2a\x7c\x1e\x1a\x42\x4b\x3d\x79\xcd\xd4\x60\x7f\x86\x69\x3f\xe2\xe9\x05\xbb\x97\x37\x3c\x3f\x7d\x7d\x2b\x95\x1a\x75\xfd\x43\xb7\x84\x18\x51\x7e\x5b\xce\x3b\x7d\x20\xcc\xb3\x52\xf6\x30\x0e\x9e\xb1\x56\x77\x2b\xe3\x74\xbb\x52\x00\xb0\x6a\x2d\x77\xd3\xbe\xac\x87\x43\x35\x79\xa3\x8f\x54\xd5\xce\xae\x54\xa1\x62\x84\xd7\x7d\x4b\xb8\xb7\x1b\xdc\x8b\x02\xdb\x47\x94\x5f\x9c\x6e\x83\xf8\x55\x95\xa4\xa4\x42\xf9\x9e\x21\x35\xd8\x00\xee\x08\x49\xc0\xe7\x91\xc0\x9d\x66\x9c\xbc\x1e\x03\x6a\x67\xcb\xac\x88\x07\x68\xe7\x86\x93\xb8\x9a\xc1\x63\xe0\x8e\x3c\x8e\xda\x4d\x14\xa4\xb8\x27\x84\x91\x6a\x6b\x2c\x35\x2a\xb9\x66\x6d\x02\xfb\xa9\x66\xc4\x84\x76\x2b\x2c\x15\x03\x31\x1e\x52\x45\xae\x5e\x89\xd5\xac\x24\x7c\x47\xa7\xac\x73\xed\x49\x33\x05\x68\xf4\x74\xca\x86\x2b\x33\xf5\xf5\x2d\xfd\xda\xb8\x9b\xfd\x14\x78\xc8\x46\x2e\x14\x9e\x78\xf2\x3d\x3e\xe4\x9e\xc4\x6c\x23\x5b\x18\xb7\x11\xc0\x2d\x7a\xeb\x30\xbf\x93\x7d\x1a\x47\x77\x46\xd0\x47\xfa\xb5\xa0\x57\xe2\x34\x6e\xa7\x99\x3c\xa6\x20\xbf\x4e\xad\x9d\x0b\x1b\x79\xd2\x2f\x67\x11\x8b\x40\x56\x38\x52\x93\xcd\x2c\x93\xfb\x32\x82\xb5\xc9\x03\x15\x4b\x0b\xeb\x3f\x46\x5f\x20\xaa\x3b\x53\xca\xfd\xa3\xf4\x2d\x1f\xb7\x43\x44\x5f\x5c\x33\x7d\xb7\xdc\x3d\x7b\x3f\xf8\xff\x0b\x77\x89\xf9\x27\xca\xcb\xeb\x1c\x2e\xa5\x6e\x97\xfd\x5e\x73\x5f\xed\xfb\x6f\x13\xf8\xcd\x5b\x46\x11\x23\xa8\x6f\x30\xcf\x3f\x03\x00\x00\xff\xff\xb0\x66\x7b\xfe\x26\x04\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x4f\x8b\xdb\x30\x10\xc5\xcf\xd6\xa7\x78\x84\xa5\xc4\x4b\xb0\xef\x29\x7b\x28\xdd\x2d\xf4\x92\x2d\xec\x42\xcf\x8a\x3c\xb2\x45\x15\xdb\x48\xe3\x84\x20\xfc\xdd\xcb\x38\x61\xfb\x4f\x29\xbd\xf4\x66\x69\xf4\xde\x9b\xdf\x8c\xeb\x1a\x1f\x87\x86\xd0\x52\x4f\x41\x33\x35\xd8\x9f\x61\xdb\xf7\x78\x7c\xc6\xee\xf9\x15\x4f\x8f\x9f\x5f\x2b\xa5\x46\x6d\xbe\xe9\x96\x90\x12\xaa\x2f\x97\xef\x9d\x3e\x10\xe6\x59\x29\x77\x18\x87\xc0\x58\xab\x62\x65\xbd\x6e\x57\xaa\x58\xb5\x8e\xbb\x69\x5f\x99\xe1\x50\x4f\xc1\xea\x23\xd5\xc6\xbb\x95\x2a\x55\x4a\x08\xba\x6f\x09\x77\x6e\x83\x3b\x79\x8e\xed\x03\xaa\x4f\x5e\xb7\x51\xcc\xea\x5a\x22\x96\x42\x75\x0d\x90\x1a\x5c\x04\x77\x84\x45\xc0\xe7\x91\xc0\x9d\x66\x9c\x82\x1e\x23\x8c\x77\x55\x56\xc4\x03\xb4\xf7\xc3\x49\x5c\xed\x10\x30\x70\x47\x01\x47\xed\x27\x8a\x52\xdc\x13\xe2\x48\xc6\x59\x47\x8d\x5a\x5c\xb3\x36\x91\xc3\x64\x18\x49\x15\xb7\x92\x54\x11\x89\x71\xbf\x5c\xcb\xf9\x85\x58\xcd\x4a\x62\x77\x74\xca\x7a\x9a\x40\x9a\x29\x42\xa3\xa7\x53\x36\x56\xd9\xa9\x37\xb7\xf4\x6b\xeb\x6f\x62\x97\xb8\xcf\x46\x26\x55\x04\xe2\x29\xf4\x78\x97\xab\xa7\x6c\x17\x5b\x58\xbf\x41\x24\xde\xa2\x77\x1e\xf3\x15\xeb\xc3\x38\xfa\x33\xa2\x3e\xd2\x8f\xbd\xbc\x10\x2f\x53\xf6\x9a\x29\x60\x8a\xf2\xbb\x18\xed\x7d\xdc\xc8\x93\xfe\xf2\x2d\x62\x11\xc8\xe6\x46\x6a\xb2\x99\xd5\xe2\x7e\xe1\x5f\xdb\x3c\x4d\x79\x69\x61\xfd\xc7\xdc\x4b\xe1\xb4\x95\xdc\x3f\x48\xdf\x72\xb8\x1d\x22\xfa\xf2\x67\xa6\xaf\x8e\xbb\xa7\x10\x86\xf0\x7f\xe1\xde\x62\xfe\x89\xf2\xed\x75\x0e\x97\x96\x6e\x7f\x87\xbe\x6e\xfa\x6f\xec\xbf\xb8\xca\x10\x52\x02\xf5\x0d\xe6\xf9\x7b\x00\x00\x00\xff\xff\x6d\x3d\x9e\xe0\x14\x04\x00\x00"), }, "/templates/cli_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "cli_flags_generated.gotpl", - modTime: time.Date(2019, 8, 4, 5, 32, 38, 55742173, time.UTC), - uncompressedSize: 2230, + modTime: time.Date(2019, 8, 4, 14, 51, 15, 321357993, time.UTC), + uncompressedSize: 2102, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\x41\x4f\xeb\x38\x10\x3e\x37\xbf\x62\xb6\xe2\x90\xa0\x6e\x7b\x5f\xc4\x89\xc2\x2e\xd2\x0a\xd0\x83\xc7\xdd\x4d\xc6\xa9\x85\xb1\x8b\xed\xc0\x43\x51\xff\xfb\xd3\x8c\x9d\xb4\x4d\x0b\xf4\xc2\xeb\xc9\x9e\xf9\xfc\xcd\x37\xdf\x8c\x9a\xd9\x0c\x2e\x6c\x85\x50\xa3\x41\x27\x02\x56\xb0\x78\x07\x59\x9f\xc1\xfc\x16\x6e\x6e\x1f\xe0\x72\x7e\xfd\x30\xcd\xb2\x95\x28\x9f\x44\x8d\xd0\xb6\x30\xbd\x8b\xe7\x1b\xf1\x8c\xb0\x5e\x67\x99\x7a\x5e\x59\x17\x20\xcf\x46\x63\xa9\x45\x3d\xce\x46\x63\x1f\x5c\x69\xcd\x2b\x1d\x83\x7a\xc6\x71\x56\x64\x6d\x0b\x4e\x98\x1a\xe1\x44\x4d\xe0\x84\x80\xf0\xcf\x39\x4c\xaf\xb4\xa8\x3d\xd1\xcc\x66\x44\xce\x89\x69\xa2\xa6\x1c\x28\x0f\x02\x18\xfe\xa6\xc2\x12\xc2\xfb\x0a\x37\xc0\x07\xba\xad\xd7\xfd\x7d\x6e\xcb\x20\x94\x26\xbe\x5d\xe0\x36\xa3\x0f\xae\x29\x03\xb4\x19\x00\x00\x27\xd2\xcf\x07\xa7\x4c\xcd\xe1\x9f\x9e\xba\xdd\x0b\x5f\x9a\xd7\x47\xe1\xf6\xc2\x57\x4a\xe3\x9d\x08\xcb\x41\xf8\x07\xbe\x34\xca\x61\x45\xe7\x85\xb5\x9a\x83\xff\xa9\xaa\x42\x13\x29\xfa\x60\xdb\xfe\x0d\x4a\x02\xbe\x24\xb9\x8f\x42\x37\x08\xc1\x35\xec\xf0\x88\xaf\xa3\xd1\xb0\xed\x6c\x44\xef\xd0\x54\xfd\x79\x9b\x63\x8e\x3e\x28\x23\x82\xb2\x66\xc3\xb4\x15\x1c\x9d\x7e\xca\xb7\xce\x68\x24\xf7\xdc\x0d\x38\x0c\x8d\x33\x34\x09\x87\xa2\x12\x0b\x8d\xe0\x70\xe5\xd0\xa3\x09\xb1\x82\x95\x10\x96\xca\xc3\x2b\x49\xa5\x97\xb9\xb4\x0e\x1a\xb6\xb1\x42\x29\x1a\x1d\x7c\x91\xc9\xc6\x94\x90\xcb\x83\x73\x29\x52\xb1\xbc\x48\x1e\xa6\x09\xc5\xda\x40\x90\x08\x40\x97\xcb\x22\xe9\xfb\x17\x03\x53\x74\x02\xc3\x12\xc1\x50\x80\xf5\x20\x2f\xce\x17\x55\x13\xc5\x07\x65\x25\x83\x53\xb5\x6b\xdf\x8f\xb4\x2b\xf8\xb6\xc4\xb0\x44\x07\xd6\x81\xb1\xa1\xaf\x49\x6b\xeb\x12\xf6\x8b\xfa\x1b\xd2\xbc\xe0\x8d\x18\x0a\xe8\xd2\x49\xc4\x90\x05\xb4\xb5\x4f\x1e\x9a\x15\x17\x67\xff\xa9\x7b\x01\xda\x96\x42\x1f\x2c\x3a\xe9\xe4\xef\xf0\x5d\x58\x13\xf0\x57\x98\xc7\x69\x11\xb3\x92\xdc\x94\xb4\x8d\xe9\xba\x28\xe1\x34\xe1\x8a\x3d\xea\x9c\x9d\x8f\x2e\x16\x6d\xcb\xcf\x11\x3a\x5e\x5e\xb2\xf1\x98\x78\x87\x25\xd3\xfe\x51\x1c\xb5\xc7\x1d\xc8\x26\xd7\xad\xe6\xae\x3f\xd4\x7d\xb3\x3a\x28\x65\x02\xe5\x94\x82\xf7\x18\xfa\x7d\xd1\x76\x21\xf4\xd1\x16\xd6\x0c\xff\x4e\x0f\x0f\x0b\xfa\xb3\x4e\x2a\x09\xd2\xd3\xbf\x71\xf4\x32\x4a\xba\x8a\xc6\x75\x46\x16\x67\x84\xf9\xeb\x1c\x8c\xea\x16\xf4\xd8\x21\x48\x5f\x30\x7e\xbd\x3d\xb6\x8f\x1d\xa3\x49\xb1\x4f\x9f\x90\x26\x6b\x26\xe0\x31\xc0\x29\xa7\x93\xde\xef\x77\x4b\x92\x53\x1e\xc3\xf4\x7f\xd6\xc7\x7a\x8a\xde\xc7\x7d\x8b\x36\x82\xee\x84\xf3\xe8\xa2\x96\x15\x9d\xab\x09\xa0\x73\xc4\xd7\x97\x4d\x18\xfe\xa6\x25\x4d\x03\xa8\x8c\x5f\x07\xbe\x5b\x97\x1b\xa5\xa9\xe7\xf4\xaf\xdd\x15\xa5\x0f\x81\x73\xfb\x62\x8e\x9b\x40\x87\x5c\x7f\xd8\xc4\x85\xf0\x21\x36\x32\x64\xdb\xca\x6f\x37\x91\x60\xb1\x97\x5d\xbd\xc7\xef\x45\xff\xee\x77\x00\x00\x00\xff\xff\x4d\xaf\x90\xd0\xb6\x08\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\xc1\x52\xdb\x30\x10\x3d\xdb\x5f\xb1\xcd\x70\xb0\x99\x34\xb9\x97\xe1\x44\xa0\x65\xa6\x03\x4c\xa1\xdc\x15\x7b\xe5\x68\x10\x52\x90\xd6\x50\x26\x93\x7f\xef\xac\x24\x3b\x4e\x48\x21\x17\x7a\xd3\x6a\x9f\xde\x7b\x7a\x5a\x7b\x3a\x85\x33\x5b\x23\x34\x68\xd0\x09\xc2\x1a\xe6\xaf\x20\x9b\x13\x98\x5d\xc3\xd5\xf5\x1d\x9c\xcf\x2e\xef\x26\x79\xbe\x14\xd5\x83\x68\x10\x56\x2b\x98\xdc\xc4\xf5\x95\x78\x44\x58\xaf\xf3\x5c\x3d\x2e\xad\x23\x28\xf2\x6c\x24\xb5\x68\x46\x79\x36\xf2\xe4\x2a\x6b\x9e\x79\x49\xea\x11\x47\x79\x99\xaf\x56\xe0\x84\x69\x10\x8e\xd4\x18\x8e\x18\x08\xdf\x4e\x61\x72\xa1\x45\xe3\x99\x66\x3a\x65\xf2\xd0\x98\x24\x6a\xee\x81\xf2\x20\x20\xc0\x5f\x14\x2d\x80\x5e\x97\xb8\x01\xde\x71\xb5\x5e\xf7\xf5\xcc\x56\x24\x94\x66\xbe\x6d\xe0\x90\xd1\x93\x6b\x2b\x82\x55\x9e\xf1\x6e\x96\x79\x72\xca\x34\x79\xf6\xdb\x8b\x66\x50\x9e\x9b\xe7\x7b\xe1\x36\xf5\x85\xd2\x78\x23\x68\xd1\x6f\xfc\xc2\xa7\x56\x39\xac\xb3\xb9\xb5\x3a\xcf\x7e\xa8\xba\x46\x93\xa5\x6a\xb5\xfa\x0a\x4a\x02\x3e\x25\x03\xf7\x42\xb7\x08\xe4\xda\x90\x59\x16\xca\x6c\xf7\x1e\xf1\x18\x9a\xba\x5f\x0f\x29\x66\xe8\x49\x19\x41\xca\x9a\x0d\xd1\x60\x33\x3b\x7e\x97\x6f\x9d\x73\xc6\xb7\xc1\x3c\x38\xa4\xd6\x19\x8e\xd6\xa1\xa8\xc5\x5c\x23\x38\x5c\x3a\xf4\x68\x28\x2a\x58\x09\xb4\x50\x1e\x9e\xd9\x29\x9f\x2c\xa4\x75\xd0\x72\x46\x50\xa3\x14\xad\x26\x5f\xe6\xb2\x35\x15\x14\x72\x6f\xd0\x65\x12\x2b\x4a\x88\x91\x71\xe4\x51\x18\xb8\x1f\xbb\xe8\x0a\x59\x26\x73\xdf\x91\xc2\xf9\xce\x1d\x2d\x10\x0c\x6f\x04\x33\x18\xc6\xe0\x03\xc9\x44\xb1\x4f\x53\x06\x64\x92\xba\xf4\xdd\xf3\xf5\x6a\x2f\x0b\xa4\x05\x3a\xb0\x0e\x8c\xa5\x5e\x90\x27\xd0\x25\xec\x07\xe2\x1b\xd2\xa2\x04\x9e\x83\x2d\xf5\xae\x97\x1c\xec\x52\x80\xb6\xf6\xc1\x43\xbb\x0c\xca\x21\x76\xbe\xb7\x00\x6d\x2b\xa1\xf7\x2a\x8e\x3b\xef\x5b\x7c\x67\xd6\x10\xfe\xa1\x59\x7c\x24\x66\x56\x32\xdc\x48\xda\xd6\x74\x57\xa8\xe0\x38\xe1\xca\x37\xd4\x45\xc8\x3c\xe6\x17\xba\x7c\x1e\xa1\x23\x0e\xc3\x35\x1a\x0d\xbf\xbb\x61\x27\x6c\xa3\xf6\x5b\x1f\x66\xdf\xe9\xc6\x71\x90\x0c\xdf\xbb\x5d\xee\x35\x31\x86\x6a\xc2\x9b\xb7\x48\xfd\x8c\x68\x3b\x17\xfa\xe0\xf0\x9a\x00\xff\xcc\xf4\xf6\x1b\xfa\x5f\x19\x2a\x09\xd2\xf3\x9f\x34\xa6\x18\xcd\x5c\xc4\xc8\xba\x08\xcb\x13\xc6\x7c\x39\x05\xa3\xc2\x44\x1e\x14\xbc\xf4\x65\x9e\xad\xfb\x47\xfa\x77\x3e\xfc\x2e\x21\x95\x77\xe8\x52\x10\x63\xf0\x48\x70\x1c\xda\xc9\xe3\x67\x66\x23\x39\x17\x8f\x34\xf9\x19\x9c\x05\x27\x65\x8c\x6c\x98\xc6\xc6\xc0\x8d\x70\x1e\x5d\xd4\x5e\xf2\xba\x1e\x03\x3a\xc7\x34\xbd\x52\xc2\x0c\x5d\xec\x40\x65\xfc\xd9\x87\xda\xba\xc2\x28\x5d\x32\x36\xfd\xd5\x59\x9e\x81\x03\x03\x07\x64\x9c\xf1\x53\xbc\x71\x7a\x26\x3c\x45\xb7\xbb\x0c\x83\xfe\xd0\x69\x82\x45\xc3\x03\x53\x07\xbe\x73\x7f\xe2\x6f\x00\x00\x00\xff\xff\x9b\xde\x9c\x04\x36\x08\x00\x00"), }, } fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ diff --git a/flag-gen/templates/altsrc_flags_generated.gotpl b/flag-gen/templates/altsrc_flags_generated.gotpl index e89eb8e..07f6e82 100644 --- a/flag-gen/templates/altsrc_flags_generated.gotpl +++ b/flag-gen/templates/altsrc_flags_generated.gotpl @@ -4,19 +4,19 @@ package {{ .PackageName }} import ( "flag" - "github.com/urfave/cli" + "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 + 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 } + return &{{ $flag.Name }}Flag{ {{ $flag.Name }}Flag: fl, set: nil } } // Apply saves the flagSet for later usage calls, then calls @@ -29,7 +29,7 @@ func (f *{{ $flag.Name }}Flag) Apply(set *flag.FlagSet) { // 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) + f.set = set + return f.{{ $flag.Name }}Flag.ApplyWithError(set) } {{ end }} \ No newline at end of file diff --git a/flag-gen/templates/cli_flags_generated.gotpl b/flag-gen/templates/cli_flags_generated.gotpl index 3a6ca7c..3d4c64d 100644 --- a/flag-gen/templates/cli_flags_generated.gotpl +++ b/flag-gen/templates/cli_flags_generated.gotpl @@ -10,14 +10,14 @@ import ( {{ range $i, $flag := .Flags }} // {{ $flag.Name }}Flag is a flag with type {{ $flag.Type }}{{ $flag.Doctail }} type {{ $flag.Name }}Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - {{- if eq $flag.Value true }} - Value {{ $flag.Type }} + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + {{- if eq $flag.Value true }} + Value {{ $flag.Type }} {{- end }} {{- if eq $flag.Destination true }} Destination *{{ $flag.Type }} @@ -27,43 +27,43 @@ type {{ $flag.Name }}Flag struct { // String returns a readable representation of this value // (for usage defaults) func (f {{ $flag.Name }}Flag) String() string { - return FlagStringer(f) + return FlagStringer(f) } // GetName returns the name of the flag func (f {{ $flag.Name }}Flag) GetName() string { - return f.Name + return f.Name } // IsRequired returns whether or not the flag is required func (f {{ $flag.Name }}Flag) IsRequired() bool { - return f.Required + return f.Required } // {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns // {{ $flag.ContextDefault }} if not found -func (c *Context) {{ $flag.Name }}(name string){{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { - return lookup{{ $flag.Name }}(name, c.flagSet) +func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} { + return lookup{{ $flag.Name }}(name, c.flagSet) } // Global{{ $flag.Name }} looks up the value of a global {{ $flag.Name }}Flag, returns // {{ $flag.ContextDefault }} if not found -func (c *Context) Global{{ $flag.Name }}(name string){{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookup{{ $flag.Name }}(name, fs) - } - return {{ $flag.ContextDefault }} +func (c *Context) Global{{ $flag.Name }}(name string) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} { + if fs := lookupGlobalFlagSet(name, c); fs != nil { + return lookup{{ $flag.Name }}(name, fs) + } + return {{ $flag.ContextDefault }} } -func lookup{{ $flag.Name }}(name string, set *flag.FlagSet){{ if ne .ContextType "" }} {{ $flag.ContextType }} {{ else }} {{ $flag.Type }} {{- end }} { - f := set.Lookup(name) - if f != nil { - {{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }} - if err != nil { - return {{ $flag.ContextDefault }} - } - {{ if ne .ParserCast "" }}return {{ $flag.ParserCast }}{{ else }}return parsed{{ end }} - } - return {{ $flag.ContextDefault }} +func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} { + f := set.Lookup(name) + if f != nil { + {{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }} + if err != nil { + return {{ $flag.ContextDefault }} + } + {{ if ne .ParserCast "" }}return {{ $flag.ParserCast }}{{ else }}return parsed{{ end }} + } + return {{ $flag.ContextDefault }} } {{ end }} \ No newline at end of file diff --git a/flag_generated.go b/flag_generated.go index f106d23..83e10d7 100644 --- a/flag_generated.go +++ b/flag_generated.go @@ -10,13 +10,13 @@ import ( // BoolFlag is a flag with type bool type BoolFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Destination *bool + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Destination *bool } // String returns a readable representation of this value @@ -64,13 +64,13 @@ func lookupBool(name string, set *flag.FlagSet) bool { // BoolTFlag is a flag with type bool that is true by default type BoolTFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Destination *bool + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Destination *bool } // String returns a readable representation of this value @@ -118,14 +118,14 @@ func lookupBoolT(name string, set *flag.FlagSet) bool { // DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) type DurationFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value time.Duration - Destination *time.Duration + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value time.Duration + Destination *time.Duration } // String returns a readable representation of this value @@ -173,14 +173,14 @@ func lookupDuration(name string, set *flag.FlagSet) time.Duration { // Float64Flag is a flag with type float64 type Float64Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value float64 - Destination *float64 + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value float64 + Destination *float64 } // String returns a readable representation of this value @@ -228,13 +228,13 @@ func lookupFloat64(name string, set *flag.FlagSet) float64 { // GenericFlag is a flag with type Generic type GenericFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value Generic + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value Generic } // String returns a readable representation of this value @@ -282,14 +282,14 @@ func lookupGeneric(name string, set *flag.FlagSet) interface{} { // Int64Flag is a flag with type int64 type Int64Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value int64 - Destination *int64 + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value int64 + Destination *int64 } // String returns a readable representation of this value @@ -337,14 +337,14 @@ func lookupInt64(name string, set *flag.FlagSet) int64 { // IntFlag is a flag with type int type IntFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value int - Destination *int + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value int + Destination *int } // String returns a readable representation of this value @@ -392,13 +392,13 @@ func lookupInt(name string, set *flag.FlagSet) int { // IntSliceFlag is a flag with type *IntSlice type IntSliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *IntSlice + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value *IntSlice } // String returns a readable representation of this value @@ -446,13 +446,13 @@ func lookupIntSlice(name string, set *flag.FlagSet) []int { // Int64SliceFlag is a flag with type *Int64Slice type Int64SliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *Int64Slice + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value *Int64Slice } // String returns a readable representation of this value @@ -500,14 +500,14 @@ func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { // StringFlag is a flag with type string type StringFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value string - Destination *string + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value string + Destination *string } // String returns a readable representation of this value @@ -555,13 +555,13 @@ func lookupString(name string, set *flag.FlagSet) string { // StringSliceFlag is a flag with type *StringSlice type StringSliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *StringSlice + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value *StringSlice } // String returns a readable representation of this value @@ -609,14 +609,14 @@ func lookupStringSlice(name string, set *flag.FlagSet) []string { // Uint64Flag is a flag with type uint64 type Uint64Flag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value uint64 - Destination *uint64 + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value uint64 + Destination *uint64 } // String returns a readable representation of this value @@ -664,14 +664,14 @@ func lookupUint64(name string, set *flag.FlagSet) uint64 { // UintFlag is a flag with type uint type UintFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value uint - Destination *uint + Name string + Usage string + EnvVar string + FilePath string + Required bool + Hidden bool + Value uint + Destination *uint } // String returns a readable representation of this value From 798e1f3d3aba8d04c9118962870b41ad099b7bea Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 20:29:53 +0530 Subject: [PATCH 22/31] fix spacing issue --- flag-gen/templates/cli_flags_generated.gotpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flag-gen/templates/cli_flags_generated.gotpl b/flag-gen/templates/cli_flags_generated.gotpl index 3d4c64d..97bd49f 100644 --- a/flag-gen/templates/cli_flags_generated.gotpl +++ b/flag-gen/templates/cli_flags_generated.gotpl @@ -10,7 +10,7 @@ import ( {{ range $i, $flag := .Flags }} // {{ $flag.Name }}Flag is a flag with type {{ $flag.Type }}{{ $flag.Doctail }} type {{ $flag.Name }}Flag struct { - Name string + Name string Usage string EnvVar string FilePath string From a7f0d86509d0845980b77999dc5882b32f244818 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 20:33:21 +0530 Subject: [PATCH 23/31] add zero mod fs back and commit file with latest ts --- flag-gen/assets_generate.go | 38 +++++++++++++++++++++++++++++++++---- flag-gen/assets_vfsdata.go | 4 ++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/flag-gen/assets_generate.go b/flag-gen/assets_generate.go index c3847d6..50f6045 100644 --- a/flag-gen/assets_generate.go +++ b/flag-gen/assets_generate.go @@ -9,11 +9,41 @@ import ( "net/http" ) +// zeroModTimeFileSystem is an http.FileSystem wrapper. +// It exposes a filesystem exactly like Source, except +// all file modification times are changed to zero. +// See https://github.com/shurcooL/vfsgen/pull/40#issuecomment-355416103 +type zeroModTimeFileSystem struct { + Source http.FileSystem +} + +func (fs zeroModTimeFileSystem) Open(name string) (http.File, error) { + f, err := fs.Source.Open(name) + return file{f}, err +} + +type file struct { + http.File +} + +func (f file) Stat() (os.FileInfo, error) { + fi, err := f.File.Stat() + return fileInfo{fi}, err +} + +type fileInfo struct { + os.FileInfo +} + +func (fi fileInfo) ModTime() time.Time { return time.Time{} } + func main() { - fs := union.New(map[string]http.FileSystem{ - "/templates": http.Dir("templates"), - "/source": http.Dir("source"), - }) + fs := zeroModTimeFileSystem{ + Source: union.New(map[string]http.FileSystem{ + "/templates": http.Dir("templates"), + "/source": http.Dir("source"), + }), + } err := vfsgen.Generate(fs, vfsgen.Options{}) diff --git a/flag-gen/assets_vfsdata.go b/flag-gen/assets_vfsdata.go index f5fd185..b230722 100644 --- a/flag-gen/assets_vfsdata.go +++ b/flag-gen/assets_vfsdata.go @@ -34,7 +34,7 @@ var assets = func() http.FileSystem { }, "/templates": &vfsgen۰DirInfo{ name: "templates", - modTime: time.Date(2019, 8, 4, 14, 51, 15, 358024804, time.UTC), + modTime: time.Date(2019, 8, 4, 14, 58, 18, 980401456, time.UTC), }, "/templates/altsrc_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "altsrc_flags_generated.gotpl", @@ -45,7 +45,7 @@ var assets = func() http.FileSystem { }, "/templates/cli_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "cli_flags_generated.gotpl", - modTime: time.Date(2019, 8, 4, 14, 51, 15, 321357993, time.UTC), + modTime: time.Date(2019, 8, 4, 14, 58, 18, 943734538, time.UTC), uncompressedSize: 2102, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\xc1\x52\xdb\x30\x10\x3d\xdb\x5f\xb1\xcd\x70\xb0\x99\x34\xb9\x97\xe1\x44\xa0\x65\xa6\x03\x4c\xa1\xdc\x15\x7b\xe5\x68\x10\x52\x90\xd6\x50\x26\x93\x7f\xef\xac\x24\x3b\x4e\x48\x21\x17\x7a\xd3\x6a\x9f\xde\x7b\x7a\x5a\x7b\x3a\x85\x33\x5b\x23\x34\x68\xd0\x09\xc2\x1a\xe6\xaf\x20\x9b\x13\x98\x5d\xc3\xd5\xf5\x1d\x9c\xcf\x2e\xef\x26\x79\xbe\x14\xd5\x83\x68\x10\x56\x2b\x98\xdc\xc4\xf5\x95\x78\x44\x58\xaf\xf3\x5c\x3d\x2e\xad\x23\x28\xf2\x6c\x24\xb5\x68\x46\x79\x36\xf2\xe4\x2a\x6b\x9e\x79\x49\xea\x11\x47\x79\x99\xaf\x56\xe0\x84\x69\x10\x8e\xd4\x18\x8e\x18\x08\xdf\x4e\x61\x72\xa1\x45\xe3\x99\x66\x3a\x65\xf2\xd0\x98\x24\x6a\xee\x81\xf2\x20\x20\xc0\x5f\x14\x2d\x80\x5e\x97\xb8\x01\xde\x71\xb5\x5e\xf7\xf5\xcc\x56\x24\x94\x66\xbe\x6d\xe0\x90\xd1\x93\x6b\x2b\x82\x55\x9e\xf1\x6e\x96\x79\x72\xca\x34\x79\xf6\xdb\x8b\x66\x50\x9e\x9b\xe7\x7b\xe1\x36\xf5\x85\xd2\x78\x23\x68\xd1\x6f\xfc\xc2\xa7\x56\x39\xac\xb3\xb9\xb5\x3a\xcf\x7e\xa8\xba\x46\x93\xa5\x6a\xb5\xfa\x0a\x4a\x02\x3e\x25\x03\xf7\x42\xb7\x08\xe4\xda\x90\x59\x16\xca\x6c\xf7\x1e\xf1\x18\x9a\xba\x5f\x0f\x29\x66\xe8\x49\x19\x41\xca\x9a\x0d\xd1\x60\x33\x3b\x7e\x97\x6f\x9d\x73\xc6\xb7\xc1\x3c\x38\xa4\xd6\x19\x8e\xd6\xa1\xa8\xc5\x5c\x23\x38\x5c\x3a\xf4\x68\x28\x2a\x58\x09\xb4\x50\x1e\x9e\xd9\x29\x9f\x2c\xa4\x75\xd0\x72\x46\x50\xa3\x14\xad\x26\x5f\xe6\xb2\x35\x15\x14\x72\x6f\xd0\x65\x12\x2b\x4a\x88\x91\x71\xe4\x51\x18\xb8\x1f\xbb\xe8\x0a\x59\x26\x73\xdf\x91\xc2\xf9\xce\x1d\x2d\x10\x0c\x6f\x04\x33\x18\xc6\xe0\x03\xc9\x44\xb1\x4f\x53\x06\x64\x92\xba\xf4\xdd\xf3\xf5\x6a\x2f\x0b\xa4\x05\x3a\xb0\x0e\x8c\xa5\x5e\x90\x27\xd0\x25\xec\x07\xe2\x1b\xd2\xa2\x04\x9e\x83\x2d\xf5\xae\x97\x1c\xec\x52\x80\xb6\xf6\xc1\x43\xbb\x0c\xca\x21\x76\xbe\xb7\x00\x6d\x2b\xa1\xf7\x2a\x8e\x3b\xef\x5b\x7c\x67\xd6\x10\xfe\xa1\x59\x7c\x24\x66\x56\x32\xdc\x48\xda\xd6\x74\x57\xa8\xe0\x38\xe1\xca\x37\xd4\x45\xc8\x3c\xe6\x17\xba\x7c\x1e\xa1\x23\x0e\xc3\x35\x1a\x0d\xbf\xbb\x61\x27\x6c\xa3\xf6\x5b\x1f\x66\xdf\xe9\xc6\x71\x90\x0c\xdf\xbb\x5d\xee\x35\x31\x86\x6a\xc2\x9b\xb7\x48\xfd\x8c\x68\x3b\x17\xfa\xe0\xf0\x9a\x00\xff\xcc\xf4\xf6\x1b\xfa\x5f\x19\x2a\x09\xd2\xf3\x9f\x34\xa6\x18\xcd\x5c\xc4\xc8\xba\x08\xcb\x13\xc6\x7c\x39\x05\xa3\xc2\x44\x1e\x14\xbc\xf4\x65\x9e\xad\xfb\x47\xfa\x77\x3e\xfc\x2e\x21\x95\x77\xe8\x52\x10\x63\xf0\x48\x70\x1c\xda\xc9\xe3\x67\x66\x23\x39\x17\x8f\x34\xf9\x19\x9c\x05\x27\x65\x8c\x6c\x98\xc6\xc6\xc0\x8d\x70\x1e\x5d\xd4\x5e\xf2\xba\x1e\x03\x3a\xc7\x34\xbd\x52\xc2\x0c\x5d\xec\x40\x65\xfc\xd9\x87\xda\xba\xc2\x28\x5d\x32\x36\xfd\xd5\x59\x9e\x81\x03\x03\x07\x64\x9c\xf1\x53\xbc\x71\x7a\x26\x3c\x45\xb7\xbb\x0c\x83\xfe\xd0\x69\x82\x45\xc3\x03\x53\x07\xbe\x73\x7f\xe2\x6f\x00\x00\x00\xff\xff\x9b\xde\x9c\x04\x36\x08\x00\x00"), From 489d92d2e2477b240015e83af07658e826eaa7cb Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 20:44:15 +0530 Subject: [PATCH 24/31] add missing os package --- flag-gen/assets_generate.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flag-gen/assets_generate.go b/flag-gen/assets_generate.go index 50f6045..021da71 100644 --- a/flag-gen/assets_generate.go +++ b/flag-gen/assets_generate.go @@ -7,6 +7,8 @@ import ( "github.com/shurcooL/vfsgen" "log" "net/http" + "os" + "time" ) // zeroModTimeFileSystem is an http.FileSystem wrapper. From ac5c97b41844032ae47d5f94d7f73533af629f11 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Sun, 4 Aug 2019 20:45:28 +0530 Subject: [PATCH 25/31] add latest assets file --- flag-gen/assets_vfsdata.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flag-gen/assets_vfsdata.go b/flag-gen/assets_vfsdata.go index b230722..024039a 100644 --- a/flag-gen/assets_vfsdata.go +++ b/flag-gen/assets_vfsdata.go @@ -23,29 +23,29 @@ var assets = func() http.FileSystem { }, "/source": &vfsgen۰DirInfo{ name: "source", - modTime: time.Date(2019, 8, 4, 4, 7, 51, 386498815, time.UTC), + modTime: time.Time{}, }, "/source/flag-types.json": &vfsgen۰CompressedFileInfo{ name: "flag-types.json", - modTime: time.Date(2019, 8, 4, 2, 47, 4, 104288603, time.UTC), + modTime: time.Time{}, uncompressedSize: 2559, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x94\xc1\x6e\x9c\x30\x10\x86\xef\x3c\xc5\xc8\xbd\x40\xb5\x82\x1c\x56\x7b\xd8\x63\x55\xb5\xda\x5b\xa5\x34\xbd\x24\x51\xe4\x80\x21\x56\x1d\x1b\xd9\x43\xd4\x28\xca\xbb\x57\xf6\x2e\xbb\x60\x0c\x62\x5b\x2d\xb9\xfe\x23\x98\xef\x9b\xb1\xe6\x36\x02\x78\x8b\x00\x00\x88\xa4\xcf\x8c\x6c\x81\x7c\x51\x4a\x90\xd5\x3e\xc3\xd7\xda\x65\x8f\x9d\xec\x85\x8a\xc6\x86\x25\x15\x86\x1d\xb2\x82\x19\x24\x5b\x40\xdd\xb4\x49\xae\x24\xb2\x3f\xf8\x50\xb0\x92\x36\xc2\x16\x89\xfb\xa0\xfd\x4b\x4d\xb5\x61\xda\xc6\x06\x75\xae\xe4\x4b\xfa\xc3\x26\xb6\x79\x5c\xa6\xbf\x6c\x8f\xf4\x1a\x35\x97\x55\x9c\x24\x24\x02\x78\x5f\x85\x51\x7f\xfe\x3f\x6b\xa1\x72\xa4\x5c\xd8\x8f\x01\x9f\x28\x02\x37\xae\x0c\x8f\xaf\xd0\xf2\x2f\xa9\xf5\xb5\xd1\x14\xb9\x92\xbe\x19\xf2\x67\x96\xfa\xc5\x56\xb1\xeb\x33\x69\x18\x1b\xc6\xe0\x09\xb1\x36\xdb\x2c\xab\x94\xa0\xb2\x4a\x95\xae\xb2\xfa\x77\x95\xd9\x0e\xd9\x27\x87\xdc\xf6\x49\x26\xd4\xaf\x86\xda\x8e\xb1\xf7\x83\xf9\xde\xdf\x84\xa2\xb8\x59\xfb\xda\x65\x3f\x9e\x25\x3c\x0f\xb6\xb7\x23\xd7\x7d\x00\xbb\x82\xcd\x7a\x14\xf8\x3b\x93\x4c\xf3\xdc\x07\xf6\xe2\x71\xe0\xee\xb3\x0c\x10\x4b\x2e\xfc\xe1\xb7\x2d\xb8\x44\xa6\x4b\x9a\xb3\xb7\xf7\x31\xb8\x9d\x0c\xcc\x92\xcb\x05\x26\xb9\x93\xa1\x39\x5e\x4d\x8e\x72\x27\x31\xc0\xfa\xa1\xa4\xbd\x4f\x1f\x72\xea\xfa\x59\xaa\xd8\x45\xc5\x94\xcb\xb5\xe0\x39\xf3\x85\x3e\xfb\x85\x4b\xbc\x8c\xdb\xfb\xce\xdc\x4e\xda\x47\xcd\xf8\x48\x91\x24\xfb\xc8\x2a\x33\xad\x95\x8e\x25\x17\x53\x52\x9b\xf5\xa8\x96\x57\xba\x98\xd8\xe9\xf1\x8e\xa9\x1d\x48\xce\x93\xdb\xef\xde\x17\x33\xbd\xf4\x5f\xdf\xe0\x1d\xb9\x23\x43\xe8\xe1\xab\x9b\x4b\x19\xde\x41\xa0\x76\x99\x25\xf4\x87\x12\xdc\x42\x87\xe5\xbc\x35\xdc\xf0\xd0\xcd\x6a\x16\x39\x5a\xb6\xf7\xd9\x57\xeb\x86\x0f\xcf\x56\xb3\xc0\xdd\x9a\x86\x0d\x1f\xae\xc6\xbf\x5c\xd1\x7d\xf4\x37\x00\x00\xff\xff\x66\x52\x85\x44\xff\x09\x00\x00"), }, "/templates": &vfsgen۰DirInfo{ name: "templates", - modTime: time.Date(2019, 8, 4, 14, 58, 18, 980401456, time.UTC), + modTime: time.Time{}, }, "/templates/altsrc_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "altsrc_flags_generated.gotpl", - modTime: time.Date(2019, 8, 4, 14, 47, 17, 700754849, time.UTC), + modTime: time.Time{}, uncompressedSize: 1044, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x92\x4f\x8b\xdb\x30\x10\xc5\xcf\xd6\xa7\x78\x84\xa5\xc4\x4b\xb0\xef\x29\x7b\x28\xdd\x2d\xf4\x92\x2d\xec\x42\xcf\x8a\x3c\xb2\x45\x15\xdb\x48\xe3\x84\x20\xfc\xdd\xcb\x38\x61\xfb\x4f\x29\xbd\xf4\x66\x69\xf4\xde\x9b\xdf\x8c\xeb\x1a\x1f\x87\x86\xd0\x52\x4f\x41\x33\x35\xd8\x9f\x61\xdb\xf7\x78\x7c\xc6\xee\xf9\x15\x4f\x8f\x9f\x5f\x2b\xa5\x46\x6d\xbe\xe9\x96\x90\x12\xaa\x2f\x97\xef\x9d\x3e\x10\xe6\x59\x29\x77\x18\x87\xc0\x58\xab\x62\x65\xbd\x6e\x57\xaa\x58\xb5\x8e\xbb\x69\x5f\x99\xe1\x50\x4f\xc1\xea\x23\xd5\xc6\xbb\x95\x2a\x55\x4a\x08\xba\x6f\x09\x77\x6e\x83\x3b\x79\x8e\xed\x03\xaa\x4f\x5e\xb7\x51\xcc\xea\x5a\x22\x96\x42\x75\x0d\x90\x1a\x5c\x04\x77\x84\x45\xc0\xe7\x91\xc0\x9d\x66\x9c\x82\x1e\x23\x8c\x77\x55\x56\xc4\x03\xb4\xf7\xc3\x49\x5c\xed\x10\x30\x70\x47\x01\x47\xed\x27\x8a\x52\xdc\x13\xe2\x48\xc6\x59\x47\x8d\x5a\x5c\xb3\x36\x91\xc3\x64\x18\x49\x15\xb7\x92\x54\x11\x89\x71\xbf\x5c\xcb\xf9\x85\x58\xcd\x4a\x62\x77\x74\xca\x7a\x9a\x40\x9a\x29\x42\xa3\xa7\x53\x36\x56\xd9\xa9\x37\xb7\xf4\x6b\xeb\x6f\x62\x97\xb8\xcf\x46\x26\x55\x04\xe2\x29\xf4\x78\x97\xab\xa7\x6c\x17\x5b\x58\xbf\x41\x24\xde\xa2\x77\x1e\xf3\x15\xeb\xc3\x38\xfa\x33\xa2\x3e\xd2\x8f\xbd\xbc\x10\x2f\x53\xf6\x9a\x29\x60\x8a\xf2\xbb\x18\xed\x7d\xdc\xc8\x93\xfe\xf2\x2d\x62\x11\xc8\xe6\x46\x6a\xb2\x99\xd5\xe2\x7e\xe1\x5f\xdb\x3c\x4d\x79\x69\x61\xfd\xc7\xdc\x4b\xe1\xb4\x95\xdc\x3f\x48\xdf\x72\xb8\x1d\x22\xfa\xf2\x67\xa6\xaf\x8e\xbb\xa7\x10\x86\xf0\x7f\xe1\xde\x62\xfe\x89\xf2\xed\x75\x0e\x97\x96\x6e\x7f\x87\xbe\x6e\xfa\x6f\xec\xbf\xb8\xca\x10\x52\x02\xf5\x0d\xe6\xf9\x7b\x00\x00\x00\xff\xff\x6d\x3d\x9e\xe0\x14\x04\x00\x00"), }, "/templates/cli_flags_generated.gotpl": &vfsgen۰CompressedFileInfo{ name: "cli_flags_generated.gotpl", - modTime: time.Date(2019, 8, 4, 14, 58, 18, 943734538, time.UTC), + modTime: time.Time{}, uncompressedSize: 2102, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x54\xc1\x52\xdb\x30\x10\x3d\xdb\x5f\xb1\xcd\x70\xb0\x99\x34\xb9\x97\xe1\x44\xa0\x65\xa6\x03\x4c\xa1\xdc\x15\x7b\xe5\x68\x10\x52\x90\xd6\x50\x26\x93\x7f\xef\xac\x24\x3b\x4e\x48\x21\x17\x7a\xd3\x6a\x9f\xde\x7b\x7a\x5a\x7b\x3a\x85\x33\x5b\x23\x34\x68\xd0\x09\xc2\x1a\xe6\xaf\x20\x9b\x13\x98\x5d\xc3\xd5\xf5\x1d\x9c\xcf\x2e\xef\x26\x79\xbe\x14\xd5\x83\x68\x10\x56\x2b\x98\xdc\xc4\xf5\x95\x78\x44\x58\xaf\xf3\x5c\x3d\x2e\xad\x23\x28\xf2\x6c\x24\xb5\x68\x46\x79\x36\xf2\xe4\x2a\x6b\x9e\x79\x49\xea\x11\x47\x79\x99\xaf\x56\xe0\x84\x69\x10\x8e\xd4\x18\x8e\x18\x08\xdf\x4e\x61\x72\xa1\x45\xe3\x99\x66\x3a\x65\xf2\xd0\x98\x24\x6a\xee\x81\xf2\x20\x20\xc0\x5f\x14\x2d\x80\x5e\x97\xb8\x01\xde\x71\xb5\x5e\xf7\xf5\xcc\x56\x24\x94\x66\xbe\x6d\xe0\x90\xd1\x93\x6b\x2b\x82\x55\x9e\xf1\x6e\x96\x79\x72\xca\x34\x79\xf6\xdb\x8b\x66\x50\x9e\x9b\xe7\x7b\xe1\x36\xf5\x85\xd2\x78\x23\x68\xd1\x6f\xfc\xc2\xa7\x56\x39\xac\xb3\xb9\xb5\x3a\xcf\x7e\xa8\xba\x46\x93\xa5\x6a\xb5\xfa\x0a\x4a\x02\x3e\x25\x03\xf7\x42\xb7\x08\xe4\xda\x90\x59\x16\xca\x6c\xf7\x1e\xf1\x18\x9a\xba\x5f\x0f\x29\x66\xe8\x49\x19\x41\xca\x9a\x0d\xd1\x60\x33\x3b\x7e\x97\x6f\x9d\x73\xc6\xb7\xc1\x3c\x38\xa4\xd6\x19\x8e\xd6\xa1\xa8\xc5\x5c\x23\x38\x5c\x3a\xf4\x68\x28\x2a\x58\x09\xb4\x50\x1e\x9e\xd9\x29\x9f\x2c\xa4\x75\xd0\x72\x46\x50\xa3\x14\xad\x26\x5f\xe6\xb2\x35\x15\x14\x72\x6f\xd0\x65\x12\x2b\x4a\x88\x91\x71\xe4\x51\x18\xb8\x1f\xbb\xe8\x0a\x59\x26\x73\xdf\x91\xc2\xf9\xce\x1d\x2d\x10\x0c\x6f\x04\x33\x18\xc6\xe0\x03\xc9\x44\xb1\x4f\x53\x06\x64\x92\xba\xf4\xdd\xf3\xf5\x6a\x2f\x0b\xa4\x05\x3a\xb0\x0e\x8c\xa5\x5e\x90\x27\xd0\x25\xec\x07\xe2\x1b\xd2\xa2\x04\x9e\x83\x2d\xf5\xae\x97\x1c\xec\x52\x80\xb6\xf6\xc1\x43\xbb\x0c\xca\x21\x76\xbe\xb7\x00\x6d\x2b\xa1\xf7\x2a\x8e\x3b\xef\x5b\x7c\x67\xd6\x10\xfe\xa1\x59\x7c\x24\x66\x56\x32\xdc\x48\xda\xd6\x74\x57\xa8\xe0\x38\xe1\xca\x37\xd4\x45\xc8\x3c\xe6\x17\xba\x7c\x1e\xa1\x23\x0e\xc3\x35\x1a\x0d\xbf\xbb\x61\x27\x6c\xa3\xf6\x5b\x1f\x66\xdf\xe9\xc6\x71\x90\x0c\xdf\xbb\x5d\xee\x35\x31\x86\x6a\xc2\x9b\xb7\x48\xfd\x8c\x68\x3b\x17\xfa\xe0\xf0\x9a\x00\xff\xcc\xf4\xf6\x1b\xfa\x5f\x19\x2a\x09\xd2\xf3\x9f\x34\xa6\x18\xcd\x5c\xc4\xc8\xba\x08\xcb\x13\xc6\x7c\x39\x05\xa3\xc2\x44\x1e\x14\xbc\xf4\x65\x9e\xad\xfb\x47\xfa\x77\x3e\xfc\x2e\x21\x95\x77\xe8\x52\x10\x63\xf0\x48\x70\x1c\xda\xc9\xe3\x67\x66\x23\x39\x17\x8f\x34\xf9\x19\x9c\x05\x27\x65\x8c\x6c\x98\xc6\xc6\xc0\x8d\x70\x1e\x5d\xd4\x5e\xf2\xba\x1e\x03\x3a\xc7\x34\xbd\x52\xc2\x0c\x5d\xec\x40\x65\xfc\xd9\x87\xda\xba\xc2\x28\x5d\x32\x36\xfd\xd5\x59\x9e\x81\x03\x03\x07\x64\x9c\xf1\x53\xbc\x71\x7a\x26\x3c\x45\xb7\xbb\x0c\x83\xfe\xd0\x69\x82\x45\xc3\x03\x53\x07\xbe\x73\x7f\xe2\x6f\x00\x00\x00\xff\xff\x9b\xde\x9c\x04\x36\x08\x00\x00"), From adfe6a09c121a6b96357ea161f2d679d509c013f Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Tue, 6 Aug 2019 12:14:18 +0530 Subject: [PATCH 26/31] indenting fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 20f3a58..282de14 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_script: - go get github.com/urfave/gfmrun/... || true - go get golang.org/x/tools/cmd/goimports - if [ ! -f node_modules/.bin/markdown-toc ] ; then - npm install markdown-toc ; + npm install markdown-toc ; fi script: From 5070d00811cd5f2f21b0a6e021581e8efb2479e9 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Tue, 6 Aug 2019 12:33:33 +0530 Subject: [PATCH 27/31] move packages slice to global scope --- build/build.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build/build.go b/build/build.go index b83a8e0..455f8d9 100644 --- a/build/build.go +++ b/build/build.go @@ -12,7 +12,7 @@ import ( "strings" ) -var packages []string +var packages = []string{"cli", "altsrc"} func main() { app := cli.NewApp() @@ -43,8 +43,6 @@ func main() { }, } - packages = []string{"cli", "altsrc"} - err := app.Run(os.Args) if err != nil { log.Fatal(err) From e8bbb4c3b5472320f0af5fb00961c76f1061edd4 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Wed, 7 Aug 2019 01:46:22 +0530 Subject: [PATCH 28/31] remove unnecessary sprintf --- build/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.go b/build/build.go index 455f8d9..64a7bb4 100644 --- a/build/build.go +++ b/build/build.go @@ -58,7 +58,7 @@ func TestActionFunc(c *cli.Context) error { var packageName string if pkg == "cli" { - packageName = fmt.Sprintf("github.com/urfave/cli") + packageName = "github.com/urfave/cli" } else { packageName = fmt.Sprintf("github.com/urfave/cli/%s", pkg) } From 6ee5b89e03a0fc47c6351c902ef714f1475e8fde Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Wed, 7 Aug 2019 01:50:50 +0530 Subject: [PATCH 29/31] move build.go to root --- build/build.go => build.go | 2 ++ 1 file changed, 2 insertions(+) rename build/build.go => build.go (99%) diff --git a/build/build.go b/build.go similarity index 99% rename from build/build.go rename to build.go index 64a7bb4..2a38f8b 100644 --- a/build/build.go +++ b/build.go @@ -1,3 +1,5 @@ +//+build ignore + package main import ( From c19938fbbfb19120beeca5d0af02291a99e61f27 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Wed, 7 Aug 2019 01:51:02 +0530 Subject: [PATCH 30/31] update ci commands --- .travis.yml | 10 +++++----- appveyor.yml | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 282de14..2528ecb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,11 +22,11 @@ before_script: fi script: - - go run build/build.go generate - - go run build/build.go vet - - go run build/build.go test - - go run build/build.go gfmrun - - go run build/build.go toc + - go run build.go generate + - go run build.go vet + - go run build.go test + - go run build.go gfmrun + - go run build.go toc after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/appveyor.yml b/appveyor.yml index 6e4806b..ed74366 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ install: - go get -v -t ./... build_script: - - go run build/build.go generate - - go run build/build.go vet - - go run build/build.go test - - go run build/build.go gfmrun + - go run build.go generate + - go run build.go vet + - go run build.go test + - go run build.go gfmrun From e2de8c74587d464770155415cda09c3569224692 Mon Sep 17 00:00:00 2001 From: Ajitem Sahasrabuddhe Date: Wed, 7 Aug 2019 12:38:17 +0530 Subject: [PATCH 31/31] update readme with correct error message, add 1.12 and 1.11 to travis --- .travis.yml | 4 +++- README.md | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2528ecb..9154f35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: go sudo: false dist: trusty osx_image: xcode8.3 -go: 1.11.x +go: + - 1.11.x + - 1.12.x os: - linux diff --git a/README.md b/README.md index 17d0900..001d76f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ cli [![Build Status](https://travis-ci.org/urfave/cli.svg?branch=master)](https://travis-ci.org/urfave/cli) [![Windows Build Status](https://ci.appveyor.com/api/projects/status/rtgk5xufi932pb2v?svg=true)](https://ci.appveyor.com/project/urfave/cli) + [![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://godoc.org/github.com/urfave/cli) [![codebeat](https://codebeat.co/badges/0a8f30aa-f975-404b-b878-5fab3ae1cc5f)](https://codebeat.co/projects/github-com-urfave-cli) [![Go Report Card](https://goreportcard.com/badge/urfave/cli)](https://goreportcard.com/report/urfave/cli) @@ -888,7 +889,9 @@ Calling `App.Run` will not automatically call `os.Exit`, which means that by default the exit code will "fall through" to being `0`. An explicit exit code may be set by returning a non-nil error that fulfills `cli.ExitCoder`, *or* a `cli.MultiError` that includes an error that fulfills `cli.ExitCoder`, e.g.: - + ``` go package main