Refine search
private void printUsage(Object options) { CmdLineParser parser = new CmdLineParser(options); StringWriter sw = new StringWriter(); sw.append(USAGE_PREFIX + "\n"); sw.append(ALT_USAGE_PREFIX + " <source> <destination>\n"); sw.append(ALT_USAGE_PREFIX + " [OPTION]... [<value>...]\n\n"); sw.append("Options:"); System.out.println(sw.toString()); parser.getProperties().withUsageWidth(100); parser.printUsage(System.out); }
/** * Creates a new command line owner that * parses arguments/options and set them into * the given object. * * @param bean * instance of a class annotated by {@link Option} and {@link Argument}. * this object will receive values. If this is {@code null}, the processing will * be skipped, which is useful if you'd like to feed metadata from other sources. * * @throws IllegalAnnotationError * if the option bean class is using args4j annotations incorrectly. */ public CmdLineParser(Object bean) { // for display purposes, we like the arguments in argument order, but the options in alphabetical order this(bean, ParserProperties.defaults()); }
if (parserProperties.getAtSyntax()) { expandedArgs = expandAtFiles(args); if( isOption(arg) ) { boolean isKeyValuePair = arg.contains(parserProperties.getOptionValueDelimiter()) || arg.indexOf('=')!=-1; currentOptionHandler = isKeyValuePair ? findOptionHandler(arg) : findOptionByName(arg);
/** * @param args : arguments / options. * @return The command line parser. * @throws CmdLineException If an error occurs while parsing the options. */ public CmdLineParser parseOptions(final String... args) throws CmdLineException { final CmdLineParser parser = new CmdLineParser(this); ParserProperties.defaults().withUsageWidth(150); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(); System.err.println("======> " + e.getMessage()); System.err.println(); printUsage(parser); throw e; } return parser; }
public CommandLineArguments() { parser = new CmdLineParser(this, ParserProperties.defaults().withShowDefaults(true).withUsageWidth(80)); }
private CmdLineParser getParser() { if (parser == null) { final ParserProperties properties = ParserProperties.defaults(); properties.withUsageWidth(80); parser = new CmdLineParser(this, properties); } return parser; }
public ArgsUtil(AppAbortStrategy strategy, BasicOptions opts) { this.abortStrategy = strategy; this.opts = opts; this.parser = new CmdLineParser(opts); try { parser.getProperties() .withUsageWidth(Integer.parseInt(System.getenv("COLUMNS"))); } catch (Exception e) { parser.getProperties().withUsageWidth(120); } }
public static void printUsage(CmdLineParser parser, OptionHandlerFilter filter, PrintStream out) { parser.getProperties().withUsageWidth(USAGE_WIDTH); parser.printUsage(new OutputStreamWriter(out), null, filter); }
/** * Sets the width of the usage output. * @param usageWidth the width of the usage output in columns. * @throws IllegalArgumentException if {@code usageWidth} is negative * @deprecated * Use {@link ParserProperties#withUsageWidth(int)} instead. */ public void setUsageWidth(int usageWidth) { parserProperties.withUsageWidth(usageWidth); }
private OptionHandler findOptionHandler(String name) { // Look for key/value pair first. int pos = name.indexOf(parserProperties.getOptionValueDelimiter()); if (pos < 0) { pos = name.indexOf('='); // historical compatibility fallback } if (pos > 0) { name = name.substring(0, pos); } return findOptionByName(name); }
/** * Get string representing usage for this option, of the form "name metaval" or "name=metaval, * e.g. "--foo VALUE" or "--foo=VALUE" * @param rb ResourceBundle to get localized version of meta string * @param properties * Affects the formatting behaviours. */ public final String getNameAndMeta(ResourceBundle rb, ParserProperties properties) { String str = option.isArgument() ? "" : option.toString(); String meta = getMetaVariable(rb); if (meta != null) { if (str.length() > 0) { str += properties.getOptionValueDelimiter(); } str += meta; } return str; }
/** * Returns an instance of the default parser properties. * This instance can be manipulated with the {@code withXXX()} methods * in this class. */ public static ParserProperties defaults() { return new ParserProperties(); }
public static void main(String[] args) throws Exception { Args indexArgs = new Args(); CmdLineParser parser = new CmdLineParser(indexArgs, ParserProperties.defaults().withUsageWidth(90)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.err.println("Example: "+ IndexFreebase.class.getSimpleName() + parser.printExample(OptionHandlerFilter.REQUIRED)); return; } new IndexFreebase(indexArgs.input, indexArgs.index, indexArgs.storeTriples, indexArgs.langEnOnly).run(); }
public ConverterOptions() { String columns = System.getProperty("columns", System.getenv("COLUMNS")); helpWidth = (columns != null && columns.matches("\\d+")) ? Integer.parseInt(columns) : DefaultConfig.HELP_WIDTH; ParserProperties props = ParserProperties.defaults() .withOptionSorter(null) .withUsageWidth(helpWidth) .withShowDefaults(false); parser = new CmdLineParser(this, props); }
protected CmdLineParser createParser(Args args) { return new CmdLineParser(args, ParserProperties.defaults().withUsageWidth(120)); }
public ArgsUtil(AppAbortStrategy strategy, BasicOptions opts) { this.abortStrategy = strategy; this.opts = opts; this.parser = new CmdLineParser(opts); try { parser.getProperties() .withUsageWidth(Integer.parseInt(System.getenv("COLUMNS"))); } catch (Exception e) { parser.getProperties().withUsageWidth(120); } }
/** * Sets the width of the usage output. * @param usageWidth the width of the usage output in columns. * @throws IllegalArgumentException if {@code usageWidth} is negative * @deprecated * Use {@link ParserProperties#withUsageWidth(int)} instead. */ public void setUsageWidth(int usageWidth) { parserProperties.withUsageWidth(usageWidth); }
private OptionHandler findOptionHandler(String name) { // Look for key/value pair first. int pos = name.indexOf(parserProperties.getOptionValueDelimiter()); if (pos < 0) { pos = name.indexOf('='); // historical compatibility fallback } if (pos > 0) { name = name.substring(0, pos); } return findOptionByName(name); }
/** * Get string representing usage for this option, of the form "name metaval" or "name=metaval, * e.g. "--foo VALUE" or "--foo=VALUE" * @param rb ResourceBundle to get localized version of meta string * @param properties * Affects the formatting behaviours. */ public final String getNameAndMeta(ResourceBundle rb, ParserProperties properties) { String str = option.isArgument() ? "" : option.toString(); String meta = getMetaVariable(rb); if (meta != null) { if (str.length() > 0) { str += properties.getOptionValueDelimiter(); } str += meta; } return str; }
/** * Returns an instance of the default parser properties. * This instance can be manipulated with the {@code withXXX()} methods * in this class. */ public static ParserProperties defaults() { return new ParserProperties(); }