Example usage for org.apache.commons.cli OptionBuilder isRequired

List of usage examples for org.apache.commons.cli OptionBuilder isRequired

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder isRequired.

Prototype

public static OptionBuilder isRequired() 

Source Link

Document

The next Option created will be required.

Usage

From source file:org.apache.sqoop.tools.tool.RepositoryDumpTool.java

@Override
public boolean runToolWithConfiguration(String[] arguments) {

    boolean skipSensitive = true;

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("include-sensitive").withDescription(
            "Dump all data including sensitive information such as passwords. Passwords will be dumped in clear text")
            .create());/*from w ww . ja v a  2s  . c  om*/
    options.addOption(
            OptionBuilder.isRequired().hasArg().withArgName("filename").withLongOpt("output").create('o'));

    CommandLineParser parser = new GnuParser();

    try {
        CommandLine line = parser.parse(options, arguments);
        String outputFileName = line.getOptionValue('o');

        if (line.hasOption("include-sensitive")) {
            skipSensitive = false;
        }

        BufferedWriter output = new BufferedWriter(new FileWriter(outputFileName));
        LOG.info("Writing JSON repository dump to file " + outputFileName);
        dump(skipSensitive).writeJSONString(output);
        output.flush();
        output.close();

    } catch (ParseException e) {
        LOG.error("Error parsing command line arguments:", e);
        System.out.println("Error parsing command line arguments. Please check Server logs for details.");
        return false;
    } catch (IOException e) {
        LOG.error("Can't dump Sqoop repository to file:", e);
        System.out.println("Writing repository dump to file failed. Please check Server logs for details.");
        return false;
    }
    return true;

}

From source file:org.apache.sqoop.tools.tool.RepositoryLoadTool.java

@SuppressWarnings("static-access")
@Override/*from ww w. j  av a  2s.  c  om*/
public boolean runToolWithConfiguration(String[] arguments) {

    Options options = new Options();
    options.addOption(
            OptionBuilder.isRequired().hasArg().withArgName("filename").withLongOpt("input").create('i'));

    CommandLineParser parser = new GnuParser();

    try {
        CommandLine line = parser.parse(options, arguments);
        String inputFileName = line.getOptionValue('i');

        LOG.info("Reading JSON from file" + inputFileName);
        InputStream input = new FileInputStream(inputFileName);
        String jsonTxt = IOUtils.toString(input, Charsets.UTF_8);
        JSONObject json = (JSONObject) JSONValue.parse(jsonTxt);
        boolean res = load(json);
        input.close();
        return res;

    } catch (FileNotFoundException e) {
        LOG.error("Repository dump file not found:", e);
        System.out.println("Input file not found. Please check Server logs for details.");
        return false;
    } catch (IOException e) {
        LOG.error("Unable to read repository dump file:", e);
        System.out.println("Unable to read input file. Please check Server logs for details.");
        return false;
    } catch (ParseException e) {
        LOG.error("Error parsing command line arguments:", e);
        System.out.println("Error parsing command line arguments. Please check Server logs for details.");
        return false;
    }
}

From source file:org.eclim.command.Options.java

/**
 * Parses the String representation of an Option to an Option instance.
 *
 * @param option The option String./*from   w ww . jav  a 2s  . c o m*/
 * @return The Option.
 */
public Option parseOption(String option) {
    String[] parts = StringUtils.split(option);

    // command can have any additional arguments.
    //if(parts.length == 1 && ANY.equals(parts[0])){
    //}

    if (REQUIRED.equals(parts[0])) {
        OptionBuilder.isRequired();
    }
    if (ARG.equals(parts[3])) {
        OptionBuilder.hasArg();
        //OptionBuilder.withArgName(parts[2]);
    } else if (ANY.equals(parts[3])) {
        OptionBuilder.hasOptionalArgs();
    }
    OptionBuilder.withLongOpt(parts[2]);
    return OptionBuilder.create(parts[1]);
}

From source file:org.eclipse.jubula.documentation.gen.TexGen.java

/**
 * @return The command line options/*from www  .j  a va  2 s. c o  m*/
 */
