@Test public void testFormatMetavar() { ArgumentImpl arg = new ArgumentImpl(config_, "--foo"); assertEquals("FOO", arg.formatMetavar()); arg.dest("BAZ"); assertEquals("BAZ", arg.formatMetavar()); arg.metavar("BAR"); assertEquals("BAR", arg.formatMetavar()); arg.nargs(3); assertEquals("BAR BAR BAR", arg.formatMetavar()); arg.metavar("ALPHA", "BRAVO", "CHARLIE"); assertEquals("ALPHA BRAVO CHARLIE", arg.formatMetavar()); arg.nargs(4); assertEquals("ALPHA BRAVO CHARLIE CHARLIE", arg.formatMetavar()); arg.nargs("?"); assertEquals("[ALPHA]", arg.formatMetavar()); arg.nargs("*"); assertEquals("[ALPHA [BRAVO ...]]", arg.formatMetavar()); arg.nargs("+"); assertEquals("ALPHA [BRAVO ...]", arg.formatMetavar()); }
String formatMetavar() { StringBuilder sb = new StringBuilder(); if (action_.consumeArgument()) { String[] metavar = resolveMetavar(); if (minNumArg_ == 0 && maxNumArg_ == 1) { sb.append("[").append(metavar[0]).append("]"); } else if (minNumArg_ == 0 && maxNumArg_ == Integer.MAX_VALUE) { sb.append("[").append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]]"); } else if (minNumArg_ == 1 && maxNumArg_ == Integer.MAX_VALUE) { sb.append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]"); } else if (minNumArg_ == -1) { sb.append(metavar[0]); } else if (minNumArg_ > 0 && minNumArg_ == maxNumArg_) { int i, max; for (i = 0, max = Math.min(minNumArg_, metavar.length); i < max; ++i) { sb.append(metavar[i]).append(" "); } for (; i < minNumArg_; ++i) { sb.append(metavar[metavar.length - 1]).append(" "); } sb.delete(sb.length() - 1, sb.length()); } } return sb.toString(); }
ArgumentImpl implements Argument { String formatMetavar() { StringBuilder sb = new StringBuilder(); if (action_.consumeArgument()) { String[] metavar = resolveMetavar(); if (minNumArg_ == 0 && maxNumArg_ == 1) { sb.append("[").append(metavar[0]).append("]"); } else if (minNumArg_ == 0 && maxNumArg_ == Integer.MAX_VALUE) { sb.append("[").append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]]"); } else if (minNumArg_ == 1 && maxNumArg_ == Integer.MAX_VALUE) { sb.append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]"); } else if (minNumArg_ == -1) { sb.append(metavar[0]); } else if (minNumArg_ > 0 && minNumArg_ == maxNumArg_) { int i, max; for (i = 0, max = Math.min(minNumArg_, metavar.length); i < max; ++i) { sb.append(metavar[i]).append(" "); } for (; i < minNumArg_; ++i) { sb.append(metavar[metavar.length - 1]).append(" "); } sb.delete(sb.length() - 1, sb.length()); } } return sb.toString(); } }
ArgumentImpl implements Argument { String formatMetavar() { StringBuilder sb = new StringBuilder(); if (action_.consumeArgument()) { String[] metavar = resolveMetavar(); if (minNumArg_ == 0 && maxNumArg_ == 1) { sb.append("[").append(metavar[0]).append("]"); } else if (minNumArg_ == 0 && maxNumArg_ == Integer.MAX_VALUE) { sb.append("[").append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]]"); } else if (minNumArg_ == 1 && maxNumArg_ == Integer.MAX_VALUE) { sb.append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]"); } else if (minNumArg_ == -1) { sb.append(metavar[0]); } else if (minNumArg_ > 0 && minNumArg_ == maxNumArg_) { int i, max; for (i = 0, max = Math.min(minNumArg_, metavar.length); i < max; ++i) { sb.append(metavar[i]).append(" "); } for (; i < minNumArg_; ++i) { sb.append(metavar[metavar.length - 1]).append(" "); } sb.delete(sb.length() - 1, sb.length()); } } return sb.toString(); } ArgumentImpl(ArgumentParserConfigurationImpl config,
            String... nameOrFlags);   ArgumentImpl(ArgumentParserConfigurationImpl config,
            ArgumentGroupImpl argumentGroup, String... nameOrFlags); }
