org.apache.commons.cli.OptionBuilder Java Examples

The following examples show how to use org.apache.commons.cli.OptionBuilder. 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: EffectiveTomEEXml.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static CommandLine parseCommand(final String[] args) throws SystemExitException {
    final Options options = new Options();
    options.addOption(OptionBuilder.hasArg(true).withLongOpt("path").withDescription("[openejb|tomee].xml path").create("p"));

    final CommandLine line;
    try {
        line = new PosixParser().parse(options, args);
    } catch (final ParseException exp) {
        help(options);
        throw new SystemExitException(-1);
    }

    if (line.hasOption("help")) {
        help(options);
        return null;
    }
    return line;
}
 
Example #3
Source File: BaseSqoopTool.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
protected void addValidationOpts(RelatedOptions validationOptions) {
  validationOptions.addOption(OptionBuilder
    .withDescription("Validate the copy using the configured validator")
    .withLongOpt(VALIDATE_ARG)
    .create());
  validationOptions.addOption(OptionBuilder
    .withArgName(VALIDATOR_CLASS_ARG).hasArg()
    .withDescription("Fully qualified class name for the Validator")
    .withLongOpt(VALIDATOR_CLASS_ARG)
    .create());
  validationOptions.addOption(OptionBuilder
    .withArgName(VALIDATION_THRESHOLD_CLASS_ARG).hasArg()
    .withDescription("Fully qualified class name for ValidationThreshold")
    .withLongOpt(VALIDATION_THRESHOLD_CLASS_ARG)
    .create());
  validationOptions.addOption(OptionBuilder
    .withArgName(VALIDATION_FAILURE_HANDLER_CLASS_ARG).hasArg()
    .withDescription("Fully qualified class name for "
      + "ValidationFailureHandler")
    .withLongOpt(VALIDATION_FAILURE_HANDLER_CLASS_ARG)
    .create());
}
 
Example #4
Source File: CreateJobFunction.java    From sqoop-on-spark with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
public CreateJobFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_LINK_ID))
    .withLongOpt(Constants.OPT_FROM)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_FROM_CHAR)
  );
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_LINK_ID))
    .withLongOpt(Constants.OPT_TO)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_TO_CHAR)
  );
}
 
Example #5
Source File: CodeGenTool.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
@Override
/** Configure the command-line arguments we expect to receive */
public void configureOptions(ToolOptions toolOptions) {

  toolOptions.addUniqueOptions(getCommonOptions());

  RelatedOptions codeGenOpts = getCodeGenOpts(false);
  codeGenOpts.addOption(OptionBuilder.withArgName("table-name")
      .hasArg()
      .withDescription("Table to generate code for")
      .withLongOpt(TABLE_ARG)
      .create());
  codeGenOpts.addOption(OptionBuilder.withArgName("statement")
      .hasArg()
      .withDescription("SQL 'statement' to generate code for")
      .withLongOpt(SQL_QUERY_ARG)
      .create(SQL_QUERY_SHORT_ARG));
  toolOptions.addUniqueOptions(codeGenOpts);

  toolOptions.addUniqueOptions(getOutputFormatOptions());
  toolOptions.addUniqueOptions(getInputFormatOptions());
  toolOptions.addUniqueOptions(getHiveOptions(true));
  toolOptions.addUniqueOptions(getHCatalogOptions());
}
 
Example #6
Source File: Export.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("static-access")
public Options createOptions() {
  
	Options options = super.createOptions();
	
	
	Option entityFetcherThreads = OptionBuilder.withArgName( ENTITY_FETCHER_THREADS ).hasArg()
            .withDescription( "Number of threads to fetch entities in parallel (defaults to 50)" ).create( ENTITY_FETCHER_THREADS );
	options.addOption( entityFetcherThreads);
	
	Option entityMemberFetcherMultiplier = OptionBuilder.withArgName( ENTITY_MEMBER_FETCHER_MULT ).hasArg()
            .withDescription( "This defines the number of threads for fetching entity members like assets/collections by multiplying the number of entity fetcher threads. Defaults to 1" ).create( ENTITY_MEMBER_FETCHER_MULT );
	options.addOption( entityMemberFetcherMultiplier);
	
	return options;
}
 
