Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with clibuilder not honoring the type flag GROOVY-9886 #1467

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,14 @@ class CliBuilder {
}
if (args.size() == 2 && args[0] instanceof Map) {
def convert = args[0].remove('convert')
def type = args[0].remove('type')
def type = args[0]['type']
def defaultValue = args[0].remove('defaultValue')
if (type && !(type instanceof Class)) {
throw new CliBuilderException("'type' must be a Class")
}
if ((convert || type) && !args[0].containsKey('args') &&
type?.simpleName?.toLowerCase() != 'boolean') {
args[0].remove('type')
args[0].args = 1
}
def option = option(name, args[0], args[1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,20 @@ usage: groovy
assert hello.nums() == [12, 34]
}

// GROOVY-9886
void testHonorsTypeParameter() {
def cli = new CliBuilder(writer : new PrintWriter(System.out))
def opt = 'a'
def key = 'abc'
def type = double.class
def desc = 'abc'
cli."$opt"(args: 1, longOpt: key, type: type, desc)
def options = cli.parse(['--abc', '0.00'])
options.getOptions().each {
assert(it.getType().toString() == 'double')
}
}

void testParseFromInstanceFlagEdgeCases() {
def cli = new CliBuilder()
def options = cli.parseFromSpec(FlagEdgeCasesI, '-abc -efg true --ijk foo --lmn bar baz'.split())
Expand Down