Created
February 4, 2010 21:37
-
-
Save cl4rk3/295145 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
args?.tokenize().each {token -> | |
def nameValueSwitch = token =~ '--?(.*)=(.*)' | |
if (nameValueSwitch.matches()) { // this token is a name/value pair (ex: --foo=bar or -z=qux) | |
println nameValueSwitch | |
argsMap[nameValueSwitch[0][1]] = nameValueSwitch[0][2] | |
} | |
else { | |
def nameOnlySwitch = token =~ "--?(.*)" | |
if (nameOnlySwitch.matches()) { // this token is just a switch (ex: -force or --help) | |
argsMap[nameOnlySwitch[0][1]] = true | |
} | |
else { // single item tokens, append in order to an array of params | |
argsMap["params"] << token | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment