docs
This commit is contained in:
parent
6da413ad82
commit
bfdd794eb3
28
command.go
28
command.go
@ -220,7 +220,7 @@ func reorderArgs(commandFlags []Flag, args []string) []string {
|
|||||||
var remainingArgs []string
|
var remainingArgs []string
|
||||||
var reorderedArgs []string
|
var reorderedArgs []string
|
||||||
|
|
||||||
readFlagValue := false
|
nextIndexMayContainValue := false
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
|
|
||||||
// dont reorder any args after a --
|
// dont reorder any args after a --
|
||||||
@ -229,28 +229,30 @@ func reorderArgs(commandFlags []Flag, args []string) []string {
|
|||||||
if arg == "--" {
|
if arg == "--" {
|
||||||
remainingArgs = append(remainingArgs, args[i:]...)
|
remainingArgs = append(remainingArgs, args[i:]...)
|
||||||
break
|
break
|
||||||
}
|
|
||||||
|
|
||||||
if readFlagValue && !strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") {
|
// checks if this arg is a value that should be re-ordered next to its associated flag
|
||||||
readFlagValue = false
|
} else if nextIndexMayContainValue && !strings.HasPrefix(arg, "-") {
|
||||||
reorderedArgs = append(reorderedArgs, arg)
|
nextIndexMayContainValue = false
|
||||||
continue
|
|
||||||
}
|
|
||||||
readFlagValue = false
|
|
||||||
|
|
||||||
if arg != "-" && strings.HasPrefix(arg, "-") && argIsFlag(commandFlags, arg) {
|
|
||||||
reorderedArgs = append(reorderedArgs, arg)
|
reorderedArgs = append(reorderedArgs, arg)
|
||||||
|
|
||||||
readFlagValue = !strings.Contains(arg, "=")
|
// checks if this is an arg that should be re-ordered
|
||||||
continue
|
} else if arg != "-" && strings.HasPrefix(arg, "-") && argIsFlag(commandFlags, arg) {
|
||||||
}
|
|
||||||
|
|
||||||
|
// we have determined that this is a flag that we should re-order
|
||||||
|
reorderedArgs = append(reorderedArgs, arg)
|
||||||
|
// if this arg does not contain a "=", then the next index may contain the value for this flag
|
||||||
|
nextIndexMayContainValue = !strings.Contains(arg, "=")
|
||||||
|
|
||||||
|
// simply append any remaining args
|
||||||
|
} else {
|
||||||
remainingArgs = append(remainingArgs, arg)
|
remainingArgs = append(remainingArgs, arg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return append(reorderedArgs, remainingArgs...)
|
return append(reorderedArgs, remainingArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// argIsFlag checks if an arg is one of our command flags
|
||||||
func argIsFlag(commandFlags []Flag, arg string) bool {
|
func argIsFlag(commandFlags []Flag, arg string) bool {
|
||||||
// this line turns `--flag` into `flag`
|
// this line turns `--flag` into `flag`
|
||||||
arg = strings.Replace(arg, "-", "", -1)
|
arg = strings.Replace(arg, "-", "", -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user