List of usage examples for org.apache.commons.cli OptionBuilder withDescription
public static OptionBuilder withDescription(String newDescription)
From source file:org.lilyproject.runtime.cli.LilyRuntimeCli.java
private void run(String[] args) throws Exception { // Forward JDK logging to SLF4J LogManager.getLogManager().reset(); LogManager.getLogManager().getLogger("").addHandler(new SLF4JBridgeHandler()); LogManager.getLogManager().getLogger("").setLevel(Level.ALL); Options cliOptions = new Options(); Option confDirsOption = OptionBuilder.withArgName("confdir").hasArg() .withDescription("The Lily runtime configuration directory. Can be multiple paths separated by " + File.pathSeparator) .withLongOpt("confdir").create('c'); cliOptions.addOption(confDirsOption); Option repositoryLocationOption = OptionBuilder.withArgName("maven-repo-path").hasArg() .withDescription(// w ww .j a v a 2 s . c om "Location of the (Maven-style) artifact repository. Use comma-separated entries to " + "specify multiple locations which will be searched in the order as specified.") .withLongOpt("repository").create('r'); cliOptions.addOption(repositoryLocationOption); Option disabledModulesOption = OptionBuilder.withArgName("mod-id1,mod-id2,...").hasArg() .withDescription("Comma-separated list of modules that should be disabled.") .withLongOpt("disable-modules").create('i'); cliOptions.addOption(disabledModulesOption); Option disableClassSharingOption = OptionBuilder .withDescription("Disable optional sharing of classes between modules") .withLongOpt("disable-class-sharing").create('d'); cliOptions.addOption(disableClassSharingOption); Option consoleLoggingOption = OptionBuilder.withArgName("loglevel").hasArg() .withDescription("Enable logging to console for the root log category with specified loglevel " + "(debug, info, warn, error)") .withLongOpt("console-logging").create('l'); cliOptions.addOption(consoleLoggingOption); Option consoleLogCatOption = OptionBuilder.withArgName("logcategory").hasArg() .withDescription("Enable console logging only for this category") .withLongOpt("console-log-category").create('m'); cliOptions.addOption(consoleLogCatOption); Option logConfigurationOption = OptionBuilder.withArgName("config").hasArg() .withDescription("Log4j configuration file (properties or .xml)").withLongOpt("log-configuration") .create("o"); cliOptions.addOption(logConfigurationOption); Option classLoadingLoggingOption = OptionBuilder .withDescription("Print information about the classloader setup (at startup).") .withLongOpt("classloader-log").create("z"); cliOptions.addOption(classLoadingLoggingOption); Option verboseOption = OptionBuilder.withDescription("Prints lots of information.").withLongOpt("verbose") .create("v"); cliOptions.addOption(verboseOption); Option quietOption = OptionBuilder.withDescription("Suppress normal output.").withLongOpt("quiet") .create("q"); cliOptions.addOption(quietOption); Option sourceLocationsOption = OptionBuilder.withArgName("sourcelocationfile").hasArg() .withDescription( "Path to property file containing alternate source location directory for artifacts.") .withLongOpt("source-locations").create("s"); cliOptions.addOption(sourceLocationsOption); Option modeOption = OptionBuilder.withArgName("modename").hasArg() .withDescription("The runtime mode: prototype, production").withLongOpt("runtime-mode").create("p"); cliOptions.addOption(modeOption); Option versionOption = OptionBuilder.withDescription( "Don't start the service, only dump the version info string for the module defined with -Dlilyruntime.info.module") .withLongOpt("version").create("V"); cliOptions.addOption(versionOption); Option helpOption = new Option("h", "help", false, "Shows help"); cliOptions.addOption(helpOption); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; boolean showHelp = false; try { cmd = parser.parse(cliOptions, args); } catch (ParseException e) { showHelp = true; } if (showHelp || cmd.hasOption(helpOption.getOpt())) { printHelp(cliOptions); System.exit(1); } Logging.setupLogging(cmd.hasOption(verboseOption.getOpt()), cmd.hasOption(quietOption.getOpt()), cmd.hasOption(classLoadingLoggingOption.getOpt()), cmd.getOptionValue(logConfigurationOption.getOpt()), cmd.getOptionValue(consoleLoggingOption.getOpt()), cmd.getOptionValue(consoleLogCatOption.getOpt())); try { Logging.registerLog4jMBeans(); } catch (JMException e) { infolog.error("Unable to register log4j JMX control", e); } infolog.info("Starting the Lily Runtime."); List<File> confDirs = new ArrayList<File>(); if (!cmd.hasOption(confDirsOption.getOpt())) { File confDir = new File(DEFAULT_CONF_DIR).getAbsoluteFile(); if (!confDir.exists()) { System.out.println("Default configuration directory " + DEFAULT_CONF_DIR + " not found in current directory: " + confDir.getAbsolutePath()); System.out .println("To specify another location, use the -" + confDirsOption.getOpt() + " argument"); System.exit(1); } confDirs.add(confDir); } else { String confPathArg = cmd.getOptionValue(confDirsOption.getOpt()); String[] confPaths = confPathArg.split(File.pathSeparator); for (String confPath : confPaths) { confPath = confPath.trim(); if (confPath.length() == 0) { continue; } File confDir = new File(confPath); if (!confDir.exists()) { System.out.println( "Specified configuration directory does not exist: " + confDir.getAbsolutePath()); System.exit(1); } confDirs.add(confDir); } } ArtifactRepository artifactRepository; if (cmd.hasOption(repositoryLocationOption.getOpt())) { artifactRepository = new ChainedMaven2StyleArtifactRepository( cmd.getOptionValue(repositoryLocationOption.getOpt())); } else { File maven2Repository = findLocalMavenRepository(); infolog.info("Using local Maven repository at " + maven2Repository.getAbsolutePath()); artifactRepository = new Maven2StyleArtifactRepository(maven2Repository); } Set<String> disabledModuleIds = getDisabledModuleIds(cmd.getOptionValue(disabledModulesOption.getOpt())); SourceLocations sourceLocations; if (cmd.hasOption(sourceLocationsOption.getOpt())) { File file = new File(cmd.getOptionValue(sourceLocationsOption.getOpt())).getAbsoluteFile(); if (!file.exists()) { System.out.println( "The specified source locations property file does not exist: " + file.getAbsolutePath()); System.exit(1); } InputStream is = null; try { is = new FileInputStream(file); sourceLocations = new SourceLocations(is, file.getParent()); } catch (Throwable t) { throw new LilyRTException("Problem reading source locations property file.", t); } finally { IOUtils.closeQuietly(is); } } else { sourceLocations = new SourceLocations(); } LilyRuntimeSettings settings = new LilyRuntimeSettings(); settings.setConfManager(new ConfManagerImpl(confDirs)); settings.setDisabledModuleIds(disabledModuleIds); settings.setRepository(artifactRepository); settings.setSourceLocations(sourceLocations); settings.setEnableArtifactSharing(!cmd.hasOption(disableClassSharingOption.getOpt())); LilyRuntime runtime = new LilyRuntime(settings); if (cmd.hasOption(modeOption.getOpt())) { String optionValue = cmd.getOptionValue(modeOption.getOpt()); Mode mode = Mode.byName(optionValue); runtime.setMode(mode); } if (cmd.hasOption(versionOption.getOpt())) { System.out.println(runtime.buildModel().moduleInfo(System.getProperty("lilyruntime.info.module"))); System.exit(0); } try { runtime.start(); Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHandler(runtime))); printStartedMessage(); } catch (Throwable e) { e.printStackTrace(); System.err.println("Startup failed. Will try to shutdown and exit."); try { runtime.stop(); } finally { System.exit(1); } } }
From source file:org.lilyproject.testclientfw.BaseRepositoryTestTool.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); solrOption = OptionBuilder.withArgName("URL").hasArg() .withDescription(/*from www . j a v a2 s .com*/ "URL of Solr. If using cloud mode then use the zookeeper connection string for Solr") .withLongOpt("solr").create("s"); solrCloudOption = OptionBuilder.withDescription("Connect to a Solr cloud server").withLongOpt("solrcloud") .create("sc"); repositoryOption = OptionBuilder.withArgName("repository").hasArg() .withDescription("Repository name, if not specified the default repository is used") .withLongOpt("repository").create(); options.add(solrOption); options.add(solrCloudOption); options.add(repositoryOption); return options; }
From source file:org.lilyproject.testclientfw.BaseTestTool.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); workersOption = OptionBuilder.withArgName("count").hasArg().withDescription("Number of workers (threads)") .withLongOpt("workers").create("w"); options.add(workersOption);/* w w w.j a v a 2 s . c om*/ verboseOption = OptionBuilder.withDescription("Be verbose").withLongOpt("verbose").create("vb"); options.add(verboseOption); hbaseMetricsOption = OptionBuilder .withDescription("Enable HBase metrics options (requires JMX on default port 10102)") .withLongOpt("hbase-metrics").create("hm"); options.add(hbaseMetricsOption); lilyMetricsOption = OptionBuilder .withDescription("Enable Lily metrics options (requires JMX on default port 10202)") .withLongOpt("lily-metrics").create("lm"); options.add(lilyMetricsOption); return options; }
From source file:org.lilyproject.tools.generatesplitkeys.GenerateSplitKeys.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); uuidSplitsOption = OptionBuilder.withArgName("count").hasArg() .withDescription("Generate this amount of UUID splits").withLongOpt("uuid-splits").create("us"); options.add(uuidSplitsOption);/* ww w .j a va 2s. c om*/ uuidSplitsLengthOption = OptionBuilder.withArgName("length").hasArg() .withDescription("Length of UUID split key in bytes").withLongOpt("uuid-splits-length") .create("usl"); options.add(uuidSplitsLengthOption); userIdSplitsOption = OptionBuilder.withArgName("count").hasArg() .withDescription("Generate this amount of USER ID splits").withLongOpt("userid-splits") .create("is"); options.add(userIdSplitsOption); userIdSplitsLengthOption = OptionBuilder.withArgName("length").hasArg() .withDescription("Length of USER split key in bytes").withLongOpt("userid-splits-length") .create("isl"); options.add(userIdSplitsLengthOption); noPrefixOption = OptionBuilder.withDescription("Do not include the type-prefix byte") .withLongOpt("no-prefix").create("np"); options.add(noPrefixOption); return options; }
From source file:org.lilyproject.tools.import_.cli.JsonImportTool.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); workersOption = OptionBuilder.withArgName("count").hasArg().withDescription("Number of workers (threads)") .withLongOpt("workers").create("w"); options.add(workersOption);//from w w w. jav a 2s. co m schemaOnlyOption = OptionBuilder .withDescription("Only import the field types and record types, not the records.") .withLongOpt("schema-only").create("s"); options.add(schemaOnlyOption); quietOption = OptionBuilder .withDescription("Instead of printing out all record ids, only print a dot every 1000 records") .withLongOpt("quiet").create("q"); options.add(quietOption); tableOption = OptionBuilder.withArgName("table").hasArg() .withDescription("Repository table to import to, defaults to record table").withLongOpt("table") .create(); options.add(tableOption); repositoryOption = OptionBuilder.withArgName("repository").hasArg() .withDescription("Repository name, if not specified default repository is used") .withLongOpt("repository").create(); options.add(repositoryOption); fileFormatOption = OptionBuilder.withArgName("format").hasArg() .withDescription("Input file format (see explanation at bottom)").withLongOpt("format").create(); options.add(fileFormatOption); ignoreEmptyFieldsOption = OptionBuilder.withDescription( "Ignores fields defined as empty strings, ignores zero-length lists, ignores nested" + " records containing no fields. When in root record, adds them as fields-to-delete.") .withLongOpt("ignore-empty-fields").create(); options.add(ignoreEmptyFieldsOption); ignoreAndDeleteEmptyFieldsOption = OptionBuilder .withDescription( "Does everything ignore-empty-fields does, and adds empty fields in the root record" + "to the list of fields-to-delete (only makes sense for updates).") .withLongOpt("ignore-and-delete-empty-fields").create(); options.add(ignoreAndDeleteEmptyFieldsOption); maxErrorsOption = OptionBuilder.withArgName("count").hasArg() .withDescription("Give up the import after this amount of errors (only for records, not schema)") .withLongOpt("max-errors").create(); options.add(maxErrorsOption); rolesOption = OptionBuilder.withArgName("roles").hasArg() .withDescription("Comma-separated list of active user roles (excluding tenant part). Only has " + "effect when the NGDATA hbase-authz coprocessor is installed.") .withLongOpt("roles").create(); options.add(rolesOption); return options; }
From source file:org.lilyproject.tools.mboximport.MboxImport.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); fileOption = OptionBuilder.withArgName("file").hasArg().withDescription("File or directory name") .withLongOpt("file").create("f"); options.add(fileOption);/* ww w .j a v a2 s . c o m*/ schemaOption = OptionBuilder.withDescription("Create/update the schema").withLongOpt("schema").create("s"); options.add(schemaOption); return options; }
From source file:org.lilyproject.tools.scanner.cli.ScannerCli.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); limitOption = OptionBuilder.withArgName("number").hasArg() .withDescription("Limit printing to a number of records").withLongOpt("limit").create("l"); options.add(limitOption);//w w w . j a va2 s.co m countOption = OptionBuilder.withDescription("Count the number of records").withLongOpt("count").create("c"); options.add(countOption); printOption = OptionBuilder.withDescription("Print records to the command line").withLongOpt("print") .create("p"); options.add(printOption); configOption = OptionBuilder.hasArg().withArgName("file") .withDescription("Configure the record scanner using a json file").withLongOpt("config").create(); options.add(configOption); startOption = OptionBuilder.hasArg().withArgName("id") .withDescription("Scan records starting at the record with the given ID").withLongOpt("start") .create(); options.add(startOption); stopOption = OptionBuilder.hasArg().withArgName("id") .withDescription("Scan records stopping at the record with the given ID").withLongOpt("stop") .create(); options.add(stopOption); recordTypeOption = OptionBuilder.hasArg().withArgName("{namespace}recordTypeName") .withDescription("Filter records by record type name").withLongOpt("record-type").create("r"); options.add(recordTypeOption); tableOption = OptionBuilder.hasArg().withArgName("table") .withDescription("Repository table to scan (defaults to record)").withLongOpt("table").create(); options.add(tableOption); repositoryOption = OptionBuilder.hasArg().withArgName("repository") .withDescription("Repository name (defaults to 'default')").withLongOpt("repository").create(); options.add(repositoryOption); rolesOption = OptionBuilder.withArgName("roles").hasArg() .withDescription("Comma-separated list of active user roles (excluding tenant part). Only has " + "effect when the NGDATA hbase-authz coprocessor is installed.") .withLongOpt("roles").create(); options.add(rolesOption); return options; }
From source file:org.lilyproject.tools.tester.Tester.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); configFileOption = OptionBuilder.withArgName("config.json").hasArg() .withDescription("Test tool configuration file").withLongOpt("config").create("c"); options.add(configFileOption);//from w w w . j a v a 2 s. co m dumpSampleConfigOption = OptionBuilder.withDescription("Dumps a sample configuration to standard out") .withLongOpt("dump-sample-config").create("d"); options.add(dumpSampleConfigOption); iterationsOption = OptionBuilder.withArgName("iterations").hasArg() .withDescription("Number of times to run the scenario").withLongOpt("iterations").create("i"); options.add(iterationsOption); return options; }
From source file:org.lilyproject.tools.upgrade.UpgradeFrom2_0Tool.java
@Override public List<Option> getOptions() { List<Option> options = super.getOptions(); confirmOption = OptionBuilder.withDescription("Confirm you want to start the upgrade.").create("confirm"); options.add(confirmOption);// w ww. j a v a 2 s . c om return options; }
From source file:org.lockss.devtools.PdfTools.java
protected Options initializeOptions() { Options options = new Options(); OptionBuilder.withLongOpt(HELP_LONG); OptionBuilder.withDescription("Displays this help message"); options.addOption(OptionBuilder.create(HELP)); OptionBuilder.withLongOpt(INPUT_LONG); OptionBuilder.withDescription("Input PDF file"); OptionBuilder.hasArg();/*from w w w . j a v a2 s. com*/ OptionBuilder.withArgName("infile"); options.addOption(OptionBuilder.create(INPUT)); OptionBuilder.withLongOpt(REWRITE_LONG); OptionBuilder.withDescription("Rewrites infile (normalizes token streams, etc.) to outfile"); OptionBuilder.hasArg(); OptionBuilder.withArgName("outfile"); options.addOption(OptionBuilder.create(REWRITE)); OptionBuilder.withLongOpt(TOKEN_STREAMS_LONG); OptionBuilder.withDescription("Dumps all token streams to outfile"); OptionBuilder.hasArg(); OptionBuilder.withArgName("outfile"); options.addOption(OptionBuilder.create(TOKEN_STREAMS)); return options; }