-
Notifications
You must be signed in to change notification settings - Fork 337
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
Custom types on main parameters don't appear to work. (1.72) #375
Comments
Definitely looks like a bug, will take a look. |
So... not a bug. First of all, the example above works if pasted verbatim in a You will get the error you saw if your converter is a nested class, though:
In this case, JCommander can't instantiate it since it needs to pass the instance of the enclosing class to it first. Admittedly, the error message should tell you that instead of failing the way it does right now. And I'm actually considering adding support for this case. In the meantime, can you confirm that your example above works? |
Sorry, with that exact example I get the error posted above. I tried moving the converter out of being a nested class but got the same error. I've attached a full gradle project as an example. If you run |
Hi. I was about to post this same bug. To be exact, custom types cannot be used in a main parameter, unless the main parameter is a list. Here is an example that exhibits this problem: package testing;
import java.nio.file.Path;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.converters.PathConverter;
public class JcommanderTest {
@Parameter( converter = PathConverter.class )
public Path filepath;
public static void main(String[] args) {
JcommanderTest cmd = new JcommanderTest();
String[] argv = { "/tmp/file.txt" };
JCommander.newBuilder().addObject(cmd).build().parse(argv);
System.out.printf("The filepath is %s class %s%n", cmd.filepath, cmd.filepath.getClass().getName());
}
} The result is:
If I add |
Same as #380 ? |
@juewe Yep, that one seems to be a dupe. |
My reduced test case is as follows:
As far as I can see I've configured the converter properly, but the error I get is:
Note I get the same error on main arguments on commands as well.
The text was updated successfully, but these errors were encountered: