kohsuke/args4j

Space in VALUE breaks --foo=VALUE

atnak opened this issue · 1 comments

atnak commented

Specifying the options as --foo=VALUE throws --foo=... is not a valid option if VALUE contains a space.

Code to reproduce

import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

public class Foo {

	@Option(name = "--foo")
	String foo;

	public static void main(String[] args) throws Exception {
		new CmdLineParser(new Foo()).parseArgument(new String[] {
				"--foo=bar baz", // This throws "is not a valid option"
				"--foo", "bar baz", // This is accepted
		});
	}
}
atnak commented

This problem is the result of not specifying ParserProperties.optionValueDelimiter which defaults to a space. It only works with = when there are not spaces in the value because that behaviour is kept for backwards compatibility.

Anyone not using a space should specify ParserProperties.optionValueDelimiter to ensure consistent behaviour:

new CmdLineParser(..., ParserProperties.defaults().withOptionValueDelimiter("="))

Closing this issue.