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 May 22, 2022
1 parent c9d9735 commit 97af685
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 47 deletions.
2 changes: 1 addition & 1 deletion altsrc/yaml_file_loader.go
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/urfave/cli/v2"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

type yamlSourceContext struct {
Expand Down
40 changes: 32 additions & 8 deletions flag-spec.yaml
Expand Up @@ -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: {}
Expand Down
28 changes: 2 additions & 26 deletions flag_int_slice.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -176,19 +153,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)
}

// IntSlice looks up the value of a local IntSliceFlag, returns
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
12 changes: 2 additions & 10 deletions 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=
2 changes: 1 addition & 1 deletion internal/genflags/cmd/genflags/main.go
Expand Up @@ -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 (
Expand Down
30 changes: 30 additions & 0 deletions zz_generated.flags.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 97af685

Please sign in to comment.