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

The following examples show how to use org.apache.commons.cli.OptionBuilder#withArgName() . 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: 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 2
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 3
Source File: AddFind.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public AddFind()
{
	super("add", "a");

	OptionBuilder.withArgName("outputDir");
	OptionBuilder.withLongOpt("output");
	OptionBuilder.hasArg();
	OptionBuilder.withDescription("override default download directory");
	OptionBuilder.withType(File.class);
	getOptions().addOption( OptionBuilder.create('o') );
	getOptions().addOption("r", "recurse", false, "recurse sub-directories.");
	getOptions().addOption("f", "find", false, "only find files, don't add.");
	getOptions().addOption("h", "help", false, "display help about this command");
	getOptions().addOption("l", "list", false, "list previous find results");
}
 
Example 4
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 5
Source File: Loops.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the Loops 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 database to use");
  Option webGraphDbOpts = OptionBuilder.create("webgraphdb");
  options.addOption(webGraphDbOpts);

  CommandLineParser parser = new GnuParser();
  try {

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

    String webGraphDb = line.getOptionValue("webgraphdb");
    findLoops(new Path(webGraphDb));
    return 0;
  }
  catch (Exception e) {
    LOG.error("Loops: " + StringUtils.stringifyException(e));
    return -2;
  }
}
 
Example 6
Source File: LinuxOptions.java    From ade with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addPlatformSpecificOptions(Options options){
    OptionBuilder.withArgName(OPTION_YEAR);
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("year of messages in Linux syslogs");
    options.addOption(OptionBuilder.create(OPTION_YEAR));
}
 
Example 7
Source File: Upload.java    From ade with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method to parse specific arguments for "Upload".
 * 
 * @throws AdeException 
 * 
 */
protected final void parseArgs(String[] args) throws AdeException {
    final Options options = new Options();

    OptionBuilder.withArgName(OPTION_DUMP_PARSE_REPORT);
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Specify this option to generate parse report");
    options.addOption(OptionBuilder.create(OPTION_DUMP_PARSE_REPORT));

    final CommandLine line = super.parseArgs(options, args);

    if (line.hasOption(OPTION_DUMP_PARSE_REPORT)) {
        getAdeExtProperties().setParseReportRequested(true);
    }
}
 
Example 8
Source File: Analyze.java    From ade with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method to parse specific arguments for "Analyze".
 */
@Override
protected final void parseArgs(String[] args) throws AdeException {
    final Options options = new Options();

    OptionBuilder.withArgName(OPTION_SOURCES);
    OptionBuilder.withLongOpt(OPTION_SOURCES);
    OptionBuilder.isRequired(false);
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Specify the Source to be analyzed.  ");
    options.addOption(OptionBuilder.create("s"));

    super.parseArgs(options, args);

}
 
Example 9
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 10
Source File: ApplicationArguments.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
private Option createAnOptionWithArgument(String[] argInfo)
{
	OptionBuilder.withArgName(argInfo[0]);
	OptionBuilder.hasArg();
	OptionBuilder.withDescription(argInfo[2]);
	Option opt = OptionBuilder.create( argInfo[0]);
	if (!isStringEmpty(argInfo[1]))
	{
		opt.setLongOpt(argInfo[1]);
	}
	return opt;
}
 
Example 11
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 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: LoopReader.java    From nutch-htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Runs the LoopReader tool.  For this tool to work the loops job must have
 * already been run on the corresponding 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 {

    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;
    }

    String webGraphDb = line.getOptionValue("webgraphdb");
    String url = line.getOptionValue("url");
    LoopReader reader = new LoopReader(NutchConfiguration.create());
    reader.dumpUrl(new Path(webGraphDb), url);
    return;
  }
  catch (Exception e) {
    e.printStackTrace();
    return;
  }
}
 
Example 15
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 16
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 17
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 18
Source File: AdeExtOptions.java    From ade with GNU General Public License v3.0 4 votes vote down vote up
public static Options buildOptions(Options subClassOptions) {
    /* Add the options from subClass */
    Options options = new Options();
    for (Object subClassOption : subClassOptions.getOptions()) {
        Option option = (Option) subClassOption;
        options.addOption(option);
    }

    /* Add the general options */
    OptionBuilder.withArgName(OPTION_HELP);
    OptionBuilder.withLongOpt(OPTION_HELP);
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Print help message and exit");
    options.addOption(OptionBuilder.create('h'));

    OptionBuilder.withArgName(OPTION_INPUT_FILE);
    OptionBuilder.withLongOpt(OPTION_INPUT_FILE);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Input file name or 'stdin'");
    options.addOption(OptionBuilder.create('f'));

    OptionBuilder.withArgName(OPTION_INPUT_DIR);
    OptionBuilder.withLongOpt(OPTION_INPUT_DIR);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Input dir name");
    options.addOption(OptionBuilder.create('d'));

    OptionBuilder.withArgName(OPTION_SOURCES);
    OptionBuilder.withLongOpt(OPTION_SOURCES);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Source Names.");
    options.addOption(OptionBuilder.create('s'));

    OptionBuilder.withArgName(OPTION_OS_TYPE);
    OptionBuilder.withLongOpt(OPTION_OS_TYPE);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("The OS Type."
            + "If this option is omitted, the default is Linux");
    options.addOption(OptionBuilder.create('o'));

    OptionBuilder.withArgName(OPTION_GMT_OFFSET);
    OptionBuilder.withLongOpt(OPTION_GMT_OFFSET);
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("hours offset from GMT");
    options.addOption(OptionBuilder.create('g'));

    return options;
}
 
Example 19
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 20
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;
}