Example usage for org.apache.commons.cli Option getLongOpt

List of usage examples for org.apache.commons.cli Option getLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getLongOpt.

Prototype

public String getLongOpt() 

Source Link

Document

Retrieve the long name of this Option.

Usage

From source file:com.teradata.tempto.runner.TemptoRunnerCommandLineParser.java

private TemptoRunnerOptions commandLineToOptions(CommandLine commandLine) {
    ImmutableMap.Builder<String, String> values = ImmutableMap.<String, String>builder();
    for (Option option : options) {
        Optional<String> value = getOptionValue(commandLine, option);
        if (value.isPresent()) {
            values.put(option.getLongOpt(), value.get());
        }/*from   w  w w  .  j  av  a 2s.com*/
    }
    return new TemptoRunnerOptions(values.build());
}

From source file:com.bbva.kltt.apirest.core.launcher.GlobalLauncher.java

/**
 * Return the String option value from the command line given the representing option
 *
 * @param option with the representing option of the command line
 * @return the value of the option, null if unsettled
 *//*from w ww.  ja v a  2s  .  co  m*/
protected String getCmdStringOption(final Option option) {
    if (this.commandLine.hasOption(option.getOpt())) {
        return this.commandLine.getOptionValue(option.getOpt()).trim();
    } else if (this.commandLine.hasOption(option.getLongOpt())) {
        return this.commandLine.getOptionValue(option.getLongOpt()).trim();
    }

    return null;
}

From source file:com.zimbra.cs.localconfig.LocalConfigCLI.java

/**
 * Prints supported usage to stdout. Removes hidden options from the list to be printed
 *
 *//*  w  ww.  j  a  v a2 s  .c  om*/
private void usage() {
    Collection<Object> options = mOptions.getOptions();
    Options displayOptions = new Options();
    for (Object obj : options) {
        // copy over the supported options
        Option opt = (Option) obj; // should be a safe cast, this api REALLY needs generics
        if (!"all".equals(opt.getLongOpt())) {
            displayOptions.addOption(opt);
        }
    }
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("zmlocalconfig [options] [args]", "where [options] are:", displayOptions, "");
    System.exit(0);
}

From source file:com.emc.ecs.sync.config.ConfigUtilTest.java

private void assertOption(org.apache.commons.cli.Option option, String longOpt, boolean required, int args,
        String argName) {//from   w w w.  jav a 2s. com
    Assert.assertNull(option.getOpt());
    Assert.assertEquals(longOpt, option.getLongOpt());
    Assert.assertEquals(required, option.isRequired());
    Assert.assertEquals(args, option.getArgs());
    Assert.assertEquals(argName, option.getArgName());
}

From source file:edu.cmu.tetrad.cli.ExtendedCommandLineParser.java

/**
 * Query to see if the option is passed in from command-line.
 *
 * @param option option to search for//from  w  w  w  .  jav a 2  s.  co  m
 * @param arguments inputs from the command-line
 * @return true if the option is passed in from command-line
 */
public boolean hasOption(Option option, String[] arguments) {
    if (option == null || arguments == null) {
        return false;
    }

    for (String argument : arguments) {
        if (argument.startsWith("--")) {
            argument = argument.substring(2, argument.length());
            if (argument.equals(option.getLongOpt())) {
                return true;
            }
        } else if (argument.startsWith("-")) {
            argument = argument.substring(1, argument.length());
            if (argument.equals(option.getOpt())) {
                return true;
            }
        }
    }

    return false;
}

From source file:com.bc.fiduceo.post.PostProcessingToolTest.java