private static Options createOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("generate type"); //$NON-NLS-1$
    OptionBuilder
            .withDescription("The type of output to generate (i.e. 'actions', 'errors'). Default: 'actions'"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    // Not required. Default to type 'actions'.
    options.addOption(OptionBuilder.create("gt")); //$NON-NLS-1$

    OptionBuilder.withArgName("template directory"); //$NON-NLS-1$
    OptionBuilder.withDescription("The directory which contains the template files"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create("td")); //$NON-NLS-1$

    OptionBuilder.withArgName("output directory"); //$NON-NLS-1$
    OptionBuilder.withDescription("The output directory"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create("od")); //$NON-NLS-1$

    OptionBuilder.withArgName("language"); //$NON-NLS-1$
    OptionBuilder.withDescription("The language, e.g. 'en' or 'de'"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("nl")); //$NON-NLS-1$
    return options;
}

From source file:org.graphwalker.CLI.java

@SuppressWarnings("static-access")
private void buildRequirementsCLI() {
    opt.addOption(OptionBuilder.isRequired().withArgName("file|folder")
            .withDescription("The file (or folder) containing graphml formatted files.").hasArg()
            .withLongOpt("input_graphml").create("f"));
}

From source file:org.graphwalker.CLI.java

@SuppressWarnings("static-access")
private void buildOnlineCLI() {
    opt.addOption("a", "statistics", false, "Prints the statistics of the test, at the end of the run.");
    opt.addOption("x", "extended", false, "Use an extended finite state machine to handle the model.");
    opt.addOption("j", false, "Enable JavaScript engine");
    opt.addOption(OptionBuilder.isRequired().withArgName("stop-condition").withDescription(
            "Defines the stop condition(s).\nHalts the generation after the specified stop-conditon(s) has been met. "
                    + "At least 1 condition must be given. If more than 1 is given, the condition that meets "
                    + "it's stop-condition first, will cause the generation to halt. "
                    + "To separate multiple conditions, the separator pipe-character | is used. "
                    + "A list of valid stop-conditions are:\n -------------------\n"
                    + generateListOfValidStopConditions()
                    + " -------------------\nFor more extensive examples, "
                    + "see http://mbt.tigris.org/wiki/All_about_stop_conditions")
            .hasArg().create("s"));
    opt.addOption(OptionBuilder.isRequired().withArgName("generator").withDescription(
            "The generator to be used when traversing the model. At least 1 generator must be given. "
                    + "To separate multiple generators, the separator pipe-character | is used. "
                    + "A list of valid generators are:\n -------------------\n"
                    + generateListOfValidGenerators() + " -------------------\nFor more extensive examples, "
                    + "see http://mbt.tigris.org/wiki/All_about_generators")
            .hasArg().create("g"));
    opt.addOption(OptionBuilder.isRequired().withArgName("file|folder")
            .withDescription("The file (or folder) containing graphml formatted files.").hasArg()
            .withLongOpt("input_graphml").create("f"));
    opt.addOption(OptionBuilder.withArgName("seconds").withDescription(
            "Prints the test coverage of the graph during execution every <n second>. The printout goes to the log file defined in "
                    + "mbt.properties, and only, if at least INFO level is set in " + "that same file.")
            .hasArg().withLongOpt("log-coverage").create("o"));
    opt.addOption("c", "class_name", true, "Optional class name to use for test execution.");
    opt.addOption("t", "report-template", true,
            "Optional report template to use. (Also requires option -r) (To be better documented)");
    opt.addOption("r", "report-output", true,
            "Optional report filename to save report to. (Also requires option -t)  (To be better documented)");
    opt.addOption("w", "weighted", false,
            "Use weighted values if they exist in the model, and the generator is RANDOM.");
    opt.addOption("d", "dry-run", false,
            "Will execute a dry-run of the model. Dialog will pop up for every edge and vertex.");
}

From source file:org.graphwalker.CLI.java

/**
 * Build the command offline command line parser
 *///  w  ww.  j  a v  a 2s.c  o m