Example #7
Source File: ImportTool.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
/**
 * Return options for incremental import.
 */
protected RelatedOptions getIncrementalOptions() {
  RelatedOptions incrementalOpts =
      new RelatedOptions("Incremental import arguments");

  incrementalOpts.addOption(OptionBuilder.withArgName("import-type")
      .hasArg()
      .withDescription(
      "Define an incremental import of type 'append' or 'lastmodified'")
      .withLongOpt(INCREMENT_TYPE_ARG)
      .create());
  incrementalOpts.addOption(OptionBuilder.withArgName("column")
      .hasArg()
      .withDescription("Source column to check for incremental change")
      .withLongOpt(INCREMENT_COL_ARG)
      .create());
  incrementalOpts.addOption(OptionBuilder.withArgName("value")
      .hasArg()
      .withDescription("Last imported value in the incremental check column")
      .withLongOpt(INCREMENT_LAST_VAL_ARG)
      .create());

  return incrementalOpts;
}
 
Example #8
Source File: CreateHiveTableTool.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
@Override
/** Configure the command-line arguments we expect to receive */
public void configureOptions(ToolOptions toolOptions) {

  toolOptions.addUniqueOptions(getCommonOptions());

  RelatedOptions hiveOpts = getHiveOptions(false);
  hiveOpts.addOption(OptionBuilder.withArgName("table-name")
      .hasArg()
      .withDescription("The db table to read the definition from")
      .withLongOpt(TABLE_ARG)
      .create());
  toolOptions.addUniqueOptions(hiveOpts);

  toolOptions.addUniqueOptions(getOutputFormatOptions());
}
 
Example #9
Source File: SetServerFunction.java    From sqoop-on-spark with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
public SetServerFunction() {
  this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_HOST)
      .withDescription(resourceString(Constants.RES_SET_HOST_DESCRIPTION))
      .withLongOpt(Constants.OPT_HOST)
      .create(Constants.OPT_HOST_CHAR));
  this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_PORT)
      .withDescription(resourceString(Constants.RES_SET_PORT_DESCRIPTION))
      .withLongOpt(Constants.OPT_PORT)
      .create(Constants.OPT_PORT_CHAR));
  this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_WEBAPP)
      .withDescription(resourceString(Constants.RES_WEBAPP_DESCRIPTION))
      .withLongOpt(Constants.OPT_WEBAPP)
      .create(Constants.OPT_WEBAPP_CHAR));
  this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_URL)
      .withDescription(resourceString(Constants.RES_URL_DESCRIPTION))
      .withLongOpt(Constants.OPT_URL)
      .create(Constants.OPT_URL_CHAR));
}
 
Example #10
Source File: TestGenericOptionsParser.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Test that options passed to the constructor are used.
 */
@SuppressWarnings("static-access")
public void testCreateWithOptions() throws Exception {
  // Create new option newOpt
  Option opt = OptionBuilder.withArgName("int")
  .hasArg()
  .withDescription("A new option")
  .create("newOpt");
  Options opts = new Options();
  opts.addOption(opt);

  // Check newOpt is actually used to parse the args
  String[] args = new String[2];
  args[0] = "--newOpt";
  args[1] = "7";
  GenericOptionsParser g = new GenericOptionsParser(opts, args);
  assertEquals("New option was ignored",
    "7", g.getCommandLine().getOptionValues("newOpt")[0]);
}
 
Example #11
Source File: SQLServerManager.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
/**
 * Create related options for SQL Server extra parameters.
 *
 * @return
 */