@Test
public void testOptions() {
    final Options options = PostProcessingTool.getOptions();
    assertEquals(6, options.getOptions().size());

    Option o;

    o = options.getOption("c");
    assertNotNull(o);/*www  .ja v a 2  s . c  o  m*/
    assertEquals("config", o.getLongOpt());
    assertEquals("Defines the configuration directory. Defaults to './config'.", o.getDescription());
    assertEquals(true, o.hasArg());
    assertEquals(false, o.isRequired());

    o = options.getOption("i");
    assertNotNull(o);
    assertEquals("input-dir", o.getLongOpt());
    assertEquals("Defines the path to the input mmd files directory.", o.getDescription());
    assertEquals(true, o.hasArg());
    assertEquals(true, o.isRequired());

    o = options.getOption("end");
    assertNotNull(o);
    assertEquals("end-date", o.getLongOpt());
    assertEquals("Defines the processing end-date, format 'yyyy-DDD'. DDD = Day of year.", o.getDescription());
    assertEquals(true, o.hasArg());
    assertEquals(true, o.isRequired());

    o = options.getOption("h");
    assertNotNull(o);
    assertEquals("help", o.getLongOpt());
    assertEquals("Prints the tool usage.", o.getDescription());
    assertEquals(false, o.hasArg());
    assertEquals(false, o.isRequired());

    o = options.getOption("j");
    assertNotNull(o);
    assertEquals("job-config", o.getLongOpt());
    assertEquals(
            "Defines the path to post processing job configuration file. Path is relative to the configuration directory.",
            o.getDescription());
    assertEquals(true, o.hasArg());
    assertEquals(true, o.isRequired());

    o = options.getOption("start");
    assertNotNull(o);
    assertEquals("start-date", o.getLongOpt());
    assertEquals("Defines the processing start-date, format 'yyyy-DDD'. DDD = Day of year.",
            o.getDescription());
    assertEquals(true, o.hasArg());
    assertEquals(true, o.isRequired());
}

From source file:com.github.dmyersturnbull.transformations.CommandLineHelper.java

@Nonnull
public CommandLineHelper addOptions(@Nonnull Option... additionalOptions) {
    for (Option option : additionalOptions) {
        m_options.addOption(option);//  w  ww.  j  a  va2s . c o m
        if (m_shortNames.contains(option.getOpt())) {
            throw new IllegalArgumentException("Option with short name " + option.getOpt() + " already exists");
        }
        m_shortNames.add(option.getOpt());
        if (option.getLongOpt() != null) {
            if (m_longNames.contains(option.getLongOpt())) {
                throw new IllegalArgumentException(
                        "Option with long name " + option.getLongOpt() + " already exists");
            }
            m_longNames.add(option.getLongOpt());
        }
    }
    return this;
}

From source file:jtabwb.launcher.CmdLineOptions.java

void defineCmdLineOptions() {
    LinkedList<Option> lo = new LinkedList<Option>();

    // HELP//from ww  w  .j  ava  2s  . com
    lo.add(Option.builder(OptNames.HELP).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.HELP).build());
    // INPUT
    lo.add(Option.builder(OptNames.INPUT).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.INPUT_FORMULA)
            .build());
    // LATEX_CTREE
    lo.add(Option.builder().longOpt(OptNames.LATEX_CTREE)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LATEX_CTREE_FILE).build());
    // LATEX_PROOF
    lo.add(Option.builder().longOpt(OptNames.LATEX_PROOF)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LATEX_PROOF_FILE).build());
    if (configuration.availableProvers.size() > 1) {
        // LIST_PROVERS
        lo.add(Option.builder().longOpt(OptNames.LIST_PROVERS)
                .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LIST_PROVERS).build());
        // PROVER
        if (configuration.availableProvers.size() > 1)
            lo.add(Option.builder(OptNames.PROVER).hasArg().argName("name")
                    .desc(String.format(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.PROVER,
                            configuration.availableProvers.getNames()))
                    .build());
    }
    if (configuration.availableReaders.size() > 1) {
        // READER
        lo.add(Option.builder(OptNames.READER).hasArg().argName("name")
                .desc(String.format(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.READER,
                        configuration.availableReaders.getNames()))
                .build());
        // LIST_READERS
        lo.add(Option.builder().longOpt(OptNames.LIST_READERS)
                .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LIST_READER).build());
    }
    // LOG
    lo.add(Option.builder().longOpt(OptNames.LOG).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LOG_FILE)
            .build());
    // LOG_TIME
    lo.add(Option.builder().longOpt(OptNames.LOG_TIME).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LOG_TIME)
            .build());
    // SAVE_TRACE
    lo.add(Option.builder().longOpt(OptNames.SAVE_TRACE)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.PTRACE_FILE).build());
    // VERBOSE
    lo.add(Option.builder(OptNames.VERBOSE).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.VERBOSE).build());
    // TESTSET
    lo.add(Option.builder().longOpt(OptNames.TESTSET).hasArg(true).argName("test-name")
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.TESTSET).build());
    // LOGDIR
    lo.add(Option.builder().longOpt(OptNames.LOG_DIR).hasArg(true).argName("filename")
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LOGDIR).build());
    // F3_TIME_STR
    lo.add(Option.builder().longOpt(OptNames.F3_TIME_STR).hasArg(false)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.F3_TIME_STR).build());
    // JTABWB_TIME_STR 
    lo.add(Option.builder().longOpt(OptNames.JTABWB_TIME_STR).hasArg(false)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.JTABWB_TIME_STR).build());

    for (Option opt : lo)
        if (configuration.cmdLineOptions.getOption(opt.getOpt()) != null
                || configuration.cmdLineOptions.getOption(opt.getLongOpt()) != null)
            throw new LauncherOptionDefinitionException(String.format(
                    MSG.CMD_LINE_OPTIONS.EXCEPTIONS.LAUNCHER_OPTION_NAME_REDEFINITION_ERROR, opt.getOpt()));
        else
            configuration.cmdLineOptions.addOption(opt);
}

