Rebase main, update flag-spec.yaml to add Action field

main
Wendell Sun 2 years ago
parent 602471bf21
commit b33117618a
No known key found for this signature in database
GPG Key ID: C1231D5B4615398A

@ -1,5 +1,3 @@
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
@ -10,7 +8,6 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
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/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.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

@ -7,47 +7,77 @@ flag_types:
- name: Count
type: int
pointer: true
- name: Action
type: "func(*Context, bool) error"
float64:
struct_fields:
- name: Action
type: "func(*Context, float64) error"
Float64Slice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
struct_fields:
- name: Action
type: "func(*Context, []float64) error"
int:
struct_fields:
- name: Base
type: int
- name: Action
type: "func(*Context, int) error"
IntSlice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
struct_fields:
- name: Action
type: "func(*Context, []int) error"
int64:
struct_fields:
- name: Base
type: int
- name: Action
type: "func(*Context, int64) error"
Int64Slice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
struct_fields:
- name: Action
type: "func(*Context, []int64) error"
uint:
struct_fields:
- name: Base
type: int
- name: Action
type: "func(*Context, uint) error"
UintSlice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
struct_fields:
- name: Action
type: "func(*Context, []uint) error"
uint64:
struct_fields:
- name: Base
type: int
- name: Action
type: "func(*Context, uint64) error"
Uint64Slice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
struct_fields:
- name: Action
type: "func(*Context, []uint64) error"
string:
struct_fields:
- name: TakesFile
type: bool
- name: Action
type: "func(*Context, string) error"
StringSlice:
value_pointer: true
skip_interfaces:
@ -55,7 +85,12 @@ flag_types:
struct_fields:
- name: TakesFile
type: bool
- name: Action
type: "func(*Context, []string) error"
time.Duration:
struct_fields:
- name: Action
type: "func(*Context, time.Duration) error"
Timestamp:
value_pointer: true
struct_fields:
@ -63,12 +98,18 @@ flag_types:
type: string
- name: Timezone
type: "*time.Location"
- name: Action
type: "func(*Context, *time.Time) error"
Generic:
no_destination_pointer: true
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"

