We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
@Test public void testMissingRequiredParams() { class Example { @Parameters(index = "1", arity = "0..1") String optional; @Parameters(index = "0") String mandatory; } try { CommandLine.parse(new Example(), new String[] {"mandatory"}); } catch(MissingParameterException ex) { fail(); } try { CommandLine.parse(new Example(), new String[0]); fail("Should not accept missing mandatory parameter"); } catch(MissingParameterException ex) { assertEquals("Missing required parameter: mandatory", ex.getMessage()); } } @Test public void testMissingRequiredParams1() { class Tricky1 { @Parameters(index = "2") String anotherMandatory; @Parameters(index = "1", arity = "0..1") String optional; @Parameters(index = "0") String mandatory; } try { CommandLine.parse(new Tricky1(), new String[0]); fail("Should not accept missing mandatory parameter"); } catch(MissingParameterException ex) { assertEquals("Missing required parameters: mandatory, anotherMandatory", ex.getMessage()); } try { CommandLine.parse(new Tricky1(), new String[] {"firstonly"}); fail("Should not accept missing mandatory parameter"); } catch(MissingParameterException ex) { assertEquals("Missing required parameter: anotherMandatory", ex.getMessage()); } } @Test public void testMissingRequiredParams2() { class Tricky2 { @Parameters(index = "2", arity = "0..1") String anotherOptional; @Parameters(index = "1", arity = "0..1") String optional; @Parameters(index = "0") String mandatory; } try { CommandLine.parse(new Tricky2(), new String[] {"mandatory"}); } catch(MissingParameterException ex) { fail(); } try { CommandLine.parse(new Tricky2(), new String[0]); fail("Should not accept missing mandatory parameter"); } catch(MissingParameterException ex) { assertEquals("Missing required parameter: mandatory", ex.getMessage()); } }
The text was updated successfully, but these errors were encountered:
assertNoMissingParameters method
assertNoMissingParameters
if (arity == 1) { if (field.isAnnotationPresent(Option.class)) { throw new MissingParameterException("Missing required parameter for " + optionDescription("", field, 0)); } Arity indexRange = Arity.valueOf(field.getAnnotation(Parameters.class).index()); Help.IParamLabelRenderer labelRenderer = Help.createMinimalParamLabelRenderer(); String sep = ""; String names = ""; int count = 0; for (int i = indexRange.min; i < positionalParametersFields.size(); i++) { if (Arity.forParameters(positionalParametersFields.get(i)).min > 0) { names += sep + labelRenderer.renderParameterLabel(positionalParametersFields.get(i), Collections.<IStyle>emptyList()); sep = ", "; count++; } } String msg = "Missing required parameter"; Arity paramArity = Arity.forParameters(field); if (paramArity.isVariable) { msg += "s at positions " + paramArity + ": "; } else { msg += (count > 1 ? "s: " : ": "); } throw new MissingParameterException(msg + names); }
Sorry, something went wrong.
9e662b3
No branches or pull requests
The text was updated successfully, but these errors were encountered: