You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2016/04/21 08:35:25 UTC
[jira] [Resolved] (GROOVY-6538) Support default value for
OptionAccessor.getProperty()
[ https://issues.apache.org/jira/browse/GROOVY-6538?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King resolved GROOVY-6538.
-------------------------------
Resolution: Fixed
Assignee: Paul King
Fix Version/s: 2.5.0-beta-1
I am going to close this. There is now some minimal CLI default value support in the upcoming 2.5 beta. Perhaps it isn't exactly as envisaged by this issue but I think any further work if needed should be re-cast as an enhancement to the currently provided feature.
> 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-beta-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.4#6332)