Skip to content

Commit

Permalink
Rebase main, update flag-spec.yaml to add Action field
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Sep 15, 2022
1 parent 602471b commit b331176
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 29 deletions.
3 changes: 0 additions & 3 deletions cmd/urfave-cli-genflags/go.sum
@@ -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=
Expand All @@ -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=
Expand Down
41 changes: 41 additions & 0 deletions flag-spec.yaml
Expand Up @@ -7,68 +7,109 @@ 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:
- fmt.Stringer
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:
- name: Layout
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"
28 changes: 2 additions & 26 deletions flag_int_slice.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -197,19 +174,18 @@ 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 {
return f.Action(c, c.IntSlice(f.Name))
}

return nil
>>>>>>> e132f01 (feat: flag action)
}

func (f *IntSliceFlag) stringify() string {
Expand Down
52 changes: 52 additions & 0 deletions godoc-current.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b331176

Please sign in to comment.