Add Args.Swap command for swapping arguments
The usecase: my-cli user <USERID> set <FIELD> <VALUE> Being able to swap <USERID> with set argument, we can have nested subcommands while preserving all variable arguments along the way.
This commit is contained in:
parent
d38a3b82a6
commit
6f8cfa703a
@ -140,6 +140,15 @@ func (a Args) Present() bool {
|
||||
return len(a) != 0
|
||||
}
|
||||
|
||||
// Swaps arguments at the given indexes
|
||||
func (a Args) Swap(from, to int) error {
|
||||
if from >= len(a) || to >= len(a) {
|
||||
return errors.New("index out of range")
|
||||
}
|
||||
a[from], a[to] = a[to], a[from]
|
||||
return nil
|
||||
}
|
||||
|
||||
func lookupInt(name string, set *flag.FlagSet) int {
|
||||
f := set.Lookup(name)
|
||||
if f != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user