diff --git a/args4j/src/org/kohsuke/args4j/NamedOptionDef.java b/args4j/src/org/kohsuke/args4j/NamedOptionDef.java index 1ed2dd16..939448fe 100644 --- a/args4j/src/org/kohsuke/args4j/NamedOptionDef.java +++ b/args4j/src/org/kohsuke/args4j/NamedOptionDef.java @@ -5,12 +5,12 @@ /** * Immutable run-time copy of {@link Option} annotation. */ -public final class NamedOptionDef extends OptionDef { +public class NamedOptionDef extends OptionDef { private final String name; private final String[] aliases; private final String[] depends; private final String[] forbids; - + /** * @deprecated * multi-valuedness as option definition does not make sense. It's driven by the setter. @@ -27,7 +27,20 @@ public NamedOptionDef(Option o) { this.depends = createZeroSizedArrayIfNull(o.depends()); this.forbids = createZeroSizedArrayIfNull(o.forbids()); } - + + /** + * Create a copy of another NamedOptionDef + * @param o The original option + */ + public NamedOptionDef(NamedOptionDef o) { + super(o.usage(),o.metaVar(),o.required(),o.help(),o.hidden(),o.handler(),false); + + this.name = o.name(); + this.aliases = o.aliases(); + this.depends = o.depends(); + this.forbids = o.forbids(); + } + private static String[] createZeroSizedArrayIfNull(String in[]) { if (in == null) { return new String[0]; @@ -39,7 +52,7 @@ private static String[] createZeroSizedArrayIfNull(String in[]) { public String name() { return name; } - + public String[] aliases() { return Arrays.copyOf(aliases, aliases.length); } @@ -51,12 +64,12 @@ public String[] depends() { public String[] forbids() { return Arrays.copyOf(forbids, forbids.length); } - + @Override public String toString() { - if (aliases.length > 0) { + if (aliases().length > 0) { String str = ""; - for (String alias : aliases) { + for (String alias : aliases()) { if (str.length() > 0) { str += ", "; } @@ -66,7 +79,7 @@ public String toString() { } return name(); } - + @Override public boolean isArgument() { return false; diff --git a/args4j/src/org/kohsuke/args4j/spi/NegatableBooleanOptionHandler.java b/args4j/src/org/kohsuke/args4j/spi/NegatableBooleanOptionHandler.java new file mode 100644 index 00000000..9fba0b6c --- /dev/null +++ b/args4j/src/org/kohsuke/args4j/spi/NegatableBooleanOptionHandler.java @@ -0,0 +1,100 @@ +package org.kohsuke.args4j.spi; + +import java.util.Arrays; + +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.IllegalAnnotationError; +import org.kohsuke.args4j.NamedOptionDef; +import org.kohsuke.args4j.OptionDef; +import org.kohsuke.args4j.spi.OptionHandler; +import org.kohsuke.args4j.spi.Parameters; +import org.kohsuke.args4j.spi.Setter; + +/** + * Boolean {@link OptionHandler} that allows values to be specified as + * --