Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Aug 15, 2022
1 parent 0decf96 commit 6d0c7a8
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 48 deletions.
23 changes: 0 additions & 23 deletions flag.go
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"regexp"
"runtime"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -318,28 +317,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
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
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
224 changes: 201 additions & 23 deletions godoc-current.txt
Expand Up @@ -64,8 +64,8 @@ GLOBAL OPTIONS:
COPYRIGHT:
{{wrap .Copyright 3}}{{end}}
`
AppHelpTemplate is the text template for the Default help topic. cli.go uses
text/template to render templates. You can render custom help text by
AppHelpTemplate is the text template for the Default help topic. cli.go
uses text/template to render templates. You can render custom help text by
setting this variable.

var CommandHelpTemplate = `NAME:
Expand Down Expand Up @@ -201,9 +201,9 @@ func DefaultAppComplete(cCtx *Context)
func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context)
func FlagNames(name string, aliases []string) []string
func HandleAction(action interface{}, cCtx *Context) (err error)
HandleAction attempts to figure out which Action signature was used. If it's
an ActionFunc or a func with the legacy signature for Action, the func is
run!
HandleAction attempts to figure out which Action signature was used.
If it's an ActionFunc or a func with the legacy signature for Action,
the func is run!

func HandleExitCoder(err error)
HandleExitCoder handles errors implementing ExitCoder by printing their
Expand Down Expand Up @@ -360,14 +360,14 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error)
to generate command-specific flags

func (a *App) RunContext(ctx context.Context, arguments []string) (err error)
RunContext is like Run except it takes a Context that will be passed to its
commands and sub-commands. Through this, you can propagate timeouts and
RunContext is like Run except it takes a Context that will be passed to
its commands and sub-commands. Through this, you can propagate timeouts and
cancellation requests

func (a *App) Setup()
Setup runs initialization code to ensure all data structures are ready for
`Run` or inspection prior to `Run`. It is internally called by `Run`, but
will return early if setup has already happened.
Setup runs initialization code to ensure all data structures are ready
for `Run` or inspection prior to `Run`. It is internally called by `Run`,
but will return early if setup has already happened.

func (a *App) ToFishCompletion() (string, error)
ToFishCompletion creates a fish completion string for the `*App` The
Expand Down Expand Up @@ -698,6 +698,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 @@ -799,9 +807,9 @@ func Exit(message interface{}, exitCode int) ExitCoder
Exit wraps a message and exit code into an error, which by default is
handled with a call to os.Exit during default error handling.

This is the simplest way to trigger a non-zero exit code for an App without
having to call os.Exit manually. During testing, this behavior can be
avoided by overiding the ExitErrHandler function on an App or the
This is the simplest way to trigger a non-zero exit code for an App
without having to call os.Exit manually. During testing, this behavior
can be avoided by overiding the ExitErrHandler function on an App or the
package-global OsExiter function.

func NewExitError(message interface{}, exitCode int) ExitCoder
Expand Down Expand Up @@ -1431,8 +1439,8 @@ type MultiInt64Flag = SliceFlag[*Int64SliceFlag, []int64, int64]
directly, as Value and/or Destination. See also SliceFlag.

type MultiIntFlag = SliceFlag[*IntSliceFlag, []int, int]
MultiIntFlag extends IntSliceFlag with support for using slices directly, as
Value and/or Destination. See also SliceFlag.
MultiIntFlag extends IntSliceFlag with support for using slices directly,
as Value and/or Destination. See also SliceFlag.

type MultiStringFlag = SliceFlag[*StringSliceFlag, []string, string]
MultiStringFlag extends StringSliceFlag with support for using slices
Expand Down Expand Up @@ -1513,8 +1521,8 @@ type RequiredFlag interface {

IsRequired() bool
}
RequiredFlag is an interface that allows us to mark flags as required it
allows flags required flags to be backwards compatible with the Flag
RequiredFlag is an interface that allows us to mark flags as required
it allows flags required flags to be backwards compatible with the Flag
interface

type Serializer interface {
Expand All @@ -1527,9 +1535,9 @@ type SliceFlag[T SliceFlagTarget[E], S ~[]E, E any] struct {
Value S
Destination *S
}
SliceFlag extends implementations like StringSliceFlag and IntSliceFlag with
support for using slices directly, as Value and/or Destination. See also
SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag,
SliceFlag extends implementations like StringSliceFlag and IntSliceFlag
with support for using slices directly, as Value and/or Destination.
See also SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag,
MultiIntFlag.

func (x *SliceFlag[T, S, E]) Apply(set *flag.FlagSet) error
Expand Down Expand Up @@ -1893,6 +1901,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 @@ -1953,6 +2044,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 Expand Up @@ -1986,9 +2164,9 @@ func InitInputSource(flags []cli.Flag, createInputSource func() (InputSourceCont
that are supported by the input source

func InitInputSourceWithContext(flags []cli.Flag, createInputSource func(cCtx *cli.Context) (InputSourceContext, error)) cli.BeforeFunc
InitInputSourceWithContext is used to to setup an InputSourceContext on a
cli.Command Before method. It will create a new input source based on the
func provided with potentially using existing cli.Context values to
InitInputSourceWithContext is used to to setup an InputSourceContext on
a cli.Command Before method. It will create a new input source based on
the func provided with potentially using existing cli.Context values to
initialize itself. If there is no error it will then apply the new input
source to any flags that are supported by the input source

Expand Down

0 comments on commit 6d0c7a8

Please sign in to comment.