mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 01:35:17 +02:00
Update registryTool task to better handle command line arguments (#273)
* Update registryTool task to better handle command line arguments Tokens are delimited by pipes and can be escaped. If we use -args directly, we will not be able to escape the delimiter, if both the double and single quotes happen to be present in the arguments. See: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/JavaExec.html#setArgsString-java.lang.String-
This commit is contained in:
parent
8f5bd5da01
commit
3764e2b26c
1 changed files with 31 additions and 2 deletions
|
@ -592,11 +592,40 @@ task findGoldenImages(type: JavaExec) {
|
|||
args arguments
|
||||
}
|
||||
|
||||
// To run the nomulus tool:
|
||||
// gradle registryTool --args="foo --bar"
|
||||
// To run the nomulus tool with these command line tokens:
|
||||
// "--foo", "bar baz", "--qux=quz"
|
||||
// gradle registryTool --args="--foo 'bar baz' --qux=quz"
|
||||
// or:
|
||||
// gradle registryTool --PtoolArgs="--foo|bar baz|--qux=quz"
|
||||
// Note that the delimiting pipe can be backslash escaped if it is part of a
|
||||
// parameter.
|
||||
task registryTool(type: JavaExec) {
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
main = 'google.registry.tools.RegistryTool'
|
||||
|
||||
// If "-PtoolArgs=..." is present in the command line, use it to set the args,
|
||||
// otherwise use the default flag, which is "--args" to set the args.
|
||||
doFirst {
|
||||
def toolArgs = rootProject.findProperty("toolArgs")
|
||||
if (toolArgs != null) {
|
||||
def delimiter = '|'
|
||||
toolArgs += delimiter
|
||||
def argsList = []
|
||||
def currArg = ''
|
||||
for (def i = 0; i < toolArgs.length(); i++) {
|
||||
def currChar = toolArgs[i]
|
||||
if (currChar != delimiter) {
|
||||
currArg += currChar
|
||||
} else if (i != 0 && toolArgs[i - 1] == '\\') {
|
||||
currArg = currArg.substring(0, currArg.length() - 1) + currChar
|
||||
} else {
|
||||
argsList.add(currArg)
|
||||
currArg = ''
|
||||
}
|
||||
}
|
||||
args = argsList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task generateGoldenImages(type: Test) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue