@@ -1003,6 +1003,8 @@ func (f *Float64SliceFlag) GetCategory() string
1003
1003
func (f *Float64SliceFlag) GetDefaultText() string
1004
1004
GetDefaultText returns the default text for this flag
1005
1005
1006
+ func (f *Float64SliceFlag) GetDestination() []float64
1007
+
1006
1008
func (f *Float64SliceFlag) GetEnvVars() []string
1007
1009
GetEnvVars returns the env vars for this flag
1008
1010
@@ -1025,6 +1027,10 @@ func (f *Float64SliceFlag) IsVisible() bool
1025
1027
func (f *Float64SliceFlag) Names() []string
1026
1028
Names returns the names of the flag
1027
1029
1030
+ func (f *Float64SliceFlag) SetDestination(slice []float64)
1031
+
1032
+ func (f *Float64SliceFlag) SetValue(slice []float64)
1033
+
1028
1034
func (f *Float64SliceFlag) String() string
1029
1035
String returns a readable representation of this value (for usage defaults)
1030
1036
@@ -1215,6 +1221,8 @@ func (f *Int64SliceFlag) GetCategory() string
1215
1221
func (f *Int64SliceFlag) GetDefaultText() string
1216
1222
GetDefaultText returns the default text for this flag
1217
1223
1224
+ func (f *Int64SliceFlag) GetDestination() []int64
1225
+
1218
1226
func (f *Int64SliceFlag) GetEnvVars() []string
1219
1227
GetEnvVars returns the env vars for this flag
1220
1228
@@ -1237,6 +1245,10 @@ func (f *Int64SliceFlag) IsVisible() bool
1237
1245
func (f *Int64SliceFlag) Names() []string
1238
1246
Names returns the names of the flag
1239
1247
1248
+ func (f *Int64SliceFlag) SetDestination(slice []int64)
1249
+
1250
+ func (f *Int64SliceFlag) SetValue(slice []int64)
1251
+
1240
1252
func (f *Int64SliceFlag) String() string
1241
1253
String returns a readable representation of this value (for usage defaults)
1242
1254
@@ -1362,6 +1374,8 @@ func (f *IntSliceFlag) GetCategory() string
1362
1374
func (f *IntSliceFlag) GetDefaultText() string
1363
1375
GetDefaultText returns the default text for this flag
1364
1376
1377
+ func (f *IntSliceFlag) GetDestination() []int
1378
+
1365
1379
func (f *IntSliceFlag) GetEnvVars() []string
1366
1380
GetEnvVars returns the env vars for this flag
1367
1381
@@ -1384,6 +1398,10 @@ func (f *IntSliceFlag) IsVisible() bool
1384
1398
func (f *IntSliceFlag) Names() []string
1385
1399
Names returns the names of the flag
1386
1400
1401
+ func (f *IntSliceFlag) SetDestination(slice []int)
1402
+
1403
+ func (f *IntSliceFlag) SetValue(slice []int)
1404
+
1387
1405
func (f *IntSliceFlag) String() string
1388
1406
String returns a readable representation of this value (for usage defaults)
1389
1407
@@ -1396,6 +1414,22 @@ type MultiError interface {
1396
1414
}
1397
1415
MultiError is an error that wraps multiple errors.
1398
1416
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
+
1399
1433
type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error
1400
1434
OnUsageErrorFunc is executed if a usage error occurs. This is useful for
1401
1435
displaying customized usage error messages. This function is able to replace
@@ -1480,6 +1514,67 @@ type Serializer interface {
1480
1514
}
1481
1515
Serializer is used to circumvent the limitations of flag.FlagSet.Set
1482
1516
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
+
1483
1578
type StringFlag struct {
1484
1579
Name string
1485
1580
@@ -1599,6 +1694,8 @@ func (f *StringSliceFlag) GetCategory() string
1599
1694
func (f *StringSliceFlag) GetDefaultText() string
1600
1695
GetDefaultText returns the default text for this flag
1601
1696
1697
+ func (f *StringSliceFlag) GetDestination() []string
1698
+
1602
1699
func (f *StringSliceFlag) GetEnvVars() []string
1603
1700
GetEnvVars returns the env vars for this flag
1604
1701
@@ -1621,6 +1718,10 @@ func (f *StringSliceFlag) IsVisible() bool
1621
1718
func (f *StringSliceFlag) Names() []string
1622
1719
Names returns the names of the flag
1623
1720
1721
+ func (f *StringSliceFlag) SetDestination(slice []string)
1722
+
1723
+ func (f *StringSliceFlag) SetValue(slice []string)
1724
+
1624
1725
func (f *StringSliceFlag) String() string
1625
1726
String returns a readable representation of this value (for usage defaults)
1626
1727
0 commit comments