@SuppressWarnings("static-access")
private RelatedOptions getExtraOptions() {
  // Connection args (common)
  RelatedOptions extraOptions =
    new RelatedOptions("SQL Server extra options:");

  extraOptions.addOption(OptionBuilder.withArgName("string").hasArg()
    .withDescription("Optional schema name")
    .withLongOpt(SCHEMA).create());

  extraOptions.addOption(OptionBuilder.withArgName("string").hasArg()
    .withDescription("Optional table hints to use")
    .withLongOpt(TABLE_HINTS).create());

  extraOptions.addOption(OptionBuilder
    .withDescription("Allow identity inserts")
    .withLongOpt(IDENTITY_INSERT).create());

  return extraOptions;
}
 
Example #12
Source File: RunFPFTool.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Options getOptions() {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("analysis")
            .withDescription("the analysis id")
            .hasArg()
            .withArgName("ID")
            .create());
    options.addOption(OptionBuilder.withLongOpt("time-horizon")
            .withDescription("time horizon (example DACF)")
            .hasArg()
            .withArgName("TH")
            .create());
    options.addOption(OptionBuilder.withLongOpt("base-case-date")
            .withDescription("base case date (example 2013-01-15T18:45:00+01:00)")
            .hasArg()
            .withArgName("DATE")
            .create());
    options.addOption(OptionBuilder.withLongOpt("output-dir")
            .withDescription("output dir where the FPF output files will be stored")
            .hasArg()
            .isRequired()
            .withArgName("OUTPUTDIR")
            .create());
    return options;
}
 
Example #13
Source File: ZkCopy.java    From helix with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
private static Options constructCmdLineOpt() {
  Option srcOpt =
      OptionBuilder.withLongOpt(src).hasArgs(1).isRequired(true)
          .withArgName("source-URI (e.g. zk://localhost:2181/src-path")
          .withDescription("Provide source URI").create();

  Option dstOpt =
      OptionBuilder.withLongOpt(dst).hasArgs(1).isRequired(true)
          .withArgName("destination-URI (e.g. zk://localhost:2181/dst-path")
          .withDescription("Provide destination URI").create();

  Options options = new Options();
  options.addOption(srcOpt);
  options.addOption(dstOpt);
  return options;
}
 
Example #14
Source File: DeleteRoleFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public DeleteRoleFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_ROLE))
    .withLongOpt(Constants.OPT_ROLE)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_ROLE_CHAR));
}
 
Example #15
Source File: BaseSqoopTool.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
protected RelatedOptions getHBaseOptions() {
  RelatedOptions hbaseOpts =
      new RelatedOptions("HBase arguments");
  hbaseOpts.addOption(OptionBuilder.withArgName("table")
      .hasArg()
      .withDescription("Import to <table> in HBase")
      .withLongOpt(HBASE_TABLE_ARG)
      .create());
  hbaseOpts.addOption(OptionBuilder.withArgName("family")
      .hasArg()
      .withDescription("Sets the target column family for the import")
      .withLongOpt(HBASE_COL_FAM_ARG)
      .create());
  hbaseOpts.addOption(OptionBuilder.withArgName("col")
      .hasArg()
      .withDescription("Specifies which input column to use as the row key")
      .withLongOpt(HBASE_ROW_KEY_ARG)
      .create());
  hbaseOpts.addOption(OptionBuilder
      .withDescription("Enables HBase bulk loading")
      .withLongOpt(HBASE_BULK_LOAD_ENABLED_ARG)
      .create());
  hbaseOpts.addOption(OptionBuilder
      .withDescription("If specified, create missing HBase tables")
      .withLongOpt(HBASE_CREATE_TABLE_ARG)
      .create());

  return hbaseOpts;
}
 
Example #16
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 #17
Source File: StreamJob.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private Option createOption(String name, String desc,
                            String argName, int max, boolean required){
  return OptionBuilder
         .withArgName(argName)
         .hasArgs(max)
         .withDescription(desc)
         .isRequired(required)
         .create(name);
}
 
Example #18
Source File: CloneJobFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public CloneJobFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
    .withLongOpt(Constants.OPT_JID)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_JID_CHAR));
}
 
