Skip to content

Instantly share code, notes, and snippets.

@cl4rk3
Created February 4, 2010 21:37
Show Gist options
  • Save cl4rk3/295145 to your computer and use it in GitHub Desktop.
Save cl4rk3/295145 to your computer and use it in GitHub Desktop.
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