ArgumentImpl implements Argument { String formatMetavar() { StringBuilder sb = new StringBuilder(); if (action_.consumeArgument()) { String[] metavar = resolveMetavar(); if (minNumArg_ == 0 && maxNumArg_ == 1) { sb.append("[").append(metavar[0]).append("]"); } else if (minNumArg_ == 0 && maxNumArg_ == Integer.MAX_VALUE) { sb.append("[").append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]]"); } else if (minNumArg_ == 1 && maxNumArg_ == Integer.MAX_VALUE) { sb.append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]"); } else if (minNumArg_ == -1) { sb.append(metavar[0]); } else if (minNumArg_ > 0 && minNumArg_ == maxNumArg_) { int i, max; for (i = 0, max = Math.min(minNumArg_, metavar.length); i < max; ++i) { sb.append(metavar[i]).append(" "); } for (; i < minNumArg_; ++i) { sb.append(metavar[metavar.length - 1]).append(" "); } sb.delete(sb.length() - 1, sb.length()); } } return sb.toString(); } ArgumentImpl(ArgumentParserConfigurationImpl config,
            String... nameOrFlags);   ArgumentImpl(ArgumentParserConfigurationImpl config,
            ArgumentGroupImpl argumentGroup, String... nameOrFlags); @Override String textualName(); void printHelp(PrintWriter writer, boolean defaultHelp,
            TextWidthCounter textWidthCounter, int width); Object convert(ArgumentParserImpl parser, String value); @Override ArgumentImpl nargs(int n); @Override ArgumentImpl nargs(String n); @Override ArgumentImpl setConst(Object value); @Override ArgumentImpl setConst(E... values); @Override ArgumentImpl setDefault(Object value); @Override ArgumentImpl setDefault(E... values); @Override ArgumentImpl setDefault(FeatureControl ctrl); @Override ArgumentImpl type(Class<T> type); @Override ArgumentImpl type(ArgumentType<T> type); @Override ArgumentImpl required(boolean required); @Override ArgumentImpl action(ArgumentAction action); @Override ArgumentImpl choices(ArgumentChoice choice); @Override ArgumentImpl choices(Collection<E> values); @Override ArgumentImpl choices(E... values); @Override ArgumentImpl dest(String dest); @Override ArgumentImpl metavar(String... metavar); @Override ArgumentImpl help(String help); @Override ArgumentImpl help(FeatureControl ctrl); void run(ArgumentParserImpl parser, Map<String, Object> res,
            String flag, Object value); @Override String getDest(); @Override Object getConst(); @Override Object getDefault(); @Override FeatureControl getDefaultControl(); @Override FeatureControl getHelpControl(); String getName(); boolean isRequired(); String[] getMetavar(); ArgumentAction getAction(); String getHelp(); }
ArgumentImpl implements Argument { String formatMetavar() { StringBuilder sb = new StringBuilder(); if (action_.consumeArgument()) { String[] metavar = resolveMetavar(); if (minNumArg_ == 0 && maxNumArg_ == 1) { sb.append("[").append(metavar[0]).append("]"); } else if (minNumArg_ == 0 && maxNumArg_ == Integer.MAX_VALUE) { sb.append("[").append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]]"); } else if (minNumArg_ == 1 && maxNumArg_ == Integer.MAX_VALUE) { sb.append(metavar[0]).append(" [") .append(metavar.length == 1 ? metavar[0] : metavar[1]) .append(" ...]"); } else if (minNumArg_ == -1) { sb.append(metavar[0]); } else if (minNumArg_ > 0 && minNumArg_ == maxNumArg_) { int i, max; for (i = 0, max = Math.min(minNumArg_, metavar.length); i < max; ++i) { sb.append(metavar[i]).append(" "); } for (; i < minNumArg_; ++i) { sb.append(metavar[metavar.length - 1]).append(" "); } sb.delete(sb.length() - 1, sb.length()); } } return sb.toString(); } ArgumentImpl(ArgumentParserConfigurationImpl config,
            String... nameOrFlags);   ArgumentImpl(ArgumentParserConfigurationImpl config,
            ArgumentGroupImpl argumentGroup, String... nameOrFlags); @Override String textualName(); void printHelp(PrintWriter writer, boolean defaultHelp,
            TextWidthCounter textWidthCounter, int width); Object convert(ArgumentParserImpl parser, String value); @Override ArgumentImpl nargs(int n); @Override ArgumentImpl nargs(String n); @Override ArgumentImpl setConst(Object value); @Override ArgumentImpl setConst(E... values); @Override ArgumentImpl setDefault(Object value); @Override ArgumentImpl setDefault(E... values); @Override ArgumentImpl setDefault(FeatureControl ctrl); @Override ArgumentImpl type(Class<T> type); @Override ArgumentImpl type(ArgumentType<T> type); @Override ArgumentImpl required(boolean required); @Override ArgumentImpl action(ArgumentAction action); @Override ArgumentImpl choices(ArgumentChoice choice); @Override ArgumentImpl choices(Collection<E> values); @Override ArgumentImpl choices(E... values); @Override ArgumentImpl dest(String dest); @Override ArgumentImpl metavar(String... metavar); @Override ArgumentImpl help(String help); @Override ArgumentImpl help(FeatureControl ctrl); void run(ArgumentParserImpl parser, Map<String, Object> res,
            String flag, Object value); @Override String getDest(); @Override Object getConst(); @Override Object getDefault(); @Override FeatureControl getDefaultControl(); @Override FeatureControl getHelpControl(); String getName(); boolean isRequired(); String[] getMetavar(); ArgumentAction getAction(); String getHelp();  }