Example #19
Source File: DeleteLinkFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public DeleteLinkFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_LINK_ID))
    .withLongOpt(Constants.OPT_LID)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_LID_CHAR));
}
 
Example #20
Source File: LinkDynamicConfigOptions.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
@Override
public void prepareOptions(MLink link) {
  this.addOption(OptionBuilder.withLongOpt("name").hasArg().create());
  for (Option option : ConfigOptions.getConfigsOptions("link", link.getConnectorLinkConfig()
      .getConfigs())) {
    this.addOption(option);
  }
}
 
Example #21
Source File: CloneLinkFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public CloneLinkFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_LINK_ID))
    .withLongOpt(Constants.OPT_LID)
    .hasArg()
    .isRequired()
    .create(Constants.OPT_LID_CHAR)
  );
}
 
Example #22
Source File: ShowJobStatusFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public ShowJobStatusFunction() {
  this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
     .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
     .withLongOpt(Constants.OPT_JID)
     .create(Constants.OPT_JID_CHAR));
}
 
Example #23
Source File: SparkCreatingFlatTable.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static Option getSqlOption(int index) {
    return OptionBuilder.withArgName(BatchConstants.ARG_SQL_COUNT + String.valueOf(index))
            .hasArg()
            .isRequired(true)
            .withDescription("Sql0")
            .create(BatchConstants.ARG_BASE64_ENCODED_SQL + String.valueOf(index));
}
 
Example #24
Source File: NetezzaManager.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
protected RelatedOptions getNetezzaExtraOpts() {
  RelatedOptions netezzaOpts = new RelatedOptions("Netezza options");
  netezzaOpts.addOption(OptionBuilder
      .withArgName(NETEZZA_DATASLICE_ALIGNED_ACCESS_OPT).hasArg()
      .withDescription("Data slice aligned import")
      .withLongOpt(NETEZZA_DATASLICE_ALIGNED_ACCESS_LONG_ARG).create());
  return netezzaOpts;
}
 
Example #25
Source File: LocalProctorBuilder.java    From proctor with Apache License 2.0 5 votes vote down vote up
private LocalProctorBuilderArgs() {
    options.addOption(OptionBuilder.hasArg(true)
        .isRequired()
        .withLongOpt("input")
        .withArgName("base input directory")
        .withDescription("The base directory to read from.")
        .create("i"));
    options.addOption(OptionBuilder.hasArg(true)
        .withLongOpt("test-definitions-directory")
        .withArgName("test-definitions directory")
        .withDescription("test-definitions directory, relative to the base directory.")
        .create("d"));
}
 
Example #26
Source File: CreateRoleFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public CreateRoleFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_ROLE))
    .withLongOpt(Constants.OPT_ROLE)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_ROLE_CHAR)
  );
}
 
Example #27
Source File: EnableLinkFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public EnableLinkFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_LINK_ID))
    .withLongOpt(Constants.OPT_LID)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_LID_CHAR));
}
 
Example #28
Source File: DisableLinkFunction.java    From sqoop-on-spark with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
public DisableLinkFunction() {
  this.addOption(OptionBuilder
    .withDescription(resourceString(Constants.RES_PROMPT_LINK_ID))
    .withLongOpt(Constants.OPT_LID)
    .isRequired()
    .hasArg()
    .create(Constants.OPT_LID_CHAR));
}
 
Example #29
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 #30
Source File: EvalSqlTool.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
@Override
/** Configure the command-line arguments we expect to receive */
public void configureOptions(ToolOptions toolOptions) {
  toolOptions.addUniqueOptions(getCommonOptions());

  RelatedOptions evalOpts = new RelatedOptions("SQL evaluation arguments");
  evalOpts.addOption(OptionBuilder.withArgName("statement")
      .hasArg()
      .withDescription("Execute 'statement' in SQL and exit")
      .withLongOpt(SQL_QUERY_ARG)
      .create(SQL_QUERY_SHORT_ARG));

  toolOptions.addUniqueOptions(evalOpts);
}