@Parameters validation and error messages if arity > 0 is buggy
See original GitHub issuePicoCLI version: 1.0.1
I have a class annotated with @Parameters(arity = "1..*", description = "The input files")
and discovered somethings about the validation of arity >= 1
:
- Fails to validate in some cases
- Validates in some other cases but throws different messages based on whether an empty String (
""
) or zero-length String[] (new String[0]
) is supplied to theparse(xx)
method
class Example {
@Option(names = {"-h", "--help"}, help = true,
description = "Displays this help message and quits.")
private boolean helpRequested;
@Option(names = {"-o",
"--out-dir"}, required = true, usageHelp = true, description = "The output directory")
private File outputDir;
@Parameters(arity = "1..*", description = "The input files")
private File[] inputFiles;
}
//Should've failed as inputFiles were not provided
new CommandLine(new Example()).parse("-o /tmp");
//Should've failed as inputFiles were not provided
new CommandLine(new Example()).parse("-o", " /tmp");
try {
new CommandLine(new Example()).parse("");
} catch (MissingParameterException e) {
//Type 1 error message.
e.printStackTrace();
}
try {
new CommandLine(new Example()).parse();
} catch (MissingParameterException e) {
//Type 2 error message but the parameters are "essentially" the same as type 1.
e.printStackTrace();
}
Type 1 exception:
picocli.CommandLine$MissingParameterException: Missing required parameters at positions 0..*: inputFiles
at picocli.CommandLine$Interpreter.assertNoMissingParameters(CommandLine.java:2159)
at picocli.CommandLine$Interpreter.applyOption(CommandLine.java:1745)
at picocli.CommandLine$Interpreter.processPositionalParameters0(CommandLine.java:1645)
at picocli.CommandLine$Interpreter.processPositionalParameters(CommandLine.java:1601)
at picocli.CommandLine$Interpreter.processArguments(CommandLine.java:1594)
at picocli.CommandLine$Interpreter.parse(CommandLine.java:1501)
at picocli.CommandLine$Interpreter.parse(CommandLine.java:1484)
at picocli.CommandLine.parse(CommandLine.java:334)
at Main.main(Main.java:32)
Type 2 exception:
picocli.CommandLine$MissingParameterException: Missing required options [outputDir, inputFiles]
at picocli.CommandLine$MissingParameterException.create(CommandLine.java:4086)
at picocli.CommandLine$MissingParameterException.access$1600(CommandLine.java:4071)
at picocli.CommandLine$Interpreter.parse(CommandLine.java:1511)
at picocli.CommandLine$Interpreter.parse(CommandLine.java:1484)
at picocli.CommandLine.parse(CommandLine.java:334)
at Main.main(Main.java:39)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
https://dev.w3.org/xmlschema/XSV/driver.py
validateElement import validate from XSV.compile. ... dontWarn=dw f.errors=0 if baseURI is None: base = urlunsplit(('file','',os.getcwd().replace('\\' ...
Read more >jest-validate | Yarn - Package Manager
Generic configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.
Read more >Advanced - 1.68.0 - Boost C++ Libraries
This library will never actually execute the pure virtual function body while it is calling the pure virtual function default implementation to check...
Read more >Clojure `+` behaviour with nil values - Stack Overflow
1 Answer 1 · I think generally speaking Clojure adopts a 'garbage in, garbage out' attitude to argument validation, so I think it...
Read more >Type Specifications and Erlang
We'll see why when we get to discuss how its type inference algorithm works, later in the chapter. Some Windows users will see...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After removing the
usageHelp=true
from the-o
option, things worked mostly as expected.Mostly, but not completely.
I agree that the difference between the Type1 and the Type2 exceptions is strange.
The second case seems okay: both the required
-o
option and the required positional parameter are reported as missing. This is as expected.In the first case, an empty string parameter is passed. I would expect this to be parsed as a positional parameter (an
<inputFiles>
value), resulting in aMissing required option '-o=<outputDir>'
exception. Instead what we are getting is aMissing required parameters at positions 0..*: <inputFiles>
. I’ve tracked down and fixed the bug that causes this.The fix has been pushed to master and I added your example as a new set of test cases (
testIssue203()
at the bottom).Thanks for raising this! Please verify that master behaves as expected now.
Thanks @remkop !