Java Code Examples for org.kohsuke.args4j.CmdLineParser#printUsage()
The following examples show how to use
org.kohsuke.args4j.CmdLineParser#printUsage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Grep.java From tcl-regex-java with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException, RegexException { Grep that = new Grep(); CmdLineParser parser = new CmdLineParser(that); try { if (args.length == 0) { System.err.println("grep PATTERN file1 ... fileN"); parser.printUsage(System.err); return; } parser.parseArgument(args); } catch (CmdLineException e) { // handling of wrong arguments System.err.println(e.getMessage()); parser.printUsage(System.err); System.exit(1); } that.go(); }
Example 2
Source File: App.java From java-play-store-uploader with MIT License | 6 votes |
/** * Parse process arguments. * * @param args process arguments * @throws Exception argumentss error * @return {@link App} instance */ private App parseArgs(String... args) throws CmdLineException { // init parser CmdLineParser parser = new CmdLineParser(this); try { // must have args if (args == null || args.length < 1) { String msg = "No arguments given"; throw new CmdLineException(parser, this.localize(msg), msg); } // parse args parser.parseArgument(args); } catch (CmdLineException e) { // print usage and forward error System.err.println("Invalid arguments."); System.err.println("Options:"); parser.printUsage(System.err); throw e; } // return instance return this; }
Example 3
Source File: NewCommand.java From griffin with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 4
Source File: OptionsParser.java From MOE with Apache License 2.0 | 6 votes |
/** * Parses command-line flags, returning true if the parse was successful and no flags errors were * found. */ // TODO(cgruber) Rework this with JCommander so we can have plugin-specific flags public boolean parseFlags(MoeOptions options) { CmdLineParser parser = new CmdLineParser(options); try { parser.parseArgument(preprocessedArgs); if (options.shouldDisplayHelp()) { parser.printUsage(System.err); } return true; } catch (CmdLineException e) { logger.log(Level.SEVERE, e.getMessage()); parser.printUsage(System.err); return false; } }
Example 5
Source File: CliProjectsCreatorMain.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static void main(final String[] args) { CliProjectsCreatorMain bean = new CliProjectsCreatorMain(); CliProjectsCreator projectsCreator = new CliProjectsCreator(); CmdLineParser parser = new CmdLineParser(bean); try { parser.parseArgument(args); final WizardConfiguration config = bean.createProjectConfig(); projectsCreator.setLineDelimiter(config.getLineDelimiter()); projectsCreator.createProjects(config); LOG.info(String.format("Created projects for language %s in %s", config.getLanguage().getName(), config.getRootLocation())); } catch (final Throwable _t) { if (_t instanceof CmdLineException) { final CmdLineException e = (CmdLineException) _t; System.err.println(e.getMessage()); parser.printUsage(System.err); } else { throw Exceptions.sneakyThrow(_t); } } }
Example 6
Source File: NetworkProxyServer.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void doMain(String[] args) { CmdLineParser cmdLineParser = new CmdLineParser(this); try { cmdLineParser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); cmdLineParser.printUsage(System.err); return; } command.execute(portNumber); }
Example 7
Source File: DataReceiver.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void doMain(String[] args) throws Exception { CmdLineParser cmdLineParser = new CmdLineParser(this); try { cmdLineParser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); cmdLineParser.printUsage(System.err); return; } work(); }
Example 8
Source File: Repl.java From es6draft with MIT License | 5 votes |
private static String getUsageString(CmdLineParser parser, boolean showAll) { ResourceBundle rb = getResourceBundle(); StringWriter writer = new StringWriter(); writer.write(formatMessage(rb, "usage", getVersionString(), PROGRAM_NAME)); parser.printUsage(writer, rb, showAll ? OptionHandlerFilter.ALL : OptionHandlerFilter.PUBLIC); return writer.toString(); }
Example 9
Source File: VarSimTool.java From varsim with BSD 2-Clause "Simplified" License | 5 votes |
public void printUsage(final CmdLineParser parser) { System.err.println(VERSION); System.err.println("java -jar VarSim.jar " + getCommand() + " [options...]"); System.err.println(getDescription()); // print the list of available options parser.printUsage(System.err); }
Example 10
Source File: SparkPipelineRunner.java From beam with Apache License 2.0 | 5 votes |
private static SparkPipelineRunnerConfiguration parseArgs(String[] args) { SparkPipelineRunnerConfiguration configuration = new SparkPipelineRunnerConfiguration(); CmdLineParser parser = new CmdLineParser(configuration); try { parser.parseArgument(args); } catch (CmdLineException e) { LOG.error("Unable to parse command line arguments.", e); parser.printUsage(System.err); throw new IllegalArgumentException("Unable to parse command line arguments.", e); } return configuration; }
Example 11
Source File: Flags.java From js-dossier with Apache License 2.0 | 5 votes |
/** * Parses the given command line flags, exiting the program if there are any errors or if usage * information was requested with the {@link #displayHelp --help} flag. */ static synchronized Flags parse(String[] args, FileSystem fileSystem) { final Flags flags = new Flags(fileSystem); CmdLineParser parser = new CmdLineParser(flags); parser.setUsageWidth(79); try { parser.parseArgument(args); } catch (CmdLineException e) { if (!flags.displayHelp) { System.err.println(e.getMessage()); } flags.displayHelp = true; } if (flags.displayHelp) { System.err.println("\nUsage: dossier [options] -c CONFIG"); System.err.println("\nwhere options include:\n"); parser.printUsage(System.err); } if (flags.displayJsonHelp) { System.err.println("\nThe JSON configuration file may have the following options:\n"); System.err.println(Config.getOptionsText(false)); } if (flags.displayHelp || flags.displayJsonHelp) { System.exit(1); } return flags; }
Example 12
Source File: FlinkMiniClusterEntryPoint.java From beam with Apache License 2.0 | 5 votes |
private static void printUsage(CmdLineParser parser) { System.err.println( String.format( "Usage: java %s arguments...", FlinkMiniClusterEntryPoint.class.getSimpleName())); parser.printUsage(System.err); System.err.println(); }
Example 13
Source File: DownloadAccountInfo.java From ofx4j with Apache License 2.0 | 5 votes |
private void invalidArgs(CmdLineParser parser, CmdLineException e) { System.err.println(e.getMessage()); System.err.println("java DownloadAccountInfo [options...] arguments..."); // print the list of available options parser.printUsage(System.err); System.err.println(); // print option sample. This is useful some time System.err.println(" Example: java DownloadAccountInfo " + parser.printExample(ExampleMode.ALL)); System.exit(1); }
Example 14
Source File: Exporter.java From monsoon with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static void print_usage_and_exit_(CmdLineParser parser) { System.err.println("java -jar monsoon-export.jar [options] /history/dir"); parser.printUsage(System.err); System.exit(EX_TEMPFAIL); /* UNREACHABLE */ }
Example 15
Source File: MainEntry.java From LTM with Apache License 2.0 | 4 votes |
private static void showCommandLineHelp(CmdLineParser parser) { System.out.println("java [options ...] [arguments...]"); parser.printUsage(System.out); }
Example 16
Source File: CommandLineRunner.java From astor with GNU General Public License v2.0 | 4 votes |
private void initConfigFromFlags(String[] args, PrintStream err) { List<String> processedArgs = processArgs(args); CmdLineParser parser = new CmdLineParser(flags); Flags.warningGuardSpec.clear(); isConfigValid = true; try { parser.parseArgument(processedArgs.toArray(new String[] {})); // For contains --flagfile flag if (!flags.flag_file.equals("")) { processFlagFile(err); } } catch (CmdLineException e) { err.println(e.getMessage()); isConfigValid = false; } catch (IOException ioErr) { err.println("ERROR - " + flags.flag_file + " read error."); isConfigValid = false; } if (flags.version) { err.println( "Closure Compiler (http://code.google.com/closure/compiler)\n" + "Version: " + Compiler.getReleaseVersion() + "\n" + "Built on: " + Compiler.getReleaseDate()); err.flush(); } if (flags.process_common_js_modules) { flags.process_closure_primitives = true; flags.manage_closure_dependencies = true; if (flags.common_js_entry_module == null) { err.println("Please specify --common_js_entry_module."); err.flush(); isConfigValid = false; } flags.closure_entry_point = Lists.newArrayList( ProcessCommonJSModules.toModuleName(flags.common_js_entry_module)); } if (!isConfigValid || flags.display_help) { isConfigValid = false; parser.printUsage(err); } else { CodingConvention conv; if (flags.third_party) { conv = CodingConventions.getDefault(); } else if (flags.process_jquery_primitives) { conv = new JqueryCodingConvention(); } else { conv = new ClosureCodingConvention(); } getCommandLineConfig() .setPrintTree(flags.print_tree) .setPrintAst(flags.print_ast) .setPrintPassGraph(flags.print_pass_graph) .setJscompDevMode(flags.jscomp_dev_mode) .setLoggingLevel(flags.logging_level) .setExterns(flags.externs) .setJs(flags.getJsFiles()) .setJsOutputFile(flags.js_output_file) .setModule(flags.module) .setVariableMapInputFile(flags.variable_map_input_file) .setPropertyMapInputFile(flags.property_map_input_file) .setVariableMapOutputFile(flags.variable_map_output_file) .setCreateNameMapFiles(flags.create_name_map_files) .setPropertyMapOutputFile(flags.property_map_output_file) .setCodingConvention(conv) .setSummaryDetailLevel(flags.summary_detail_level) .setOutputWrapper(flags.output_wrapper) .setModuleWrapper(flags.module_wrapper) .setModuleOutputPathPrefix(flags.module_output_path_prefix) .setCreateSourceMap(flags.create_source_map) .setSourceMapFormat(flags.source_map_format) .setWarningGuardSpec(Flags.warningGuardSpec) .setDefine(flags.define) .setCharset(flags.charset) .setManageClosureDependencies(flags.manage_closure_dependencies) .setOnlyClosureDependencies(flags.only_closure_dependencies) .setClosureEntryPoints(flags.closure_entry_point) .setOutputManifest(ImmutableList.of(flags.output_manifest)) .setOutputModuleDependencies(flags.output_module_dependencies) .setAcceptConstKeyword(flags.accept_const_keyword) .setLanguageIn(flags.language_in) .setProcessCommonJSModules(flags.process_common_js_modules) .setCommonJSModulePathPrefix(flags.common_js_path_prefix) .setTransformAMDToCJSModules(flags.transform_amd_modules) .setWarningsWhitelistFile(flags.warnings_whitelist_file); } }
Example 17
Source File: Restore.java From zoocreeper with Apache License 2.0 | 4 votes |
private static void usage(CmdLineParser parser, int exitCode) { System.err.println(Restore.class.getName() + " [options...] arguments..."); parser.printUsage(System.err); System.exit(exitCode); }
Example 18
Source File: Closure_83_CommandLineRunner_s.java From coming with MIT License | 4 votes |
private void initConfigFromFlags(String[] args, PrintStream err) { // Args4j has a different format that the old command-line parser. // So we use some voodoo to get the args into the format that args4j // expects. Pattern argPattern = Pattern.compile("(--[a-zA-Z_]+)=(.*)"); Pattern quotesPattern = Pattern.compile("^['\"](.*)['\"]$"); List<String> processedArgs = Lists.newArrayList(); for (String arg : args) { Matcher matcher = argPattern.matcher(arg); if (matcher.matches()) { processedArgs.add(matcher.group(1)); String value = matcher.group(2); Matcher quotesMatcher = quotesPattern.matcher(value); if (quotesMatcher.matches()) { processedArgs.add(quotesMatcher.group(1)); } else { processedArgs.add(value); } } else { processedArgs.add(arg); } } CmdLineParser parser = new CmdLineParser(flags); isConfigValid = true; try { parser.parseArgument(processedArgs.toArray(new String[] {})); } catch (CmdLineException e) { err.println(e.getMessage()); isConfigValid = false; } if (flags.version) { ResourceBundle config = ResourceBundle.getBundle(configResource); err.println( "Closure Compiler (http://code.google.com/closure/compiler)\n" + "Version: " + config.getString("compiler.version") + "\n" + "Built on: " + config.getString("compiler.date")); err.flush(); } if (!isConfigValid || flags.display_help) { isConfigValid = false; parser.printUsage(err); } else { getCommandLineConfig() .setPrintTree(flags.print_tree) .setComputePhaseOrdering(flags.compute_phase_ordering) .setPrintAst(flags.print_ast) .setPrintPassGraph(flags.print_pass_graph) .setJscompDevMode(flags.jscomp_dev_mode) .setLoggingLevel(flags.logging_level) .setExterns(flags.externs) .setJs(flags.js) .setJsOutputFile(flags.js_output_file) .setModule(flags.module) .setVariableMapInputFile(flags.variable_map_input_file) .setPropertyMapInputFile(flags.property_map_input_file) .setVariableMapOutputFile(flags.variable_map_output_file) .setCreateNameMapFiles(flags.create_name_map_files) .setPropertyMapOutputFile(flags.property_map_output_file) .setCodingConvention(flags.third_party ? new DefaultCodingConvention() : new ClosureCodingConvention()) .setSummaryDetailLevel(flags.summary_detail_level) .setOutputWrapper(flags.output_wrapper) .setOutputWrapperMarker(flags.output_wrapper_marker) .setModuleWrapper(flags.module_wrapper) .setModuleOutputPathPrefix(flags.module_output_path_prefix) .setCreateSourceMap(flags.create_source_map) .setJscompError(flags.jscomp_error) .setJscompWarning(flags.jscomp_warning) .setJscompOff(flags.jscomp_off) .setDefine(flags.define) .setCharset(flags.charset) .setManageClosureDependencies(flags.manage_closure_dependencies) .setClosureEntryPoints(flags.closure_entry_point) .setOutputManifest(flags.output_manifest); } }
Example 19
Source File: Main.java From wildfly-camel with Apache License 2.0 | 4 votes |
private static void helpScreen(CmdLineParser cmdParser) { ConfigLogger.error("fuseconfig [options...]"); cmdParser.printUsage(System.err); }
Example 20
Source File: AreWeConsistentYet.java From are-we-consistent-yet with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Options options = new Options(); CmdLineParser parser = new CmdLineParser(options); try { parser.parseArgument(args); } catch (CmdLineException cle) { PrintStream err = System.err; err.println("are-we-consistent-yet version " + AreWeConsistentYet.class.getPackage() .getImplementationVersion()); err.println("Usage: are-we-consistent-yet" + " --container-name NAME --properties FILE [options...]"); parser.printUsage(err); System.exit(1); } Properties properties = new Properties(); try (InputStream is = new FileInputStream(options.propertiesFile)) { properties.load(is); } Properties propertiesRead = (Properties) properties.clone(); if (options.readerEndpoint != null) { propertiesRead.setProperty(Constants.PROPERTY_ENDPOINT, options.readerEndpoint); } try (BlobStoreContext context = blobStoreContextFromProperties( properties); BlobStoreContext contextRead = blobStoreContextFromProperties( propertiesRead)) { BlobStore blobStore = context.getBlobStore(); BlobStore blobStoreRead = contextRead.getBlobStore(); Location location = null; if (options.location != null) { for (Location loc : blobStore.listAssignableLocations()) { if (loc.getId().equalsIgnoreCase(options.location)) { location = loc; break; } } if (location == null) { throw new Exception("Could not find location: " + options.location); } } blobStore.createContainerInLocation(location, options.containerName); AreWeConsistentYet test = new AreWeConsistentYet( blobStore, blobStoreRead, options.containerName, options.iterations, options.objectSize); PrintStream out = System.out; out.println("eventual consistency count with " + options.iterations + " iterations: "); out.println("read after create: " + test.readAfterCreate()); out.println("read after delete: " + test.readAfterDelete()); out.println("read after overwrite: " + test.readAfterOverwrite()); out.println("list after create: " + test.listAfterCreate()); out.println("list after delete: " + test.listAfterDelete()); blobStore.deleteContainer(options.containerName); } }