@SuppressWarnings("static-access")
private void buildOfflineCLI() {
    opt.addOption("a", false, "Prints the statistics of the test, at the end of the run.");
    opt.addOption("x", false, "Use an extended finite state machine to handle the model.");
    opt.addOption("j", false, "Enable JavaScript engine");
    opt.addOption(OptionBuilder.isRequired().withArgName("stop-condition").withDescription(
            "Defines the stop condition(s).\nHalts the generation after the specified stop-conditon(s) has been met. "
                    + "At least 1 condition must be given. If more than 1 is given, the condition that meets "
                    + "it's stop-condition first, will cause the generation to halt. "
                    + "To separate multiple conditions, the separator pipe-character | is used. "
                    + "A list of valid stop-conditions are:\n -------------------\n"
                    + generateListOfValidStopConditions()
                    + " -------------------\nFor more extensive examples, "
                    + "see http://mbt.tigris.org/wiki/All_about_stop_conditions")
            .hasArg().create("s"));
    opt.addOption(OptionBuilder.isRequired().withArgName("generator").withDescription(
            "The generator to be used when traversing the model. At least 1 generator must be given. "
                    + "To separate multiple generators, the separator pipe-character | is used. "
                    + "A list of valid generators are:\n -------------------\n"
                    + generateListOfValidGenerators() + " -------------------\nFor more extensive examples, "
                    + "see http://mbt.tigris.org/wiki/All_about_generators")
            .hasArg().create("g"));
    opt.addOption(OptionBuilder.isRequired().withArgName("file|folder")
            .withDescription("The file (or folder) containing graphml formatted files.").hasArg().create("f"));
    opt.addOption(OptionBuilder.withArgName("seconds").withDescription(
            "Prints the test coverage of the graph during execution every <n second>. The printout goes to the log file defined in "
                    + "mbt.properties, and only, if at least INFO level is set in " + "that same file.")
            .hasArg().create("o"));
    opt.addOption("t", "report-template", true,
            "Optional report template to use. (Also requires option -r) (To be better documented)");
    opt.addOption("r", "report-output", true,
            "Optional report filename to save report to. (Also requires option -t)  (To be better documented)");
    opt.addOption("w", "weighted", false,
            "Use weighted values if they exist in the model, and the generator is RANDOM.");
}

From source file:org.graphwalker.CLI.java

/**
 * Build the command manual command line parser
 *///from  w w w  . jav  a2 s.c o m
@SuppressWarnings("static-access")
private void buildManualCLI() {
    opt.addOption("x", false, "Use an extended finite state machine to handle the model.");
    opt.addOption("j", false, "Enable JavaScript engine");
    opt.addOption(OptionBuilder.isRequired().withArgName("stop-condition").withDescription(
            "Defines the stop condition(s).\nHalts the generation after the specified stop-conditon(s) has been met. "
                    + "At least 1 condition must be given. If more than 1 is given, the condition that meets "
                    + "it's stop-condition first, will cause the generation to halt. "
                    + "To separate multiple conditions, the separator pipe-character | is used. "
                    + "A list of valid stop-conditions are:\n -------------------\n"
                    + generateListOfValidStopConditions()
                    + " -------------------\nFor more extensive examples, "
                    + "see http://mbt.tigris.org/wiki/All_about_stop_conditions")
            .hasArg().create("s"));
    opt.addOption(OptionBuilder.isRequired().withArgName("generator").withDescription(
            "The generator to be used when traversing the model. At least 1 generator must be given. "
                    + "To separate multiple generators, the separator pipe-character | is used. "
                    + "A list of valid generators are:\n -------------------\n"
                    + generateListOfValidGenerators() + " -------------------\nFor more extensive examples, "
                    + "see http://mbt.tigris.org/wiki/All_about_generators")
            .hasArg().create("g"));
    opt.addOption(OptionBuilder.isRequired().withArgName("file|folder")
            .withDescription("The file (or folder) containing graphml formatted files.").hasArg().create("f"));
    opt.addOption("w", "weighted", false,
            "Use weighted values if they exist in the model, and the generator is RANDOM.");
}

From source file:org.graphwalker.CLI.java

@SuppressWarnings("static-access")
private void buildMethodsCLI() {
    opt.addOption(OptionBuilder.isRequired().withArgName("file|folder")
            .withDescription("The file (or folder) containing graphml formatted files.").hasArg()
            .withLongOpt("input_graphml").create("f"));
}

From source file:org.graphwalker.CLI.java

/**
 * Build the command merge command line parser
 *///from w  ww.  j a  va2  s  .  c o  m
@SuppressWarnings("static-access")
private void buildMergeCLI() {
    opt.addOption(OptionBuilder.isRequired().withArgName("file|folder")
            .withDescription("The file (or folder) containing graphml formatted files.").hasArg()
            .withLongOpt("input_graphml").create("f"));
    opt.addOption("i", "index", true, "Print out the INDEX value when merging models. Default is true");
}