kohsuke / args4j

args4j
http://args4j.kohsuke.org/
MIT License
789 stars 189 forks source link

Space in VALUE breaks --foo=VALUE #167

Closed atnak closed 5 years ago

atnak commented 5 years ago

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 5 years ago

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.