-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
10a9286
commit 44a7371
Showing
5 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package misc | ||
|
||
func AddImplicitDoubleDash(args []string) []string { | ||
|
||
newArgs := make([]string, 0, len(args)) | ||
dashesAdded := false | ||
|
||
// This adds a -- before a sort where the next argument starts with a dash. | ||
// -- is a standard shell idiom to turn of flag parsing. | ||
for i := 0; i < len(args); i++ { | ||
if args[i] == "sort" { | ||
if i < len(args)-1 { | ||
nextArg := args[i+1] | ||
if len(nextArg) > 0 { | ||
if nextArg[0] == '-' { | ||
if !dashesAdded { | ||
newArgs = append(newArgs, "sort", "--", nextArg) | ||
i++ | ||
dashesAdded = true | ||
continue | ||
} | ||
} | ||
} | ||
} | ||
} else if args[i] == "--" { | ||
dashesAdded = true | ||
} | ||
newArgs = append(newArgs, args[i]) | ||
|
||
} | ||
|
||
return newArgs | ||
|
||
} |