if (option.hidden()) { continue; } boolean isFlagOption = option.typeInfo().isBoolean(); if (isFlagOption && option.arity().max <= 0) { // #612 consider arity: boolean options may require a parameter String shortestName = option.shortestName(); if (shortestName.length() == 2 && shortestName.startsWith("-")) {
@SuppressWarnings("deprecation") private void printOptionAnnotation(PrintWriter pw, OptionSpec spec, String indent) { pw.printf("%s@%s", indent, importer.getImportedName(Option.class.getCanonicalName())); indent = String.format(",%n%s ", indent); String sep = "("; sep = appendStringArray(pw, sep, indent, "names = %s", spec.names(), EMPTY_ARRAY); sep = append(pw, sep, indent, "required = %s", spec.required(), false); sep = append(pw, sep, indent, "help = %s", spec.help(), false); sep = append(pw, sep, indent, "usageHelp = %s", spec.usageHelp(), false); sep = append(pw, sep, indent, "versionHelp = %s", spec.versionHelp(), false); sep = appendStringArray(pw, sep, indent, "description = %s", spec.description(), EMPTY_ARRAY); sep = append(pw, sep, indent, "arity = \"%s\"", spec.arity().toString(), spec.arity().isUnspecified() ? spec.arity().toString() : ""); sep = append(pw, sep, indent, "paramLabel = \"%s\"", spec.paramLabel(), "<" + argElementName(spec) + ">"); sep = append(pw, sep, indent, "hideParamSyntax = %s", spec.hideParamSyntax(), false); sep = appendTypeInfo(pw, sep, indent, spec.typeInfo()); sep = appendTypeConverter(pw, sep, indent, spec.converters()); sep = append(pw, sep, indent, "split = \"%s\"", spec.splitRegex(), ""); sep = append(pw, sep, indent, "hidden = %s", spec.hidden(), false); sep = append(pw, sep, indent, "defaultValue = %s", spec.defaultValue() == null ? "__no_default_value__" : spec.defaultValue(), "__no_default_value__"); sep = append(pw, sep, indent, "showDefaultValue = \"%s\"", spec.showDefaultValue(), CommandLine.Help.Visibility.ON_DEMAND); sep = appendCompletionCandidates(pw, sep, indent, spec); sep = append(pw, sep, indent, "interactive = %s", spec.interactive(), false); sep = append(pw, sep, indent, "descriptionKey = \"%s\"", spec.descriptionKey(), ""); if (!"(".equals(sep)) { pw.print(")"); } }
} else if (optionSpec.isMultiValue() || optionSpec.arity().max > 1) { tomlResult.getArray(tomlKey); } else if (Number.class.isAssignableFrom(optionSpec.type())) {
@Test public void testOptionDefaultArityIsZeroIfUntyped() { assertEquals(Range.valueOf("0"), OptionSpec.builder("-x").build().arity()); }
public int compare(OptionSpec o1, OptionSpec o2) { Range arity1 = o1.arity(); Range arity2 = o2.arity(); int result = arity1.max - arity2.max; if (result == 0) { result = arity1.min - arity2.min; } if (result == 0) { // arity is same if (o1.isMultiValue() && !o2.isMultiValue()) { result = 1; } // f1 > f2 if (!o1.isMultiValue() && o2.isMultiValue()) { result = -1; } // f1 < f2 } return result == 0 ? super.compare(o1, o2) : result; } }
@Test public void testOptionDefaultArityIsOneIfTypeNonBoolean() { assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(int.class).build().arity()); assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(Integer.class).build().arity()); assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(Byte.class).build().arity()); assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(String.class).build().arity()); }
public int compare(OptionSpec o1, OptionSpec o2) { Range arity1 = o1.arity(); Range arity2 = o2.arity(); int result = arity1.max - arity2.max; if (result == 0) { result = arity1.min - arity2.min; } if (result == 0) { // arity is same if (o1.isMultiValue() && !o2.isMultiValue()) { result = 1; } // f1 > f2 if (!o1.isMultiValue() && o2.isMultiValue()) { result = -1; } // f1 < f2 } return result == 0 ? super.compare(o1, o2) : result; } }
@Test public void testOptionDefaultArityIsOneIfTypeNonBoolean() { assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(int.class).build().arity()); assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(Integer.class).build().arity()); assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(Byte.class).build().arity()); assertEquals(Range.valueOf("1"), OptionSpec.builder("-x").type(String.class).build().arity()); }
@Test public void testOptionDefaultArityIsZeroIfUntyped() { assertEquals(Range.valueOf("0"), OptionSpec.builder("-x").build().arity()); }