[ https://issues.apache.org/jira/browse/GROOVY-6538?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-6538. ----------------------------- > Support default value for OptionAccessor.getProperty() > ------------------------------------------------------ > > Key: GROOVY-6538 > URL: https://issues.apache.org/jira/browse/GROOVY-6538 > Project: Groovy > Issue Type: Improvement > Components: command line processing > Affects Versions: 2.2.1 > Reporter: Björn Kautler > Assignee: Paul King > Labels: CliBuilder > Fix For: 2.5.0-alpha-1 > > > When retrieving an argument from the OptionAccessor, it would be nice to be > able to give a default value that is returned if hasValue() in > OptionAccessor.getProperty() returned false > Currently to you have to do something like > {code} > def cliBuilder = new CliBuilder() > cliBuilder.d longOpt: 'directory', args: 1, 'd option' > def arguments = cliBuilder.parse args > if (!arguments) { > System.exit 1 > } > def directory > if (arguments.directory) { > directory = arguments.directory > } else { > directory = System.properties.'user.dir' > } > {code} > if would be nicer to instead just do > {code} > def cliBuilder = new CliBuilder() > cliBuilder.d longOpt: 'directory', args: 1, 'd option' > def arguments = cliBuilder.parse args > if (!arguments) { > System.exit 1 > } > def directory = arguments.directory System.properties.'user.dir' > {code} > I think something along the lines of changing > {code} > if (null == result) result = inner.hasOption(name) > if (result instanceof String[]) result = result.toList() > return result > {code} > to > {code} > if (null == result) result = inner.hasOption(name) > if (!result) result = defaultValue > if (result instanceof String[]) result = result.toList() > return result > {code} > should do what I mean. -- This message was sent by Atlassian JIRA (v6.3.15#6346)