From source file:com.google.api.codegen.GeneratorMain.java

public static void packageGeneratorMain(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(DESCRIPTOR_SET_OPTION);
    options.addOption(SERVICE_YAML_NONREQUIRED_OPTION);
    options.addOption(LANGUAGE_OPTION);//from  w ww  .  j ava  2s.  c o  m
    Option inputOption = Option.builder("i").longOpt("input")
            .desc("The input directory containing the gRPC package.").hasArg().argName("INPUT-DIR")
            .required(true).build();
    options.addOption(inputOption);
    options.addOption(OUTPUT_OPTION);
    options.addOption(PACKAGE_YAML2_OPTION);
    Option artifactTypeOption = Option.builder().longOpt("artifact_type")
            .desc("Optional. Artifacts enabled for the generator. Currently supports "
                    + "'GRPC' and 'PROTOBUF' and is ignored for all languages except Java")
            .hasArg().argName("ARTIFACT-TYPE").required(false).build();
    options.addOption(artifactTypeOption);

    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("PackageGeneratorTool", options);
    }

    ToolOptions toolOptions = ToolOptions.create();
    toolOptions.set(PackageGeneratorApp.LANGUAGE, cl.getOptionValue(LANGUAGE_OPTION.getLongOpt()));
    toolOptions.set(PackageGeneratorApp.INPUT_DIR, cl.getOptionValue(inputOption.getLongOpt()));
    toolOptions.set(PackageGeneratorApp.OUTPUT_DIR, cl.getOptionValue(OUTPUT_OPTION.getLongOpt()));
    toolOptions.set(ToolOptions.DESCRIPTOR_SET, cl.getOptionValue(DESCRIPTOR_SET_OPTION.getLongOpt()));
    if (cl.getOptionValues(SERVICE_YAML_NONREQUIRED_OPTION.getLongOpt()) != null) {
        toolOptions.set(ToolOptions.CONFIG_FILES,
                Lists.newArrayList(cl.getOptionValues(SERVICE_YAML_NONREQUIRED_OPTION.getLongOpt())));
    }
    toolOptions.set(PackageGeneratorApp.PACKAGE_CONFIG2_FILE,
            cl.getOptionValue(PACKAGE_YAML2_OPTION.getLongOpt()));
    toolOptions.set(PackageGeneratorApp.LANGUAGE, cl.getOptionValue(LANGUAGE_OPTION.getLongOpt()));

    if (cl.getOptionValue(artifactTypeOption.getLongOpt()) != null) {
        toolOptions.set(PackageGeneratorApp.ARTIFACT_TYPE,
                PackagingArtifactType.of(cl.getOptionValue(artifactTypeOption.getLongOpt())));
    }

    PackageGeneratorApp generator = new PackageGeneratorApp(toolOptions);
    int exitCode = generator.run();
    System.exit(exitCode);
}

From source file:com.netflix.exhibitor.standalone.ExhibitorCLI.java

private void logOptions(String sectionName, String prefix, Options options) {
    if (sectionName != null) {
        log.info("== " + sectionName + " ==");
    }/*www . j  a  v a2 s.co m*/

    //noinspection unchecked
    for (Option option : (Iterable<? extends Option>) options.getOptions()) {
        if (option.hasLongOpt()) {
            if (option.hasArg()) {
                log.info(prefix + option.getLongOpt() + " <arg> - " + option.getDescription());
            } else {
                log.info(prefix + option.getLongOpt() + " - " + option.getDescription());
            }
        }
    }
}