Skip to content

Instantly share code, notes, and snippets.

@crhntr
Created August 26, 2016 06:38
Show Gist options
  • Save crhntr/4c7d543e3d0c5c78596f34a4114d53c7 to your computer and use it in GitHub Desktop.
Save crhntr/4c7d543e3d0c5c78596f34a4114d53c7 to your computer and use it in GitHub Desktop.
// 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