Skip to content

Commit

Permalink
Refactor flag parsing due to missing index. Fixes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Oct 6, 2020
1 parent 95ee16d commit 0850c82
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions gum/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func ParseArgs(args []string) ParsedArgs {
}

func isGumFlag(flag string) bool {
for i := range gumFlags {
if flag[1:] == gumFlags[i] {
for _, f := range gumFlags {
if flag[1:] == f {
return true
}
}
Expand All @@ -99,8 +99,7 @@ func findFlagValue(flag string, args []string) (bool, string, []string) {
return false, "", args
}

for i := range args {
s := args[i]
for i, s := range args {
if flag == s {
// next argument should contain the value we want
if i+1 < len(args) {
Expand All @@ -122,9 +121,9 @@ func shrinkSlice(s []string, index int, length int) []string {
shrunk := make([]string, len(s)-length)

j := 0
for i := range s {
if i < index || i > index+length {
shrunk[j] = s[i]
for i, e := range s {
if i < index || i >= index+length {
shrunk[j] = e
j = j + 1
}
}
Expand All @@ -135,8 +134,7 @@ func shrinkSlice(s []string, index int, length int) []string {
func replaceArgs(args []string, replacements map[string]string, allowsSubMatch bool) []string {
nargs := make([]string, 0)

for i := range args {
key := args[i]
for _, key := range args {
exactMatch := replacements[key]

subMatch := ""
Expand Down

0 comments on commit 0850c82

Please sign in to comment.