From 97af685e64f7c1081af1df1fc16e824ec585f6d5 Mon Sep 17 00:00:00 2001 From: Wendell Sun Date: Sun, 22 May 2022 23:07:10 +0800 Subject: [PATCH] Rebase main, update flag-spec.yaml to add Action field --- altsrc/yaml_file_loader.go | 2 +- flag-spec.yaml | 40 ++++++++++++++++++++------ flag_int_slice.go | 28 ++---------------- go.mod | 2 +- go.sum | 12 ++------ internal/genflags/cmd/genflags/main.go | 2 +- zz_generated.flags.go | 30 +++++++++++++++++++ 7 files changed, 69 insertions(+), 47 deletions(-) diff --git a/altsrc/yaml_file_loader.go b/altsrc/yaml_file_loader.go index 4ace1f23ec..315db1885f 100644 --- a/altsrc/yaml_file_loader.go +++ b/altsrc/yaml_file_loader.go @@ -11,7 +11,7 @@ import ( "github.com/urfave/cli/v2" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) type yamlSourceContext struct { diff --git a/flag-spec.yaml b/flag-spec.yaml index d85fa30bd1..cf3436323b 100644 --- a/flag-spec.yaml +++ b/flag-spec.yaml @@ -3,46 +3,70 @@ # `genflags.Spec` type that maps to this file structure. flag_types: - bool: {} - float64: {} - int64: {} - int: {} - time.Duration: {} - uint64: {} - uint: {} - + bool: + struct_fields: + - { name: Action, type: "func(*Context, bool) error" } + float64: + struct_fields: + - { name: Action, type: "func(*Context, float64) error" } + int64: + struct_fields: + - { name: Action, type: "func(*Context, int64) error" } + int: + struct_fields: + - { name: Action, type: "func(*Context, int) error" } + time.Duration: + struct_fields: + - { name: Action, type: "func(*Context, time.Duration) error" } + uint64: + struct_fields: + - { name: Action, type: "func(*Context, uint64) error" } + uint: + struct_fields: + - { name: Action, type: "func(*Context, uint) error" } string: struct_fields: - { name: TakesFile, type: bool } + - { name: Action, type: "func(*Context, string) error" } Generic: struct_fields: - { name: TakesFile, type: bool } + - { name: Action, type: "func(*Context, interface{}) error" } Path: struct_fields: - { name: TakesFile, type: bool } + - { name: Action, type: "func(*Context, Path) error" } Float64Slice: value_pointer: true skip_interfaces: - fmt.Stringer + struct_fields: + - { name: Action, type: "func(*Context, []float64) error" } Int64Slice: value_pointer: true skip_interfaces: - fmt.Stringer + struct_fields: + - { name: Action, type: "func(*Context, []int64) error" } IntSlice: value_pointer: true skip_interfaces: - fmt.Stringer + struct_fields: + - { name: Action, type: "func(*Context, []int) error" } StringSlice: value_pointer: true skip_interfaces: - fmt.Stringer struct_fields: - { name: TakesFile, type: bool } + - { name: Action, type: "func(*Context, []string) error" } Timestamp: value_pointer: true struct_fields: - { name: Layout, type: string } + - { name: Action, type: "func(*Context, *time.Time) error" } # TODO: enable UintSlice # UintSlice: {} diff --git a/flag_int_slice.go b/flag_int_slice.go index aab99a8388..05e53e95a3 100644 --- a/flag_int_slice.go +++ b/flag_int_slice.go @@ -87,29 +87,6 @@ func (i *IntSlice) Get() interface{} { return *i } -<<<<<<< HEAD -======= -// IntSliceFlag is a flag with type *IntSlice -type IntSliceFlag struct { - Name string - Aliases []string - Usage string - EnvVars []string - FilePath string - Required bool - Hidden bool - Value *IntSlice - DefaultText string - HasBeenSet bool - Action func(*Context, []int) error -} - -// IsSet returns whether or not the flag has been set through env or file -func (f *IntSliceFlag) IsSet() bool { - return f.HasBeenSet -} - ->>>>>>> e132f01 (feat: flag action) // String returns a readable representation of this value // (for usage defaults) func (f *IntSliceFlag) String() string { @@ -176,11 +153,11 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error { return nil } -<<<<<<< HEAD // Get returns the flag’s value in the given Context. func (f *IntSliceFlag) Get(ctx *Context) []int { return ctx.IntSlice(f.Name) -======= +} + // RunAction executes flag action if set func (f *IntSliceFlag) RunAction(c *Context) error { if f.Action != nil { @@ -188,7 +165,6 @@ func (f *IntSliceFlag) RunAction(c *Context) error { } return nil ->>>>>>> e132f01 (feat: flag action) } // IntSlice looks up the value of a local IntSliceFlag, returns diff --git a/go.mod b/go.mod index f9111b0b37..3a70d7be8e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0 github.com/cpuguy83/go-md2man/v2 v2.0.1 golang.org/x/text v0.3.7 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0 ) require github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index afac06b6c4..b564804701 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,14 @@ github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/antzucaro/matchr v0.0.0-20180616170659-cbc221335f3c h1:CucViv7orgFBMkehuFFdkCVF5ERovbkRRyhvaYaHu/k= -github.com/antzucaro/matchr v0.0.0-20180616170659-cbc221335f3c/go.mod h1:bV/CkX4+ANGDaBwbHkt9kK287al/i9BsB18PRBvyqYo= github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0 h1:R/qAiUxFT3mNgQaNqJe0IVznjKRNm23ohAIh9lgtlzc= github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0/go.mod h1:v3ZDlfVAL1OrkKHbGSFFK60k0/7hruHPDq2XMs9Gu6U= github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 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.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/genflags/cmd/genflags/main.go b/internal/genflags/cmd/genflags/main.go index cad25088f6..4212e60da1 100644 --- a/internal/genflags/cmd/genflags/main.go +++ b/internal/genflags/cmd/genflags/main.go @@ -15,7 +15,7 @@ import ( "github.com/urfave/cli/v2" "github.com/urfave/cli/v2/internal/genflags" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) const ( diff --git a/zz_generated.flags.go b/zz_generated.flags.go index 6c16c3e75a..2bc02b58b5 100644 --- a/zz_generated.flags.go +++ b/zz_generated.flags.go @@ -21,6 +21,8 @@ type Float64SliceFlag struct { Aliases []string EnvVars []string + + Action func(*Context, []float64) error } // IsSet returns whether or not the flag has been set through env or file @@ -62,6 +64,8 @@ type GenericFlag struct { EnvVars []string TakesFile bool + + Action func(*Context, interface{}) error } // String returns a readable representation of this value (for usage defaults) @@ -106,6 +110,8 @@ type Int64SliceFlag struct { Aliases []string EnvVars []string + + Action func(*Context, []int64) error } // IsSet returns whether or not the flag has been set through env or file @@ -145,6 +151,8 @@ type IntSliceFlag struct { Aliases []string EnvVars []string + + Action func(*Context, []int) error } // IsSet returns whether or not the flag has been set through env or file @@ -186,6 +194,8 @@ type PathFlag struct { EnvVars []string TakesFile bool + + Action func(*Context, Path) error } // String returns a readable representation of this value (for usage defaults) @@ -232,6 +242,8 @@ type StringSliceFlag struct { EnvVars []string TakesFile bool + + Action func(*Context, []string) error } // IsSet returns whether or not the flag has been set through env or file @@ -273,6 +285,8 @@ type TimestampFlag struct { EnvVars []string Layout string + + Action func(*Context, *time.Time) error } // String returns a readable representation of this value (for usage defaults) @@ -317,6 +331,8 @@ type BoolFlag struct { Aliases []string EnvVars []string + + Action func(*Context, bool) error } // String returns a readable representation of this value (for usage defaults) @@ -361,6 +377,8 @@ type Float64Flag struct { Aliases []string EnvVars []string + + Action func(*Context, float64) error } // String returns a readable representation of this value (for usage defaults) @@ -405,6 +423,8 @@ type IntFlag struct { Aliases []string EnvVars []string + + Action func(*Context, int) error } // String returns a readable representation of this value (for usage defaults) @@ -449,6 +469,8 @@ type Int64Flag struct { Aliases []string EnvVars []string + + Action func(*Context, int64) error } // String returns a readable representation of this value (for usage defaults) @@ -495,6 +517,8 @@ type StringFlag struct { EnvVars []string TakesFile bool + + Action func(*Context, string) error } // String returns a readable representation of this value (for usage defaults) @@ -539,6 +563,8 @@ type DurationFlag struct { Aliases []string EnvVars []string + + Action func(*Context, time.Duration) error } // String returns a readable representation of this value (for usage defaults) @@ -583,6 +609,8 @@ type UintFlag struct { Aliases []string EnvVars []string + + Action func(*Context, uint) error } // String returns a readable representation of this value (for usage defaults) @@ -627,6 +655,8 @@ type Uint64Flag struct { Aliases []string EnvVars []string + + Action func(*Context, uint64) error } // String returns a readable representation of this value (for usage defaults)