Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Sep 10, 2022
1 parent f8b9a7c commit f11dfa6
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 25 deletions.
23 changes: 0 additions & 23 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"regexp"
"runtime"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -324,28 +323,6 @@ func stringifyFlag(f Flag) string {
fmt.Sprintf("%s\t%s", prefixedNames(df.Names(), placeholder), usageWithDefault))
}

func stringifyUintSliceFlag(f *UintSliceFlag) string {
var defaultVals []string
if f.Value != nil && len(f.Value.Value()) > 0 {
for _, i := range f.Value.Value() {
defaultVals = append(defaultVals, strconv.FormatUint(uint64(i), 10))
}
}

return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
}

func stringifyUint64SliceFlag(f *Uint64SliceFlag) string {
var defaultVals []string
if f.Value != nil && len(f.Value.Value()) > 0 {
for _, i := range f.Value.Value() {
defaultVals = append(defaultVals, strconv.FormatUint(i, 10))
}
}

return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
}

func stringifySliceFlag(usage string, names, defaultVals []string) string {
placeholder, usage := unquoteUsage(usage)
if placeholder == "" {
Expand Down
13 changes: 12 additions & 1 deletion flag_uint64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (i *Uint64Slice) Get() interface{} {
// String returns a readable representation of this value
// (for usage defaults)
func (f *Uint64SliceFlag) String() string {
return withEnvHint(f.GetEnvVars(), stringifyUint64SliceFlag(f))
return withEnvHint(f.GetEnvVars(), f.stringify())
}

// TakesValue returns true of the flag takes a value, otherwise false
Expand Down Expand Up @@ -172,6 +172,17 @@ func (f *Uint64SliceFlag) Get(ctx *Context) []uint64 {
return ctx.Uint64Slice(f.Name)
}

func (f *Uint64SliceFlag) stringify() string {
var defaultVals []string
if f.Value != nil && len(f.Value.Value()) > 0 {
for _, i := range f.Value.Value() {
defaultVals = append(defaultVals, strconv.FormatUint(i, 10))
}
}

return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
}

// Uint64Slice looks up the value of a local Uint64SliceFlag, returns
// nil if not found
func (cCtx *Context) Uint64Slice(name string) []uint64 {
Expand Down
13 changes: 12 additions & 1 deletion flag_uint_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (i *UintSlice) Get() interface{} {
// String returns a readable representation of this value
// (for usage defaults)
func (f *UintSliceFlag) String() string {
return withEnvHint(f.GetEnvVars(), stringifyUintSliceFlag(f))
return withEnvHint(f.GetEnvVars(), f.stringify())
}

// TakesValue returns true of the flag takes a value, otherwise false
Expand Down Expand Up @@ -183,6 +183,17 @@ func (f *UintSliceFlag) Get(ctx *Context) []uint {
return ctx.UintSlice(f.Name)
}

func (f *UintSliceFlag) stringify() string {
var defaultVals []string
if f.Value != nil && len(f.Value.Value()) > 0 {
for _, i := range f.Value.Value() {
defaultVals = append(defaultVals, strconv.FormatUint(uint64(i), 10))
}
}

return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
}

// UintSlice looks up the value of a local UintSliceFlag, returns
// nil if not found
func (cCtx *Context) UintSlice(name string) []uint {
Expand Down
178 changes: 178 additions & 0 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ func (cCtx *Context) Uint(name string) uint
func (cCtx *Context) Uint64(name string) uint64
Uint64 looks up the value of a local Uint64Flag, returns 0 if not found

func (cCtx *Context) Uint64Slice(name string) []uint64
Uint64Slice looks up the value of a local Uint64SliceFlag, returns nil if
not found

func (cCtx *Context) UintSlice(name string) []uint
UintSlice looks up the value of a local UintSliceFlag, returns nil if not
found

func (cCtx *Context) Value(name string) interface{}
Value returns the value of the flag corresponding to `name`

Expand Down Expand Up @@ -1916,6 +1924,89 @@ func (f *Uint64Flag) String() string
func (f *Uint64Flag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false

type Uint64Slice struct {
// Has unexported fields.
}
Uint64Slice wraps []int64 to satisfy flag.Value

func NewUint64Slice(defaults ...uint64) *Uint64Slice
NewUint64Slice makes an *Uint64Slice with default values

func (i *Uint64Slice) Get() interface{}
Get returns the slice of ints set by this flag

func (i *Uint64Slice) Serialize() string
Serialize allows Uint64Slice to fulfill Serializer

func (i *Uint64Slice) Set(value string) error
Set parses the value into an integer and appends it to the list of values

func (i *Uint64Slice) String() string
String returns a readable representation of this value (for usage defaults)

func (i *Uint64Slice) Value() []uint64
Value returns the slice of ints set by this flag

type Uint64SliceFlag struct {
Name string

Category string
DefaultText string
FilePath string
Usage string

Required bool
Hidden bool
HasBeenSet bool

Value *Uint64Slice
Destination *Uint64Slice

Aliases []string
EnvVars []string
}
Uint64SliceFlag is a flag with type *Uint64Slice

func (f *Uint64SliceFlag) Apply(set *flag.FlagSet) error
Apply populates the flag given the flag set and environment

func (f *Uint64SliceFlag) Get(ctx *Context) []uint64
Get returns the flag’s value in the given Context.

func (f *Uint64SliceFlag) GetCategory() string
GetCategory returns the category for the flag

func (f *Uint64SliceFlag) GetDefaultText() string
GetDefaultText returns the default text for this flag

func (f *Uint64SliceFlag) GetEnvVars() []string
GetEnvVars returns the env vars for this flag

func (f *Uint64SliceFlag) GetUsage() string
GetUsage returns the usage string for the flag

func (f *Uint64SliceFlag) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.

func (f *Uint64SliceFlag) IsRequired() bool
IsRequired returns whether or not the flag is required

func (f *Uint64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Uint64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

func (f *Uint64SliceFlag) Names() []string
Names returns the names of the flag

func (f *Uint64SliceFlag) String() string
String returns a readable representation of this value (for usage defaults)

func (f *Uint64SliceFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false

type UintFlag struct {
Name string

Expand Down Expand Up @@ -1978,6 +2069,93 @@ func (f *UintFlag) String() string
func (f *UintFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false

type UintSlice struct {
// Has unexported fields.
}
UintSlice wraps []int to satisfy flag.Value

func NewUintSlice(defaults ...uint) *UintSlice
NewUintSlice makes an *UintSlice with default values

func (i *UintSlice) Get() interface{}
Get returns the slice of ints set by this flag

func (i *UintSlice) Serialize() string
Serialize allows UintSlice to fulfill Serializer

func (i *UintSlice) Set(value string) error
Set parses the value into an integer and appends it to the list of values

func (i *UintSlice) SetUint(value uint)
TODO: Consistently have specific Set function for Int64 and Float64 ? SetInt
directly adds an integer to the list of values

func (i *UintSlice) String() string
String returns a readable representation of this value (for usage defaults)

func (i *UintSlice) Value() []uint
Value returns the slice of ints set by this flag

type UintSliceFlag struct {
Name string

Category string
DefaultText string
FilePath string
Usage string

Required bool
Hidden bool
HasBeenSet bool

Value *UintSlice
Destination *UintSlice

Aliases []string
EnvVars []string
}
UintSliceFlag is a flag with type *UintSlice

func (f *UintSliceFlag) Apply(set *flag.FlagSet) error
Apply populates the flag given the flag set and environment

func (f *UintSliceFlag) Get(ctx *Context) []uint
Get returns the flag’s value in the given Context.

func (f *UintSliceFlag) GetCategory() string
GetCategory returns the category for the flag

func (f *UintSliceFlag) GetDefaultText() string
GetDefaultText returns the default text for this flag

func (f *UintSliceFlag) GetEnvVars() []string
GetEnvVars returns the env vars for this flag

func (f *UintSliceFlag) GetUsage() string
GetUsage returns the usage string for the flag

func (f *UintSliceFlag) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.

func (f *UintSliceFlag) IsRequired() bool
IsRequired returns whether or not the flag is required

func (f *UintSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *UintSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

func (f *UintSliceFlag) Names() []string
Names returns the names of the flag

func (f *UintSliceFlag) String() string
String returns a readable representation of this value (for usage defaults)

func (f *UintSliceFlag) TakesValue() bool
TakesValue returns true of the flag takes a value, otherwise false

type VisibleFlag interface {
Flag

Expand Down
80 changes: 80 additions & 0 deletions zz_generated.flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,86 @@ func (f *TimestampFlag) IsVisible() bool {
return !f.Hidden
}

// Uint64SliceFlag is a flag with type *Uint64Slice
type Uint64SliceFlag struct {
Name string

Category string
DefaultText string
FilePath string
Usage string

Required bool
Hidden bool
HasBeenSet bool

Value *Uint64Slice
Destination *Uint64Slice

Aliases []string
EnvVars []string
}

// IsSet returns whether or not the flag has been set through env or file
func (f *Uint64SliceFlag) IsSet() bool {
return f.HasBeenSet
}

// Names returns the names of the flag
func (f *Uint64SliceFlag) Names() []string {
return FlagNames(f.Name, f.Aliases)
}

// IsRequired returns whether or not the flag is required
func (f *Uint64SliceFlag) IsRequired() bool {
return f.Required
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *Uint64SliceFlag) IsVisible() bool {
return !f.Hidden
}

// UintSliceFlag is a flag with type *UintSlice
type UintSliceFlag struct {
Name string

Category string
DefaultText string
FilePath string
Usage string

Required bool
Hidden bool
HasBeenSet bool

Value *UintSlice
Destination *UintSlice

Aliases []string
EnvVars []string
}

// IsSet returns whether or not the flag has been set through env or file
func (f *UintSliceFlag) IsSet() bool {
return f.HasBeenSet
}

// Names returns the names of the flag
func (f *UintSliceFlag) Names() []string {
return FlagNames(f.Name, f.Aliases)
}

// IsRequired returns whether or not the flag is required
func (f *UintSliceFlag) IsRequired() bool {
return f.Required
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *UintSliceFlag) IsVisible() bool {
return !f.Hidden
}

// BoolFlag is a flag with type bool
type BoolFlag struct {
Name string
Expand Down
Loading

0 comments on commit f11dfa6

Please sign in to comment.