Created
August 26, 2016 06:38
-
-
Save crhntr/4c7d543e3d0c5c78596f34a4114d53c7 to your computer and use it in GitHub Desktop.
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
// parseArgs(os.Args) | |
func parsArgs(args []string) ([]string, map[string][]string) { | |
argMap := make(map[string][]string) | |
arguments := []string{} | |
for i := 1; i < len(args); { | |
if args[i][0] == '-' { | |
j := i + 1 | |
argMap[args[i][1:]] = []string{} | |
for j = i + 1; j < len(args) && len(args[j]) > 0 && args[j][0] != '-'; j++ { | |
argMap[args[i][1:]] = append(argMap[args[i][1:]], args[j]) | |
} | |
i = j | |
} else { | |
arguments = append(arguments, args[i]) | |
i++ | |
} | |
} | |
return arguments, argMap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment