Java Code Examples for org.apache.commons.cli.OptionBuilder#create()

The following examples show how to use org.apache.commons.cli.OptionBuilder#create() . 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: DBToolOptions.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Option registerTaskOption(String opt, String longOpt, String description, int numArgs, LockId... lockIds) {
	Option option = OptionBuilder.create(opt);
	option.setRequired(false);
	option.setDescription("task: " + description);
	option.setLongOpt(longOpt);
	option.setArgs(numArgs);
	taskOptionMap.put(opt, option);
	LinkedHashSet<LockId> taskLockIdMap = new LinkedHashSet<LockId>();
	if (lockIds != null) {
		for (int i = 0; i < lockIds.length; i++) {
			if (lockIds[i] != null) {
				taskLockIdMap.add(lockIds[i]);
			}
		}
	}
	taskLockIdsMap.put(opt, taskLockIdMap);
	return option;
}
 
Example 2
Source File: UpdateCleaner.java    From Rhombus with MIT License 6 votes vote down vote up
public Options getCommandOptions(){
	Options ret = super.getCommandOptions();
	Option process = new Option( "p", "Process update fixes" );
	ret.addOption(process);

	OptionBuilder.withArgName("timeInNanos");
	OptionBuilder.hasArg();
	OptionBuilder.withDescription("List all updates in the system where the same object has been updated within timeInNanos");
	Option list = OptionBuilder.create( "listUpdates" );
	ret.addOption(list);

	OptionBuilder.withArgName("rowLimit");
	OptionBuilder.hasArg();
	OptionBuilder.withDescription("Limit the processer to only examine rowLimit rows");
	Option rowLimit = OptionBuilder.create( "rowLimit" );
	ret.addOption(rowLimit);

	return ret;
}
 
Example 3
Source File: Server.java    From usergrid with Apache License 2.0 5 votes vote down vote up
static Options createOptions() {
    // the nogui option will be required due to combining the graphical
    // launcher with this standalone CLI based server
    Options options = new Options();
    OptionBuilder.withDescription( "Start launcher without UI" );
    OptionBuilder.isRequired( true );
    Option noguiOption = OptionBuilder.create( "nogui" );

    OptionBuilder.isRequired( false );
    OptionBuilder.withDescription( "Initialize database" );
    Option initOption = OptionBuilder.create( "init" );

    OptionBuilder.withDescription( "Start database" );
    Option dbOption = OptionBuilder.create( "db" );

    OptionBuilder.withDescription( "Http port (without UI)" );
    OptionBuilder.hasArg();
    OptionBuilder.withArgName( "PORT" );
    OptionBuilder.withLongOpt( "port" );
    OptionBuilder.withType( Number.class );
    Option portOption = OptionBuilder.create( 'p' );

    options.addOption( initOption );
    options.addOption( dbOption );
    options.addOption( portOption );
    options.addOption( noguiOption );

    return options;
}
 
Example 4
Source File: DBToolOptions.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Option registerOptionalOption(String opt, String longOpt, String description, int numArgs) {
	Option option = OptionBuilder.create(opt);
	option.setRequired(false);
	option.setDescription("option: " + description);
	option.setLongOpt(longOpt);
	option.setArgs(numArgs);
	optionalOptionMap.put(opt, option);
	return option;
}
 
Example 5
Source File: CommandLineHelper.java    From samza with Apache License 2.0 5 votes vote down vote up
public static Option createOption(String shortOpt, String longOpt, String argName, boolean required,
    String description) {
  OptionBuilder optionBuilder = OptionBuilder.withLongOpt(longOpt).withDescription(description).isRequired(required);

  if (!StringUtils.isEmpty(argName)) {

    optionBuilder = optionBuilder.withArgName(argName).hasArg();
  }

  return optionBuilder.create(shortOpt);
}
 
Example 6
Source File: Utils.java    From carmen with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void registerOption(List<Option> options, String option_name, String arg_name, boolean has_arg, String description) {
	OptionBuilder.withArgName(arg_name);
	OptionBuilder.hasArg(has_arg);
	OptionBuilder.withDescription(description);
	Option option = OptionBuilder.create(option_name);
	
	options.add(option);		
}
 
Example 7
Source File: ExecutePlatformCommandCommand.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private void addOptions(boolean required, Options options, Set<Entry<String, ArgumentDescriptor>> entrySet) {
  for (Entry<String, ArgumentDescriptor> e : entrySet) {
    String argumentName = e.getKey();
    ArgumentDescriptor argumentDescriptor = e.getValue();
    Option option = OptionBuilder.create(argumentName);
    option.setRequired(required);
    String description = argumentDescriptor.getDescription();
    option.setDescription(createDescription(description, required));
    option.setArgs(1);
    options.addOption(option);
  }
}
 
Example 8
Source File: TaskomaticDaemon.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
private void createOption(Options accum, String longopt, boolean arg,
        String argName, String description) {
    OptionBuilder.withArgName(argName);
    OptionBuilder.withLongOpt(longopt);
    OptionBuilder.hasArg(arg);
    OptionBuilder.withDescription(description);
    Option option = OptionBuilder.create(longopt);
    accum.addOption(option);
    if (this.masterOptionsMap.get(longopt) == null) {
        this.masterOptionsMap.put(longopt, option);
    }
}
 
Example 9
Source File: TaskomaticDaemon.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private void createOption(Options accum, String longopt, boolean arg,
                          String argName, String description) {
    OptionBuilder.withArgName(argName);
    OptionBuilder.withLongOpt(longopt);
    OptionBuilder.hasArg(arg);
    OptionBuilder.withDescription(description);
    Option option = OptionBuilder.create(longopt);
    accum.addOption(option);
    if (this.masterOptionsMap.get(longopt) == null) {
        this.masterOptionsMap.put(longopt, option);
    }
}
 
Example 10
Source File: LinkRank.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the LinkRank tool.
 */
public int run(String[] args)
  throws Exception {

  Options options = new Options();
  OptionBuilder.withArgName("help");
  OptionBuilder.withDescription("show this help message");
  Option helpOpts = OptionBuilder.create("help");
  options.addOption(helpOpts);
  
  OptionBuilder.withArgName("webgraphdb");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("the web graph db to use");
  Option webgraphOpts = OptionBuilder.create("webgraphdb");
  options.addOption(webgraphOpts);

  CommandLineParser parser = new GnuParser();
  try {

    CommandLine line = parser.parse(options, args);
    if (line.hasOption("help") || !line.hasOption("webgraphdb")) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("LinkRank", options);
      return -1;
    }

    String webGraphDb = line.getOptionValue("webgraphdb");

    analyze(new Path(webGraphDb));
    return 0;
  }
  catch (Exception e) {
    LOG.error("LinkAnalysis: " + StringUtils.stringifyException(e));
    return -2;
  }
}
 
Example 11
Source File: ResolveUrls.java    From nutch-htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Runs the resolve urls tool.
 */
public static void main(String[] args) {

  Options options = new Options();
  OptionBuilder.withArgName("help");
  OptionBuilder.withDescription("show this help message");
  Option helpOpts = OptionBuilder.create("help");
  options.addOption(helpOpts);
  
  OptionBuilder.withArgName("urls");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("the urls file to check");
  Option urlOpts = OptionBuilder.create("urls");
  options.addOption(urlOpts);
  
  OptionBuilder.withArgName("numThreads");
  OptionBuilder.hasArgs();
  OptionBuilder.withDescription("the number of threads to use");
  Option numThreadOpts = OptionBuilder.create("numThreads");
  options.addOption(numThreadOpts);

  CommandLineParser parser = new GnuParser();
  try {
    // parse out common line arguments
    CommandLine line = parser.parse(options, args);
    if (line.hasOption("help") || !line.hasOption("urls")) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("ResolveUrls", options);
      return;
    }

    // get the urls and the number of threads and start the resolver
    String urls = line.getOptionValue("urls");
    int numThreads = 100;
    String numThreadsStr = line.getOptionValue("numThreads");
    if (numThreadsStr != null) {
      numThreads = Integer.parseInt(numThreadsStr);
    }
    ResolveUrls resolve = new ResolveUrls(urls, numThreads);
    resolve.resolveUrls();
  }
  catch (Exception e) {
    LOG.error("ResolveUrls: " + StringUtils.stringifyException(e));
  }
}
 
Example 12
Source File: NodeReader.java    From nutch-htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Runs the NodeReader tool.  The command line arguments must contain a 
 * webgraphdb path and a url.  The url must match the normalized url that is
 * contained in the NodeDb of the WebGraph.
 */
public static void main(String[] args)
  throws Exception {

  Options options = new Options();
  OptionBuilder.withArgName("help");
  OptionBuilder.withDescription("show this help message");
  Option helpOpts = OptionBuilder.create("help");
  options.addOption(helpOpts);
  
  OptionBuilder.withArgName("webgraphdb");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("the webgraphdb to use");
  Option webGraphOpts = OptionBuilder.create("webgraphdb");
  options.addOption(webGraphOpts);
  
  OptionBuilder.withArgName("url");
  OptionBuilder.hasOptionalArg();
  OptionBuilder.withDescription("the url to dump");
  Option urlOpts = OptionBuilder.create("url");
  options.addOption(urlOpts);

  CommandLineParser parser = new GnuParser();
  try {

    // command line must take a webgraphdb and a url
    CommandLine line = parser.parse(options, args);
    if (line.hasOption("help") || !line.hasOption("webgraphdb")
      || !line.hasOption("url")) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("WebGraphReader", options);
      return;
    }

    // dump the values to system out and return
    String webGraphDb = line.getOptionValue("webgraphdb");
    String url = line.getOptionValue("url");
    NodeReader reader = new NodeReader(NutchConfiguration.create());
    reader.dumpUrl(new Path(webGraphDb), url);
    
    return;
  }
  catch (Exception e) {
    e.printStackTrace();
    return;
  }
}
 
Example 13
Source File: ScoreUpdater.java    From nutch-htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Runs the ScoreUpdater tool.
 */
public int run(String[] args)
  throws Exception {

  Options options = new Options();
  OptionBuilder.withArgName("help");
  OptionBuilder.withDescription("show this help message");
  Option helpOpts = OptionBuilder.create("help");
  options.addOption(helpOpts);
  
  OptionBuilder.withArgName("crawldb");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("the crawldb to use");
  Option crawlDbOpts = OptionBuilder.create("crawldb");
  options.addOption(crawlDbOpts);
  
  OptionBuilder.withArgName("webgraphdb");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("the webgraphdb to use");
  Option webGraphOpts = OptionBuilder.create("webgraphdb");
  options.addOption(webGraphOpts);

  CommandLineParser parser = new GnuParser();
  try {

    CommandLine line = parser.parse(options, args);
    if (line.hasOption("help") || !line.hasOption("webgraphdb")
      || !line.hasOption("crawldb")) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("ScoreUpdater", options);
      return -1;
    }

    String crawlDb = line.getOptionValue("crawldb");
    String webGraphDb = line.getOptionValue("webgraphdb");
    update(new Path(crawlDb), new Path(webGraphDb));
    return 0;
  }
  catch (Exception e) {
    LOG.error("ScoreUpdater: " + StringUtils.stringifyException(e));
    return -1;
  }
}
 
Example 14
Source File: WebGraph.java    From nutch-htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Parses command link arguments and runs the WebGraph jobs.
 */
public int run(String[] args)
  throws Exception {

  Options options = new Options();
  OptionBuilder.withArgName("help");
  OptionBuilder.withDescription("show this help message");
  Option helpOpts = OptionBuilder.create("help");
  options.addOption(helpOpts);
  
  OptionBuilder.withArgName("webgraphdb");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("the web graph database to use");
  Option webGraphDbOpts = OptionBuilder.create("webgraphdb");
  options.addOption(webGraphDbOpts);
  
  OptionBuilder.withArgName("segment");
  OptionBuilder.hasArgs();
  OptionBuilder.withDescription("the segment(s) to use");
  Option segOpts = OptionBuilder.create("segment");
  options.addOption(segOpts);
  
  OptionBuilder.withArgName("segmentDir");
  OptionBuilder.hasArgs();
  OptionBuilder.withDescription("the segment directory to use");
  Option segDirOpts = OptionBuilder.create("segmentDir");
  options.addOption(segDirOpts);
  
  OptionBuilder.withArgName("normalize");
  OptionBuilder.withDescription("whether to use URLNormalizers on the URL's in the segment");
  Option normalizeOpts = OptionBuilder.create("normalize");
  options.addOption(normalizeOpts);
  
  OptionBuilder.withArgName("filter");
  OptionBuilder.withDescription("whether to use URLFilters on the URL's in the segment");
  Option filterOpts = OptionBuilder.create("filter");
  options.addOption(filterOpts);

  CommandLineParser parser = new GnuParser();
  try {

    CommandLine line = parser.parse(options, args);
    if (line.hasOption("help") || !line.hasOption("webgraphdb")
      || (!line.hasOption("segment") && !line.hasOption("segmentDir"))) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("WebGraph", options);
      return -1;
    }

    String webGraphDb = line.getOptionValue("webgraphdb");

    Path[] segPaths = null;

    // Handle segment option
    if (line.hasOption("segment")) {
      String[] segments = line.getOptionValues("segment");
      segPaths = new Path[segments.length];
      for (int i = 0; i < segments.length; i++) {
        segPaths[i] = new Path(segments[i]);
      }
    }

    // Handle segmentDir option
    if (line.hasOption("segmentDir")) {
      Path dir = new Path(line.getOptionValue("segmentDir"));
      FileSystem fs = dir.getFileSystem(getConf());
      FileStatus[] fstats = fs.listStatus(dir, HadoopFSUtil.getPassDirectoriesFilter(fs));
      segPaths = HadoopFSUtil.getPaths(fstats);
    }

    boolean normalize = false;

    if (line.hasOption("normalize")) {
      normalize = true;
    }

    boolean filter = false;

    if (line.hasOption("filter")) {
      filter = true;
    }

    createWebGraph(new Path(webGraphDb), segPaths, normalize, filter);
    return 0;
  }
  catch (Exception e) {
    LOG.error("WebGraph: " + StringUtils.stringifyException(e));
    return -2;
  }
}
 
Example 15
Source File: JMXGet.java    From RDFS with Apache License 2.0 4 votes vote down vote up
/**
 * parse args
 */
private static CommandLine parseArgs(Options opts, String ...args) 
throws IllegalArgumentException{

  OptionBuilder.withArgName("NameNode|DataNode");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify jmx service (NameNode by default)");
  Option jmx_service = OptionBuilder.create("service");

  OptionBuilder.withArgName("mbean server");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify mbean server (localhost by default)");
  Option jmx_server = OptionBuilder.create("server");

  OptionBuilder.withDescription("print help");
  Option jmx_help = OptionBuilder.create("help");

  OptionBuilder.withArgName("mbean server port");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify mbean server port, " +
  "if missing - it will try to connect to MBean Server in the same VM");
  Option jmx_port = OptionBuilder.create("port");

  OptionBuilder.withArgName("VM's pid");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("connect to the VM on the same machine");
  Option jmx_localVM = OptionBuilder.create("localVM");

  opts.addOption(jmx_server);
  opts.addOption(jmx_help);
  opts.addOption(jmx_service);
  opts.addOption(jmx_port);
  opts.addOption(jmx_localVM);

  CommandLine commandLine=null;
  CommandLineParser parser = new GnuParser();
  try {
    commandLine = parser.parse(opts, args, true);
  } catch(ParseException e) {
    printUsage(opts);
    throw new IllegalArgumentException("invalid args: " + e.getMessage()); 
  }
  return commandLine;
}
 
Example 16
Source File: JMXGet.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * parse args
 */
private static CommandLine parseArgs(Options opts, String... args)
throws IllegalArgumentException {

  OptionBuilder.withArgName("NameNode|DataNode");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify jmx service (NameNode by default)");
  Option jmx_service = OptionBuilder.create("service");

  OptionBuilder.withArgName("mbean server");
  OptionBuilder.hasArg();
  OptionBuilder
  .withDescription("specify mbean server (localhost by default)");
  Option jmx_server = OptionBuilder.create("server");

  OptionBuilder.withDescription("print help");
  Option jmx_help = OptionBuilder.create("help");

  OptionBuilder.withArgName("mbean server port");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify mbean server port, "
      + "if missing - it will try to connect to MBean Server in the same VM");
  Option jmx_port = OptionBuilder.create("port");

  OptionBuilder.withArgName("VM's connector url");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("connect to the VM on the same machine;"
      + "\n use:\n jstat -J-Djstat.showUnsupported=true -snap <vmpid> | "
      + "grep sun.management.JMXConnectorServer.address\n "
      + "to find the url");
  Option jmx_localVM = OptionBuilder.create("localVM");

  opts.addOption(jmx_server);
  opts.addOption(jmx_help);
  opts.addOption(jmx_service);
  opts.addOption(jmx_port);
  opts.addOption(jmx_localVM);

  CommandLine commandLine = null;
  CommandLineParser parser = new GnuParser();
  try {
    commandLine = parser.parse(opts, args, true);
  } catch (ParseException e) {
    printUsage(opts);
    throw new IllegalArgumentException("invalid args: " + e.getMessage());
  }
  return commandLine;
}
 
Example 17
Source File: JMXGet.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * parse args
 */
private static CommandLine parseArgs(Options opts, String... args)
throws IllegalArgumentException {

  OptionBuilder.withArgName("NameNode|DataNode");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify jmx service (NameNode by default)");
  Option jmx_service = OptionBuilder.create("service");

  OptionBuilder.withArgName("mbean server");
  OptionBuilder.hasArg();
  OptionBuilder
  .withDescription("specify mbean server (localhost by default)");
  Option jmx_server = OptionBuilder.create("server");

  OptionBuilder.withDescription("print help");
  Option jmx_help = OptionBuilder.create("help");

  OptionBuilder.withArgName("mbean server port");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify mbean server port, "
      + "if missing - it will try to connect to MBean Server in the same VM");
  Option jmx_port = OptionBuilder.create("port");

  OptionBuilder.withArgName("VM's connector url");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("connect to the VM on the same machine;"
      + "\n use:\n jstat -J-Djstat.showUnsupported=true -snap <vmpid> | "
      + "grep sun.management.JMXConnectorServer.address\n "
      + "to find the url");
  Option jmx_localVM = OptionBuilder.create("localVM");

  opts.addOption(jmx_server);
  opts.addOption(jmx_help);
  opts.addOption(jmx_service);
  opts.addOption(jmx_port);
  opts.addOption(jmx_localVM);

  CommandLine commandLine = null;
  CommandLineParser parser = new GnuParser();
  try {
    commandLine = parser.parse(opts, args, true);
  } catch (ParseException e) {
    printUsage(opts);
    throw new IllegalArgumentException("invalid args: " + e.getMessage());
  }
  return commandLine;
}
 
Example 18
Source File: Test.java    From usergrid with Apache License 2.0 3 votes vote down vote up
@Override
public Options createOptions() {

    Option useSpring = OptionBuilder.create( "spring" );

    Options options = new Options();
    options.addOption( useSpring );

    return options;
}
 
Example 19
Source File: PopulateSample.java    From usergrid with Apache License 2.0 3 votes vote down vote up
@Override
public Options createOptions() {

    Option useSpring = OptionBuilder.create( "spring" );

    Options options = new Options();
    options.addOption( useSpring );

    return options;
}
 
Example 20
Source File: ApiDoc.java    From usergrid with Apache License 2.0 3 votes vote down vote up
@Override
public Options createOptions() {

    Option generateWadl = OptionBuilder.create( "wadl" );

    Options options = new Options();
    options.addOption( generateWadl );

    return options;
}