private void printUsage(PrintWriter writer) { // fix defaults for options like help and other 0-arg booleans OptionHandlerRegistry.getRegistry().registerHandler(Boolean.class, BooleanNoDefOptionHandler.class); OptionHandlerRegistry.getRegistry().registerHandler(boolean.class, BooleanNoDefOptionHandler.class); ParserProperties prop = ParserProperties.defaults() .withUsageWidth(80) .withOptionSorter(null); ByteArrayOutputStream buf = new ByteArrayOutputStream(); // new args instance to get correct defaults new CmdLineParser(new CliArgs(), prop) .printUsage(new OutputStreamWriter(buf, StandardCharsets.UTF_8), null); writer.println(MessageFormat.format(Messages.UsageHelp.replace("${tab}", "\t"), new String(buf.toByteArray(), StandardCharsets.UTF_8), DangerStatementOptionHandler.getMetaVariable() + '\n' + DbObjTypeOptionHandler.getMetaVariable())); }
public Exporter(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If there are no files, comlain with a non-zero exit code. if (dir == null) System.exit(EX_USAGE); dirPath = FileSystems.getDefault().getPath(dir); }
public ApiBin(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } }
/** * Initialize the verifier, using command-line arguments. * * @param args The command-line arguments passed to the program. */ public RhistMain(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If there are no files, comlain with a non-zero exit code. if (dir == null) System.exit(EX_USAGE); path_ = FileSystems.getDefault().getPath(dir); }
/** * Initialize the verifier, using command-line arguments. * @param args The command-line arguments passed to the program. */ public Verify(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If there are no files, comlain with a non-zero exit code. if (files.isEmpty()) System.exit(EX_USAGE); }
private static void parseCommandLineArgumentsAndRun(String[] args) { CommandLineParameters parameters = new CommandLineParameters(); AmidstMetaData metadata = createMetadata(); CmdLineParser parser = new CmdLineParser( parameters, ParserProperties.defaults().withShowDefaults(false).withUsageWidth(120).withOptionSorter(null)); try { parser.parseArgument(args); run(parameters, metadata, parser); } catch (CmdLineException e) { System.out.println(metadata.getVersion().createLongVersionString()); System.err.println(e.getMessage()); parser.printUsage(System.out); System.exit(2); } }
private final void doMain(String... args) throws Exception { final ParserProperties properties = ParserProperties.defaults() .withUsageWidth(80) .withShowDefaults(true); final CmdLineParser parser = new CmdLineParser(this, properties); try { parser.parseArgument(args); final int enabledBoilers = (zlib_ ? 1:0) + (lzf_ ? 1:0) + (snappy_ ? 1:0); if (compress_ == null && decompress_ == null) { throw new IllegalArgumentException("Missing '--compress' or '--decompress' " + "argument."); } else if (compress_ != null && decompress_ != null) { throw new IllegalArgumentException("Must specify only one of '--compress' or " + "'--decompress' arguments."); } else if (enabledBoilers > 1) { throw new IllegalArgumentException("Can only specify one of --zlib, --lzf, or --snappy."); } else if (enabledBoilers == 0) { throw new IllegalArgumentException("Must specify at least one of --zlib, --lzf, or --snappy."); } run(); // Go! } catch (Exception e) { log.debug("Failed to start; see usage.", e); parser.printUsage(System.err); } }
private void doMain(final String[] args) throws Exception { final ParserProperties properties = ParserProperties.defaults().withUsageWidth(80); final CmdLineParser parser = new CmdLineParser(this, properties); try { parser.parseArgument(args); if (_url == null) { throw new CmdLineException(parser, "URL to camera stream required.", null); } // http://1.0.0.6:8085/axis-cgi/jpg/image.cgi?resolution=640x480 Camera axis = new Camera("Axis 2100 Network Camera", _url, "", "", Constants.REFRESH_RATE ); CameraFrame frame = new CameraFrame( axis ); frame.setVisible(true); frame.run(); } catch (Exception e) { System.err.println("Usage:"); parser.printUsage(System.err); } }
/** * @param args the command line arguments * @throws java.io.IOException the exception * @throws java.lang.InterruptedException the exception */ public static void main(String[] args) throws IOException, InterruptedException { try { Griffin griffin = new Griffin(); CmdLineParser parser = new CmdLineParser(griffin, ParserProperties.defaults().withUsageWidth(120)); parser.parseArgument(args); if (griffin.help || griffin.version || args.length == 0) { griffin.printHelpMessage(); parser.printUsage(System.out); } else { griffin.commands.execute(); } } catch (CmdLineException ex) { Logger.getLogger(Griffin.class.getName()).log(Level.SEVERE, null, ex); } }
/** * Executes the command */ @Override public void execute() { Griffin griffin = new Griffin(); if (help) { System.out.println("Preview the site on the given port: default: 9090"); System.out.println("usage: griffin preview [option]"); System.out.println("Options: " + LINE_SEPARATOR); CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(120)); parser.printUsage(System.out); } else { griffin.printAsciiGriffin(); griffin.preview(port); } }
/** * Executes the command */ @Override public void execute() { if (help) { System.out.println("Publish the content in the current Griffin directory."); System.out.println("usage: griffin publish [option]"); System.out.println("Options: " + LINE_SEPARATOR); CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(120)); parser.printUsage(System.out); return; } try { Griffin griffin = new Griffin(); griffin.printAsciiGriffin(); griffin.publish(fastParse, rebuild); System.out.println("All done for now! I will be bach!"); } catch (IOException | InterruptedException ex) { Logger.getLogger(PublishCommand.class.getName()).log(Level.SEVERE, null, ex); } }
/** * Executes the command */ @Override public void execute() { try { if (help || args.isEmpty()) { System.out.println("Scaffold out a new Griffin directory structure."); System.out.println("usage: griffin new [option] <path>"); System.out.println("Options: " + LINE_SEPARATOR); CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(120)); parser.printUsage(System.out); return; } else { filePath = Paths.get(args.get(0)); } Griffin griffin = new Griffin(filePath.resolve(name)); griffin.initialize(filePath, name); System.out.println("Successfully created new site."); } catch (IOException | URISyntaxException ex) { Logger.getLogger(NewCommand.class.getName()).log(Level.SEVERE, null, ex); } }
public static Options parse(final String[] args) throws IOException { Options options = new Options(); CmdLineParser parser = new CmdLineParser(options, ParserProperties.defaults().withUsageWidth(120)); try { // parse the arguments. parser.parseArgument(args); if (options.arguments.isEmpty() || options.arguments.size() < 2 || options.showUsage) { usage(parser); } } catch (CmdLineException e) { System.err.println(e.getMessage()); System.err.println(); usage(parser); } return options; }
public void doMain(String[] args) { ParserProperties props = ParserProperties.defaults().withUsageWidth(80); CmdLineParser parser = new CmdLineParser(this, props); try { parser.parseArgument(args); if (help) { System.err.println(format("java {0} [OPTIONS] [CONFIG...]", Main.class.getName())); parser.printUsage(System.err); return; } } catch (CmdLineException ex) { System.err.println(format("java {0} [OPTIONS] [CONFIG...]", Main.class.getName())); parser.printUsage(System.err); return; } startServer(); }
public static void main(String[] argv) { Args args = new Args(); CmdLineParser parser = new CmdLineParser(args, ParserProperties.defaults().withOptionSorter(null) .withUsageWidth(80).withShowDefaults(false)); boolean wasExcept = false; try { parser.parseArgument(argv); } catch (CmdLineException e) { System.out.println(e.getMessage()); wasExcept = true; } if (wasExcept || args.help) { System.out.println("java -jar prettygalaxy.v1.jar [options...]"); parser.printUsage(System.out); System.exit(args.help?0:1); } args.sanitize(); for (int i = 0; i < args.numRuns; i++) { generate(args); if (args.out == null) break; } }
public FileConvert(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If verbose mode is requested, dial up the log spam. if (verbose) { Logger.getLogger("com.groupon.lex").setLevel(Level.INFO); Logger.getLogger("com.github.groupon.monsoon").setLevel(Level.INFO); } // If there are no files, comlain with a non-zero exit code. if (srcdir == null) System.exit(EX_USAGE); srcdir_path_ = FileSystems.getDefault().getPath(srcdir); }
/** * Initialize the verifier, using command-line arguments. * * @param args The command-line arguments passed to the program. */ public FileConvert(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If verbose mode is requested, dial up the log spam. if (verbose) Logger.getLogger("com.groupon.lex").setLevel(Level.INFO); // If there are no files, comlain with a non-zero exit code. if (srcdir == null || dstdir == null) System.exit(EX_USAGE); srcdir_path_ = FileSystems.getDefault().getPath(srcdir); dstdir_path_ = FileSystems.getDefault().getPath(dstdir); }
private static ParserProperties configure() { CmdLineParser.registerHandler(BuiltIn.class, AltEnumOptionHandler.class); ParserProperties properties = ParserProperties.defaults(); properties.withOptionSorter(null); properties.withUsageWidth(100); return properties; }
/** * Parses and checks the program arguments. If the arguments are invalid or the user requested * the help message, this method returns <code>false</code> and writes the message for the user. * If the parsing is successful, this method does not print anything to the output. * * @param args * the arguments to parse * @return <code>true</code> if the arguments were successfully parsed, <code>false</code> if * arguments are invalid or the user requested the help message (<code>false</code> * generally means that SETTE should stop) */ public boolean parse(@NonNull String... args) { // register handler for tool and set the current configuration for it OptionHandlerRegistry.getRegistry().registerHandler(SetteToolConfiguration.class, ToolOptionHandler.class); ToolOptionHandler.configuration = configuration; // parse args with preset properties ParserProperties parserProps = ParserProperties.defaults() .withShowDefaults(true) .withUsageWidth(80); CmdLineParser parser = new CmdLineParser(this, parserProps); try { parser.parseArgument(args); if (help) { printHelp(parser); return false; } else { return true; } } catch (CmdLineException ex) { errorOutput.println(ex.getMessage()); printHelp(parser); return false; } }
private CmdLineParser getParser() { if (parser == null) { final ParserProperties properties = ParserProperties.defaults(); properties.withUsageWidth(80); parser = new CmdLineParser(this, properties); } return parser; }
public void doMain(String[] args) throws IOException { // parse options ParserProperties.defaults().withUsageWidth(80); CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(USAGE); parser.printUsage(System.err); System.err.println(); return; } if (arguments.size() != 3) { System.err.println(USAGE); parser.printUsage(System.err); System.err.println(); return; } LibSVMPredict predict = new LibSVMPredict( new File(arguments.get(0)), new File(arguments.get(2)), new File(arguments.get(1)), probabilityEstimates, quiteMode ); predict.predict(); }
void printExample() { CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withShowDefaults(false)); parser.printUsage(System.out); }
public static void main(String[] argv) { Args args = new Args(); CmdLineParser parser = new CmdLineParser(args, ParserProperties.defaults().withOptionSorter(null) .withUsageWidth(80).withShowDefaults(false)); boolean wasExcept = false; try { parser.parseArgument(argv); validateArgs(args); } catch (CmdLineException e) { System.out.println(e.getMessage()); wasExcept = true; } if (wasExcept || args.help) { System.out.println("java -jar PlanetGfx.v1.jar [options...]"); parser.printUsage(System.out); System.exit(args.help?0:1); } for (int i = 0; i < args.numRuns; i++) { BufferedImage im = generate(args); if (args.out == null) { NebulaStormGalaxyGfx.showImage(im); } else { NebulaStormGalaxyGfx.saveImage(im, args.out); } } // NebulaStormGalaxyGfx.showImage(im); }
public PartialCmdLineParser(Object bean, ParserProperties parserProperties) { super(bean, parserProperties); }
private static void parseOptions(Options options, String[] args) { ParserProperties properties = ParserProperties.defaults().withUsageWidth(128); CmdLineParser parser = new CmdLineParser(options, properties); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); System.err.println(getUsageString(parser, false)); System.exit(1); } if (options.showVersion) { System.out.println(getVersionString()); System.exit(0); } if (options.showHelp) { System.out.println(getUsageString(parser, false)); System.exit(0); } if (options.showExtendedHelp) { System.out.println(getUsageString(parser, true)); System.exit(0); } if (options.printCode || options.printCodeWithTypes || options.debugInfo) { // Disable interpreter when bytecode is requested options.noInterpreter = true; } if (options.fileName != null) { // Execute as last script if (options.fileName.toString().equals("-")) { // "-" is a short-hand to request reading from System.in if (System.console() == null) { // System.in is not interactive options.evalScripts.add(new EvalString(read(System.in))); } else { options.interactive = true; } } else { options.evalScripts.add(new EvalPath(options.fileName, EvalPath.Type.Script)); } } if (options.evalScripts.isEmpty()) { // Default to interactive mode when no files or expressions were set options.interactive = true; } }