List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt
public static OptionBuilder withLongOpt(String newLongopt)
From source file:com.conversantmedia.mapreduce.tool.AnnotatedToolContext.java
@SuppressWarnings("static-access") private org.apache.commons.cli.Option initOption(Options options, Option anno, String optName) { OptionBuilder.withLongOpt(optName).withArgName(getValue(anno.argName())) .withDescription(getValue(anno.description())).isRequired(anno.required()); if (anno.argCount() > 0) { OptionBuilder.hasArgs(anno.argCount()); }//from ww w. j a v a 2 s . co m return OptionBuilder.create(); }
From source file:eu.crydee.alignment.aligner.MetricsP.java
static private void parseArguments(String[] args) { Options shortCircuitOptions = new Options(); shortCircuitOptions//from ww w . j a v a 2 s . c om .addOption(OptionBuilder.withLongOpt("help").withDescription("Print this message.").create('h')); shortCircuitOptions .addOption(OptionBuilder.withLongOpt("version").withDescription("Print the version.").create('v')); Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt("corpus").hasArg().withArgName("folder-path") .withDescription("Path to the britannica corpus.").create('c')); options.addOption(OptionBuilder.isRequired().withLongOpt("whitelist-path").hasArg().withArgName("file-path") .withDescription("Path to the whitelist of files to test. One " + "city per line.").create('w')); try { CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(shortCircuitOptions, args, true); if (cmd.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("aligner", options, true); System.exit(0); } if (cmd.hasOption('v')) { System.out.println("aligner v1.0.0-SNAPSHOT"); System.exit(0); } cmd = parser.parse(options, args); WHITELIST_FILE_PATH = cmd.getOptionValue('w'); CORPUS_PATH = cmd.getOptionValue('c'); } catch (ParseException ex) { System.err.println("The CLI args could not be parsed."); System.err.println("The error message was:"); System.err.println(" " + ex.getMessage()); System.exit(1); } }
From source file:com.hortonworks.atlas.cli.AtlasCLI.java
/** * /* ww w .j a v a2 s . c o m*/ * @param args * @throws ParseException * @throws Exception */ @SuppressWarnings("static-access") AtlasCLI(String args[]) throws ParseException { CommandLineParser parser = new GnuParser(); opt = new Options(); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.action) .withDescription("action you want to perform [search|createSimpleType|createDataSetType|" + "createProcessType|createSimpleEntity|createDataSetEntity|createProcessEntity" + "|createtrait|loadtraithierarchy|importmysql]") .hasArg().withArgName("action").create() ); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.url) .withDescription("Url for the atlas host http://host:21000").hasArg().withArgName("URL").create() ); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.type).withDescription( "String describing the type of the object. You can find by querying the list - http://host:21000/api/atlas/types?type=CLASS") .hasArg().withArgName("type").create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.name).withDescription("name of type or entity") .hasArg().withArgName("name").create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.description) .withDescription("description of type or entity").hasArg().withArgName("name").create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.inp_type) .withDescription("name of type for input to a lineage").hasArg().withArgName("inp_type").create() ); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.inp_value) .withDescription("value for input to a lineage").hasArg().withArgName("inp_value").create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.out_type) .withDescription("name of output to a lineage").hasArg().withArgName("out_type").create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.out_value) .withDescription("value for output to a lineage").hasArg().withArgName("out_value").create()); opt.addOption( OptionBuilder.withLongOpt(AtlasCLIOptions.traitTypename).withDescription("value for trait type") .hasArg().withArgName(AtlasCLIOptions.traitTypename).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.traitnames).withDescription("name of the trait") .hasArg().withArgName(AtlasCLIOptions.traitnames).create()); opt.addOption( OptionBuilder.withLongOpt(AtlasCLIOptions.parentTraitName).withDescription("value of parent trait ") .hasArg().withArgName(AtlasCLIOptions.parentTraitName).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.supertype).withDescription("Super type").hasArg() .withArgName(AtlasCLIOptions.supertype).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.username).withDescription("mysql username").hasArg() .withArgName(AtlasCLIOptions.username).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.password).withDescription("mysql password").hasArg() .withArgName(AtlasCLIOptions.password).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.mysqlhost) .withDescription("mysql host. It assumes mysql is running on port 3306").hasArg() .withArgName(AtlasCLIOptions.mysqlhost).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.dbname).withDescription("mysql db").hasArg() .withArgName(AtlasCLIOptions.dbname).create()); opt.addOption(OptionBuilder.withLongOpt(AtlasCLIOptions.filepath) .withDescription("json filename. The complete filepath ").hasArg() .withArgName(AtlasCLIOptions.filepath).create()); opt.addOption( OptionBuilder.withLongOpt(AtlasCLIOptions.ambariCluster).withDescription("Ambari Cluster Name") .hasArg().withArgName(AtlasCLIOptions.ambariCluster).create()); opt.addOption(AtlasCLIOptions.listtype, false, "display all types"); opt.addOption(AtlasCLIOptions.createHive, false, "used with importmysql option. Indicating if hive_table types should also be created"); opt.addOption(AtlasCLIOptions.supressPrompt, false, "used with importmysql option. This will suppress the prompt for importing mysql"); opt.addOption(AtlasCLIOptions.genLineage, false, "used with importmysql option. Indicating if hive_table and the the mysql tables should show as lineage"); opt.addOption("help", false, "requesting help"); HelpFormatter formatter = new HelpFormatter(); CommandLine line = parser.parse(opt, args); if (line.hasOption("help") || args.length < 1) { formatter.printHelp("atlasclient", opt); } if (line.hasOption(AtlasCLIOptions.url)) { baseurl = line.getOptionValue(AtlasCLIOptions.url); this.aClient = new AtlasClient(baseurl); } else { System.err.println("url is a mandatory field"); formatter.printHelp("atlasclient", opt); System.exit(1); } // This will list you list all types if (line.hasOption(AtlasCLIOptions.listtype)) { this.listTypes(); } if (line.hasOption(AtlasCLIOptions.action)) { this.action = line.getOptionValue(AtlasCLIOptions.action); String name = line.getOptionValue(AtlasCLIOptions.name); if (AtlasCLIOptions.search.equalsIgnoreCase(this.action)) { searchEntities(line); } else if (AtlasCLIOptions.createSimpleType.equalsIgnoreCase(this.action)) { this.createSimpleType(line); } else if (AtlasCLIOptions.createDataSetType.equalsIgnoreCase(this.action)) { this.createDataSetType(line); } else if (AtlasCLIOptions.createProcessType.equalsIgnoreCase(this.action)) { this.createProcessType(line); } else if (AtlasCLIOptions.createSimpleEntity.equalsIgnoreCase(this.action)) { this.createSimpleEntity(line); } else if (AtlasCLIOptions.createDataSetEntity.equalsIgnoreCase(this.action)) { this.createDataSetEntity(line); } else if (AtlasCLIOptions.createProcessEntity.equalsIgnoreCase(this.action)) { this.createProcessEntity(line); } else if (AtlasCLIOptions.createrait.equalsIgnoreCase(this.action)) { this.createTraitType(line); } else if (AtlasCLIOptions.importMySqlTables.equalsIgnoreCase(this.action)) { try { this.importMysqlTables(line); } catch (Exception e) { e.printStackTrace(); } } else if (AtlasCLIOptions.loadtraithierarchy.equalsIgnoreCase(this.action)) { this.loadHierarchy(line); } else { formatter.printHelp("Usage:", opt); } } }
From source file:com.marklogic.shell.Shell.java
/** * Create a new Shell//from www .j ava 2 s .c om */ public Shell() { Option user = OptionBuilder.withLongOpt("user").hasArg() .withDescription("user to use to connect to Marklogic").create("u"); Option password = OptionBuilder.withLongOpt("password").hasArg() .withDescription("password to use to connect to Marklogic").create("p"); Option host = OptionBuilder.withLongOpt("host").hasArg() .withDescription("host to use to connect to Marklogic").create("H"); Option db = OptionBuilder.withLongOpt("database").hasArg().withDescription("default database").create("d"); Option port = OptionBuilder.withLongOpt("port").hasArg().withType(new java.lang.Integer(800)) .withDescription("port to use to connect to Marklogic. Defaults to 8003").create("P"); Option help = OptionBuilder.withLongOpt("help").withDescription("print help").create("h"); Option loadOption = OptionBuilder.withLongOpt("load").withDescription("load files into database") .create("l"); Option fileOption = OptionBuilder.withLongOpt("file").withDescription("read xquery from file").hasArg() .create("f"); Option formatOption = OptionBuilder.withLongOpt("format").withDescription("pretty print xml output") .create("F"); options = new Options(); options.addOption(user); options.addOption(password); options.addOption(host); options.addOption(db); options.addOption(port); options.addOption(help); options.addOption(loadOption); options.addOption(fileOption); options.addOption(formatOption); //XXX hack to support loading from command line load loader = new load(); for (Iterator i = loader.getOptions().getOptions().iterator(); i.hasNext();) { Option o = (Option) i.next(); options.addOption(o); } historyFile = new File(System.getProperty("user.home") + File.separatorChar + ".cqsh_history"); }
From source file:OneParameterization.java
@SuppressWarnings("static-access") @Override/*from ww w . j a v a2 s.c o m*/ public Options getOptions() { Options options = super.getOptions(); options.addOption( OptionBuilder.withLongOpt("parameterFile").hasArg().withArgName("file").isRequired().create('p')); options.addOption(OptionBuilder.withLongOpt("input").hasArg().withArgName("file").isRequired().create('i')); options.addOption(OptionBuilder.withLongOpt("inputnumber").hasArg().withArgName("input number").isRequired() .create('u')); options.addOption( OptionBuilder.withLongOpt("output").hasArg().withArgName("file").isRequired().create('o')); options.addOption( OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").isRequired().create('b')); options.addOption( OptionBuilder.withLongOpt("algorithm").hasArg().withArgName("name").isRequired().create('a')); options.addOption(OptionBuilder.withLongOpt("properties").hasArgs().withArgName("p1=v1;p2=v2;...") .withValueSeparator(';').create('x')); options.addOption(OptionBuilder.withLongOpt("seed").hasArg().withArgName("value").create('s')); options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e')); options.addOption(OptionBuilder.withLongOpt("metrics").create('m')); options.addOption(OptionBuilder.withLongOpt("reference").hasArg().withArgName("file").create('r')); options.addOption(OptionBuilder.withLongOpt("novariables").create('n')); options.addOption(OptionBuilder.withLongOpt("force").create('f')); //fill in option descriptions for (Object obj : options.getOptions()) { Option option = (Option) obj; option.setDescription(option.getLongOpt()); } return options; }
From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java
private static boolean loadConfiguration(String[] args, String configFile) throws Exception { OptionBuilder.withArgName("file"); OptionBuilder.hasArg();//from w w w. j av a2s . co m OptionBuilder.withDescription("config file"); OptionBuilder.withLongOpt("config"); Option configFileOption = OptionBuilder.create("C"); OptionBuilder.withArgName("property=value"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(); OptionBuilder.withDescription("properties that overrides the ones in config file"); OptionBuilder.withLongOpt("properties"); Option propertiesOption = OptionBuilder.create("P"); Options options = new Options(); options.addOption(configFileOption); options.addOption(propertiesOption); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException pe) { System.out.println(pe.getMessage()); return false; } InputStream in = null; if (configFile == null || configFile.trim().isEmpty()) { configFile = cmd.getOptionValue("C"); if (configFile != null && new File(configFile).isFile()) { in = new FileInputStream(configFile); } } else { in = MosaicHunter.class.getClassLoader().getResourceAsStream(configFile); } if (in != null) { try { ConfigManager.getInstance().loadProperties(in); } catch (IOException ioe) { System.out.println("invalid config file: " + configFile); return false; } finally { in.close(); } } Properties properties = cmd.getOptionProperties("P"); if (properties != null) { ConfigManager.getInstance().putAll(properties); } return !ConfigManager.getInstance().getProperties().isEmpty(); }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a minimum state size option to a given {@link Options} * object./*from w ww. ja v a 2s. co m*/ * * @param options * The <code>Options</code> object to add to. */ private static void addMinStateSizeOption(final Options options) { OptionBuilder.withLongOpt(MIN_STATE_SIZE_KEY_LONG); OptionBuilder.withDescription(MIN_STATE_SIZE_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(SIZE_ARG_NAME); OptionBuilder.withType(int.class); final Option minStateSize = OptionBuilder.create(MIN_STATE_SIZE_KEY); options.addOption(minStateSize); }
From source file:com.linkedin.databus.bootstrap.utils.BootstrapDropSource.java
@SuppressWarnings("static-access") public static int parseArgs(String[] args) throws IOException { CommandLineParser cliParser = new GnuParser(); Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen") .create(HELP_OPT_CHAR);//w w w. j a v a2 s . c o m Option sourceIdOption = OptionBuilder.withLongOpt(SOURCE_ID_OPT_LONG_NAME) .withDescription("Source ID for which tables need to be dropped").hasArg().withArgName("Source ID") .create(SOURCE_ID_OPT_CHAR); Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME) .withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file") .create(BOOTSTRAP_DB_PROP_OPT_CHAR); Option cmdLinePropsOption = OptionBuilder.withLongOpt(CMD_LINE_PROPS_OPT_LONG_NAME) .withDescription("Cmd line override of config properties. Semicolon separated.").hasArg() .withArgName("Semicolon_separated_properties").create(CMD_LINE_PROPS_OPT_CHAR); Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME) .withDescription("Log4j properties to use").hasArg().withArgName("property_file") .create(LOG4J_PROPS_OPT_CHAR); Options options = new Options(); options.addOption(helpOption); options.addOption(sourceIdOption); options.addOption(dbOption); options.addOption(cmdLinePropsOption); options.addOption(log4jPropsOption); CommandLine cmd = null; try { cmd = cliParser.parse(options, args); } catch (ParseException pe) { LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe); throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe); } if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) { String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR); PropertyConfigurator.configure(log4jPropFile); LOG.info("Using custom logging settings from file " + log4jPropFile); } else { PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n"); ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout); Logger.getRootLogger().removeAllAppenders(); Logger.getRootLogger().addAppender(defaultAppender); LOG.info("Using default logging settings"); } if (cmd.hasOption(HELP_OPT_CHAR)) { printCliHelp(options); System.exit(0); } if (!cmd.hasOption(SOURCE_ID_OPT_CHAR)) throw new RuntimeException("Source ID is not provided"); if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) throw new RuntimeException("Bootstrap config is not provided"); String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR); LOG.info("Loading bootstrap DB config from properties file " + propFile); _sBootstrapConfigProps = new Properties(); FileInputStream f = new FileInputStream(propFile); try { _sBootstrapConfigProps.load(f); } finally { f.close(); } if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR)) { String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR); updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString); } return Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR)); }
From source file:net.sf.clichart.main.OptionParser.java
private void addOption(org.apache.commons.cli.Options optionDefs, String[] optionDetails, boolean hasArgument) { // OptionBuilder is a stateful class OptionBuilder.withLongOpt(optionDetails[1]); OptionBuilder.withDescription(optionDetails[2]); if (hasArgument) { OptionBuilder.hasArg(true);/*w ww.j a v a 2 s .c o m*/ OptionBuilder.withValueSeparator(); } if (optionDetails[0] != null) { optionDefs.addOption(OptionBuilder.create(optionDetails[0])); } else { optionDefs.addOption(OptionBuilder.create()); } }
From source file:com.metadave.kash.KashConsole.java
@SuppressWarnings("static-access") public static CommandLine processArgs(String[] args) { Options options = new Options(); Option help = OptionBuilder.withLongOpt("help").withDescription("Print this list of commands").create(); Option nocolor = OptionBuilder.withLongOpt("nocolor").withDescription("Don't use color output").create(); Option noconfig = OptionBuilder.withLongOpt("noconfig").withDescription("Don't read ~/.Kash.config") .create();/*from w w w . j av a 2s .c o m*/ Option infile = OptionBuilder.withLongOpt("infile").withDescription("Read input from file and exit") .hasArg().withArgName("filename").create(); Option nosignals = OptionBuilder.withLongOpt("nosignals") .withDescription("Don't catch the Ctrl-C (INT) signal").create(); options.addOption(help); options.addOption(nocolor); options.addOption(noconfig); options.addOption(infile); options.addOption(nosignals); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Kash", options); System.exit(0); } return line; } catch (ParseException exp) { System.err.println("Error processing command line args: " + exp.getMessage()); System.exit(-1); } return null; }