@ -92,29 +92,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 {
@ -197,11 +174,11 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error {
return nil
}
<<<<<<< HEAD
// Get returns the flags 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 {
@ -209,7 +186,6 @@ func (f *IntSliceFlag) RunAction(c *Context) error {
}
return nil
>>>>>>> e132f01 (feat: flag action)
}
func (f *IntSliceFlag) stringify() string {

@ -250,6 +250,13 @@ TYPES
type ActionFunc func(*Context) error
ActionFunc is the action to execute when no subcommands are specified
type ActionableFlag interface {
Flag
RunAction(*Context) error
}
ActionableFlag is an interface that wraps Flag interface and RunAction
operation.
type AfterFunc func(*Context) error
AfterFunc is an action to execute after any subcommands are run, but after
the subcommand has finished it is run even if Action() panics
@ -491,6 +498,9 @@ func (f *BoolFlag) IsVisible() bool
func (f *BoolFlag) Names() []string
Names returns the names of the flag
func (f *BoolFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *BoolFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -798,6 +808,9 @@ func (f *DurationFlag) IsVisible() bool
func (f *DurationFlag) Names() []string
Names returns the names of the flag
func (f *DurationFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *DurationFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -971,6 +984,9 @@ func (f *Float64Flag) IsVisible() bool
func (f *Float64Flag) Names() []string
Names returns the names of the flag
func (f *Float64Flag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *Float64Flag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1056,6 +1072,9 @@ func (f *Float64SliceFlag) IsVisible() bool
func (f *Float64SliceFlag) Names() []string
Names returns the names of the flag
func (f *Float64SliceFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *Float64SliceFlag) SetDestination(slice []float64)
func (f *Float64SliceFlag) SetValue(slice []float64)
@ -1129,6 +1148,9 @@ func (f *GenericFlag) IsVisible() bool
func (f *GenericFlag) Names() []string
Names returns the names of the flag
func (f *GenericFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *GenericFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1191,6 +1213,9 @@ func (f *Int64Flag) IsVisible() bool
func (f *Int64Flag) Names() []string
Names returns the names of the flag
func (f *Int64Flag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *Int64Flag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1276,6 +1301,9 @@ func (f *Int64SliceFlag) IsVisible() bool
func (f *Int64SliceFlag) Names() []string
Names returns the names of the flag
func (f *Int64SliceFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *Int64SliceFlag) SetDestination(slice []int64)
func (f *Int64SliceFlag) SetValue(slice []int64)
@ -1342,6 +1370,9 @@ func (f *IntFlag) IsVisible() bool
func (f *IntFlag) Names() []string
Names returns the names of the flag
func (f *IntFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *IntFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1431,6 +1462,9 @@ func (f *IntSliceFlag) IsVisible() bool
func (f *IntSliceFlag) Names() []string
Names returns the names of the flag
func (f *IntSliceFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *IntSliceFlag) SetDestination(slice []int)
func (f *IntSliceFlag) SetValue(slice []int)
@ -1531,6 +1565,9 @@ func (f *PathFlag) IsVisible() bool
func (f *PathFlag) Names() []string
Names returns the names of the flag
func (f *PathFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *PathFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1668,6 +1705,9 @@ func (f *StringFlag) IsVisible() bool
func (f *StringFlag) Names() []string
Names returns the names of the flag
func (f *StringFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *StringFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1755,6 +1795,9 @@ func (f *StringSliceFlag) IsVisible() bool
func (f *StringSliceFlag) Names() []string
Names returns the names of the flag
func (f *StringSliceFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *StringSliceFlag) SetDestination(slice []string)
func (f *StringSliceFlag) SetValue(slice []string)
@ -1856,6 +1899,9 @@ func (f *TimestampFlag) IsVisible() bool
func (f *TimestampFlag) Names() []string
Names returns the names of the flag
func (f *TimestampFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *TimestampFlag) String() string
String returns a readable representation of this value (for usage defaults)
@ -1918,6 +1964,9 @@ func (f *Uint64Flag) IsVisible() bool
func (f *Uint64Flag) Names() []string
Names returns the names of the flag
func (f *Uint64Flag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *Uint64Flag) String() string
String returns a readable representation of this value (for usage defaults)
@ -2063,6 +2112,9 @@ func (f *UintFlag) IsVisible() bool
func (f *UintFlag) Names() []string
Names returns the names of the flag
func (f *UintFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *UintFlag) String() string
String returns a readable representation of this value (for usage defaults)

@ -22,6 +22,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
@ -64,6 +66,8 @@ type GenericFlag struct {
EnvVars []string
TakesFile bool
Action func(*Context, interface{}) error
}
// String returns a readable representation of this value (for usage defaults)
@ -109,6 +113,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
@ -149,6 +155,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
@ -191,6 +199,8 @@ type PathFlag struct {
EnvVars []string
TakesFile bool
Action func(*Context, Path) error
}
// String returns a readable representation of this value (for usage defaults)
@ -238,6 +248,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
@ -282,6 +294,8 @@ type TimestampFlag struct {
Layout string
Timezone *time.Location
Action func(*Context, *time.Time) error
}
// String returns a readable representation of this value (for usage defaults)
@ -327,6 +341,8 @@ type Uint64SliceFlag struct {
Aliases []string
EnvVars []string
Action func(*Context, []uint64) error
}
// IsSet returns whether or not the flag has been set through env or file
@ -367,6 +383,8 @@ type UintSliceFlag struct {
Aliases []string
EnvVars []string
Action func(*Context, []uint) error
}
// IsSet returns whether or not the flag has been set through env or file
@ -409,6 +427,8 @@ type BoolFlag struct {
EnvVars []string
Count *int
Action func(*Context, bool) error
}
// String returns a readable representation of this value (for usage defaults)
@ -454,6 +474,8 @@ type Float64Flag struct {
Aliases []string
EnvVars []string
Action func(*Context, float64) error
}
// String returns a readable representation of this value (for usage defaults)
@ -501,6 +523,8 @@ type IntFlag struct {
EnvVars []string
Base int
Action func(*Context, int) error
}
// String returns a readable representation of this value (for usage defaults)
@ -548,6 +572,8 @@ type Int64Flag struct {
EnvVars []string
Base int
Action func(*Context, int64) error
}
// String returns a readable representation of this value (for usage defaults)
@ -595,6 +621,8 @@ type StringFlag struct {
EnvVars []string
TakesFile bool
Action func(*Context, string) error
}
// String returns a readable representation of this value (for usage defaults)
@ -640,6 +668,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)
@ -687,6 +717,8 @@ type UintFlag struct {
EnvVars []string
Base int
Action func(*Context, uint) error
}
// String returns a readable representation of this value (for usage defaults)
@ -734,6 +766,8 @@ type Uint64Flag struct {
EnvVars []string
Base int
Action func(*Context, uint64) error
}
// String returns a readable representation of this value (for usage defaults)

Loading…
Cancel
Save