Skip to content

Commit 2d1634c

Browse files
authored
Merge pull request #1412 from urfave/update-v2-docs
Update the v2 docs since merging #1409
2 parents 8007c54 + 3082652 commit 2d1634c

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

godoc-current.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ func (f *Float64SliceFlag) GetCategory() string
10031003
func (f *Float64SliceFlag) GetDefaultText() string
10041004
GetDefaultText returns the default text for this flag
10051005

1006+
func (f *Float64SliceFlag) GetDestination() []float64
1007+
10061008
func (f *Float64SliceFlag) GetEnvVars() []string
10071009
GetEnvVars returns the env vars for this flag
10081010

@@ -1025,6 +1027,10 @@ func (f *Float64SliceFlag) IsVisible() bool
10251027
func (f *Float64SliceFlag) Names() []string
10261028
Names returns the names of the flag
10271029

1030+
func (f *Float64SliceFlag) SetDestination(slice []float64)
1031+
1032+
func (f *Float64SliceFlag) SetValue(slice []float64)
1033+
10281034
func (f *Float64SliceFlag) String() string
10291035
String returns a readable representation of this value (for usage defaults)
10301036

@@ -1215,6 +1221,8 @@ func (f *Int64SliceFlag) GetCategory() string
12151221
func (f *Int64SliceFlag) GetDefaultText() string
12161222
GetDefaultText returns the default text for this flag
12171223

1224+
func (f *Int64SliceFlag) GetDestination() []int64
1225+
12181226
func (f *Int64SliceFlag) GetEnvVars() []string
12191227
GetEnvVars returns the env vars for this flag
12201228

@@ -1237,6 +1245,10 @@ func (f *Int64SliceFlag) IsVisible() bool
12371245
func (f *Int64SliceFlag) Names() []string
12381246
Names returns the names of the flag
12391247

1248+
func (f *Int64SliceFlag) SetDestination(slice []int64)
1249+
1250+
func (f *Int64SliceFlag) SetValue(slice []int64)
1251+
12401252
func (f *Int64SliceFlag) String() string
12411253
String returns a readable representation of this value (for usage defaults)
12421254

@@ -1362,6 +1374,8 @@ func (f *IntSliceFlag) GetCategory() string
13621374
func (f *IntSliceFlag) GetDefaultText() string
13631375
GetDefaultText returns the default text for this flag
13641376

1377+
func (f *IntSliceFlag) GetDestination() []int
1378+
13651379
func (f *IntSliceFlag) GetEnvVars() []string
13661380
GetEnvVars returns the env vars for this flag
13671381

@@ -1384,6 +1398,10 @@ func (f *IntSliceFlag) IsVisible() bool
13841398
func (f *IntSliceFlag) Names() []string
13851399
Names returns the names of the flag
13861400

1401+
func (f *IntSliceFlag) SetDestination(slice []int)
1402+
1403+
func (f *IntSliceFlag) SetValue(slice []int)
1404+
13871405
func (f *IntSliceFlag) String() string
13881406
String returns a readable representation of this value (for usage defaults)
13891407

@@ -1396,6 +1414,22 @@ type MultiError interface {
13961414
}
13971415
MultiError is an error that wraps multiple errors.
13981416

1417+
type MultiFloat64Flag = SliceFlag[*Float64SliceFlag, []float64, float64]
1418+
MultiFloat64Flag extends Float64SliceFlag with support for using slices
1419+
directly, as Value and/or Destination. See also SliceFlag.
1420+
1421+
type MultiInt64Flag = SliceFlag[*Int64SliceFlag, []int64, int64]
1422+
MultiInt64Flag extends Int64SliceFlag with support for using slices
1423+
directly, as Value and/or Destination. See also SliceFlag.
1424+
1425+
type MultiIntFlag = SliceFlag[*IntSliceFlag, []int, int]
1426+
MultiIntFlag extends IntSliceFlag with support for using slices directly, as
1427+
Value and/or Destination. See also SliceFlag.
1428+
1429+
type MultiStringFlag = SliceFlag[*StringSliceFlag, []string, string]
1430+
MultiStringFlag extends StringSliceFlag with support for using slices
1431+
directly, as Value and/or Destination. See also SliceFlag.
1432+
13991433
type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error
14001434
OnUsageErrorFunc is executed if a usage error occurs. This is useful for
14011435
displaying customized usage error messages. This function is able to replace
@@ -1480,6 +1514,67 @@ type Serializer interface {
14801514
}
14811515
Serializer is used to circumvent the limitations of flag.FlagSet.Set
14821516

1517+
type SliceFlag[T SliceFlagTarget[E], S ~[]E, E any] struct {
1518+
Target T
1519+
Value S
1520+
Destination *S
1521+
}
1522+
SliceFlag extends implementations like StringSliceFlag and IntSliceFlag with
1523+
support for using slices directly, as Value and/or Destination. See also
1524+
SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag,
1525+
MultiIntFlag.
1526+
1527+
func (x *SliceFlag[T, S, E]) Apply(set *flag.FlagSet) error
1528+
1529+
func (x *SliceFlag[T, S, E]) GetCategory() string
1530+
1531+
func (x *SliceFlag[T, S, E]) GetDefaultText() string
1532+
1533+
func (x *SliceFlag[T, S, E]) GetDestination() S
1534+
1535+
func (x *SliceFlag[T, S, E]) GetEnvVars() []string
1536+
1537+
func (x *SliceFlag[T, S, E]) GetUsage() string
1538+
1539+
func (x *SliceFlag[T, S, E]) GetValue() string
1540+
1541+
func (x *SliceFlag[T, S, E]) IsRequired() bool
1542+
1543+
func (x *SliceFlag[T, S, E]) IsSet() bool
1544+
1545+
func (x *SliceFlag[T, S, E]) IsVisible() bool
1546+
1547+
func (x *SliceFlag[T, S, E]) Names() []string
1548+
1549+
func (x *SliceFlag[T, S, E]) SetDestination(slice S)
1550+
1551+
func (x *SliceFlag[T, S, E]) SetValue(slice S)
1552+
1553+
func (x *SliceFlag[T, S, E]) String() string
1554+
1555+
func (x *SliceFlag[T, S, E]) TakesValue() bool
1556+
1557+
type SliceFlagTarget[E any] interface {
1558+
Flag
1559+
RequiredFlag
1560+
DocGenerationFlag
1561+
VisibleFlag
1562+
CategorizableFlag
1563+
1564+
// SetValue should propagate the given slice to the target, ideally as a new value.
1565+
// Note that a nil slice should nil/clear any existing value (modelled as ~[]E).
1566+
SetValue(slice []E)
1567+
// SetDestination should propagate the given slice to the target, ideally as a new value.
1568+
// Note that a nil slice should nil/clear any existing value (modelled as ~*[]E).
1569+
SetDestination(slice []E)
1570+
// GetDestination should return the current value referenced by any destination, or nil if nil/unset.
1571+
GetDestination() []E
1572+
}
1573+
SliceFlagTarget models a target implementation for use with SliceFlag. The
1574+
three methods, SetValue, SetDestination, and GetDestination, are necessary
1575+
to propagate Value and Destination, where Value is propagated inwards
1576+
(initially), and Destination is propagated outwards (on every update).
1577+
14831578
type StringFlag struct {
14841579
Name string
14851580

@@ -1599,6 +1694,8 @@ func (f *StringSliceFlag) GetCategory() string
15991694
func (f *StringSliceFlag) GetDefaultText() string
16001695
GetDefaultText returns the default text for this flag
16011696

1697+
func (f *StringSliceFlag) GetDestination() []string
1698+
16021699
func (f *StringSliceFlag) GetEnvVars() []string
16031700
GetEnvVars returns the env vars for this flag
16041701

@@ -1621,6 +1718,10 @@ func (f *StringSliceFlag) IsVisible() bool
16211718
func (f *StringSliceFlag) Names() []string
16221719
Names returns the names of the flag
16231720

1721+
func (f *StringSliceFlag) SetDestination(slice []string)
1722+
1723+
func (f *StringSliceFlag) SetValue(slice []string)
1724+
16241725
func (f *StringSliceFlag) String() string
16251726
String returns a readable representation of this value (for usage defaults)
16261727

testdata/godoc-v2.x.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ func (f *Float64SliceFlag) GetCategory() string
10031003
func (f *Float64SliceFlag) GetDefaultText() string
10041004
GetDefaultText returns the default text for this flag
10051005

1006+
func (f *Float64SliceFlag) GetDestination() []float64
1007+
10061008
func (f *Float64SliceFlag) GetEnvVars() []string
10071009
GetEnvVars returns the env vars for this flag
10081010

@@ -1025,6 +1027,10 @@ func (f *Float64SliceFlag) IsVisible() bool
10251027
func (f *Float64SliceFlag) Names() []string
10261028
Names returns the names of the flag
10271029

1030+
func (f *Float64SliceFlag) SetDestination(slice []float64)
1031+
1032+
func (f *Float64SliceFlag) SetValue(slice []float64)
1033+
10281034
func (f *Float64SliceFlag) String() string
10291035
String returns a readable representation of this value (for usage defaults)
10301036

@@ -1215,6 +1221,8 @@ func (f *Int64SliceFlag) GetCategory() string
12151221
func (f *Int64SliceFlag) GetDefaultText() string
12161222
GetDefaultText returns the default text for this flag
12171223

1224+
func (f *Int64SliceFlag) GetDestination() []int64
1225+
12181226
func (f *Int64SliceFlag) GetEnvVars() []string
12191227
GetEnvVars returns the env vars for this flag
12201228

@@ -1237,6 +1245,10 @@ func (f *Int64SliceFlag) IsVisible() bool
12371245
func (f *Int64SliceFlag) Names() []string
12381246
Names returns the names of the flag
12391247

1248+
func (f *Int64SliceFlag) SetDestination(slice []int64)
1249+
1250+
func (f *Int64SliceFlag) SetValue(slice []int64)
1251+
12401252
func (f *Int64SliceFlag) String() string
12411253
String returns a readable representation of this value (for usage defaults)
12421254

@@ -1362,6 +1374,8 @@ func (f *IntSliceFlag) GetCategory() string
13621374
func (f *IntSliceFlag) GetDefaultText() string
13631375
GetDefaultText returns the default text for this flag
13641376

1377+
func (f *IntSliceFlag) GetDestination() []int
1378+
13651379
func (f *IntSliceFlag) GetEnvVars() []string
13661380
GetEnvVars returns the env vars for this flag
13671381

@@ -1384,6 +1398,10 @@ func (f *IntSliceFlag) IsVisible() bool
13841398
func (f *IntSliceFlag) Names() []string
13851399
Names returns the names of the flag
13861400

1401+
func (f *IntSliceFlag) SetDestination(slice []int)
1402+
1403+
func (f *IntSliceFlag) SetValue(slice []int)
1404+
13871405
func (f *IntSliceFlag) String() string
13881406
String returns a readable representation of this value (for usage defaults)
13891407

@@ -1396,6 +1414,22 @@ type MultiError interface {
13961414
}
13971415
MultiError is an error that wraps multiple errors.
13981416

1417+
type MultiFloat64Flag = SliceFlag[*Float64SliceFlag, []float64, float64]
1418+
MultiFloat64Flag extends Float64SliceFlag with support for using slices
1419+
directly, as Value and/or Destination. See also SliceFlag.
1420+
1421+
type MultiInt64Flag = SliceFlag[*Int64SliceFlag, []int64, int64]
1422+
MultiInt64Flag extends Int64SliceFlag with support for using slices
1423+
directly, as Value and/or Destination. See also SliceFlag.
1424+
1425+
type MultiIntFlag = SliceFlag[*IntSliceFlag, []int, int]
1426+
MultiIntFlag extends IntSliceFlag with support for using slices directly, as
1427+
Value and/or Destination. See also SliceFlag.
1428+
1429+
type MultiStringFlag = SliceFlag[*StringSliceFlag, []string, string]
1430+
MultiStringFlag extends StringSliceFlag with support for using slices
1431+
directly, as Value and/or Destination. See also SliceFlag.
1432+
13991433
type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error
14001434
OnUsageErrorFunc is executed if a usage error occurs. This is useful for
14011435
displaying customized usage error messages. This function is able to replace
@@ -1480,6 +1514,67 @@ type Serializer interface {
14801514
}
14811515
Serializer is used to circumvent the limitations of flag.FlagSet.Set
14821516

1517+
type SliceFlag[T SliceFlagTarget[E], S ~[]E, E any] struct {
1518+
Target T
1519+
Value S
1520+
Destination *S
1521+
}
1522+
SliceFlag extends implementations like StringSliceFlag and IntSliceFlag with
1523+
support for using slices directly, as Value and/or Destination. See also
1524+
SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag,
1525+
MultiIntFlag.
1526+
1527+
func (x *SliceFlag[T, S, E]) Apply(set *flag.FlagSet) error
1528+
1529+
func (x *SliceFlag[T, S, E]) GetCategory() string
1530+
1531+
func (x *SliceFlag[T, S, E]) GetDefaultText() string
1532+
1533+
func (x *SliceFlag[T, S, E]) GetDestination() S
1534+
1535+
func (x *SliceFlag[T, S, E]) GetEnvVars() []string
1536+
1537+
func (x *SliceFlag[T, S, E]) GetUsage() string
1538+
1539+
func (x *SliceFlag[T, S, E]) GetValue() string
1540+
1541+
func (x *SliceFlag[T, S, E]) IsRequired() bool
1542+
1543+
func (x *SliceFlag[T, S, E]) IsSet() bool
1544+
1545+
func (x *SliceFlag[T, S, E]) IsVisible() bool
1546+
1547+
func (x *SliceFlag[T, S, E]) Names() []string
1548+
1549+
func (x *SliceFlag[T, S, E]) SetDestination(slice S)
1550+
1551+
func (x *SliceFlag[T, S, E]) SetValue(slice S)
1552+
1553+
func (x *SliceFlag[T, S, E]) String() string
1554+
1555+
func (x *SliceFlag[T, S, E]) TakesValue() bool
1556+
1557+
type SliceFlagTarget[E any] interface {
1558+
Flag
1559+
RequiredFlag
1560+
DocGenerationFlag
1561+
VisibleFlag
1562+
CategorizableFlag
1563+
1564+
// SetValue should propagate the given slice to the target, ideally as a new value.
1565+
// Note that a nil slice should nil/clear any existing value (modelled as ~[]E).
1566+
SetValue(slice []E)
1567+
// SetDestination should propagate the given slice to the target, ideally as a new value.
1568+
// Note that a nil slice should nil/clear any existing value (modelled as ~*[]E).
1569+
SetDestination(slice []E)
1570+
// GetDestination should return the current value referenced by any destination, or nil if nil/unset.
1571+
GetDestination() []E
1572+
}
1573+
SliceFlagTarget models a target implementation for use with SliceFlag. The
1574+
three methods, SetValue, SetDestination, and GetDestination, are necessary
1575+
to propagate Value and Destination, where Value is propagated inwards
1576+
(initially), and Destination is propagated outwards (on every update).
1577+
14831578
type StringFlag struct {
14841579
Name string
14851580

@@ -1599,6 +1694,8 @@ func (f *StringSliceFlag) GetCategory() string
15991694
func (f *StringSliceFlag) GetDefaultText() string
16001695
GetDefaultText returns the default text for this flag
16011696

1697+
func (f *StringSliceFlag) GetDestination() []string
1698+
16021699
func (f *StringSliceFlag) GetEnvVars() []string
16031700
GetEnvVars returns the env vars for this flag
16041701

@@ -1621,6 +1718,10 @@ func (f *StringSliceFlag) IsVisible() bool
16211718
func (f *StringSliceFlag) Names() []string
16221719
Names returns the names of the flag
16231720

1721+
func (f *StringSliceFlag) SetDestination(slice []string)
1722+
1723+
func (f *StringSliceFlag) SetValue(slice []string)
1724+
16241725
func (f *StringSliceFlag) String() string
16251726
String returns a readable representation of this value (for usage defaults)
16261727

0 commit comments

Comments
 (0)