Example usage for org.apache.commons.cli Options Options

List of usage examples for org.apache.commons.cli Options Options

Introduction

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

Prototype

Options

Source Link

Usage

From source file:com.github.besherman.fingerprint.Main.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withDescription("creates a fingerprint file for the directory").hasArg()
            .withArgName("dir").create('c'));

    options.addOption(OptionBuilder.withDescription("shows a diff between two fingerprint files")
            .withArgName("left-file> <right-file").hasArgs(2).create('d'));

    options.addOption(OptionBuilder.withDescription("shows a diff between a fingerprint and a directory")
            .withArgName("fingerprint> <dir").hasArgs(2).create('t'));

    options.addOption(OptionBuilder.withDescription("shows duplicates in a directory").withArgName("dir")
            .hasArgs(1).create('u'));

    options.addOption(//w w w  .j  a  va2s.  c  om
            OptionBuilder.withDescription("output to file").withArgName("output-file").hasArg().create('o'));

    PosixParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException ex) {
        System.out.println(ex.getMessage());
        System.out.println("");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("fingerprint-dir", options, true);
        System.exit(7);
    }

    if (cmd.hasOption('c')) {
        Path root = Paths.get(cmd.getOptionValue('c'));

        if (!Files.isDirectory(root)) {
            System.err.println("root is not a directory");
            System.exit(7);
        }

        OutputStream out = System.out;

        if (cmd.hasOption('o')) {
            Path p = Paths.get(cmd.getOptionValue('o'));
            out = Files.newOutputStream(p);
        }

        Fingerprint fp = new Fingerprint(root, "");
        fp.write(out);

    } else if (cmd.hasOption('d')) {
        String[] ar = cmd.getOptionValues('d');
        Path leftFingerprintFile = Paths.get(ar[0]), rightFingerprintFile = Paths.get(ar[1]);
        if (!Files.isRegularFile(leftFingerprintFile)) {
            System.out.printf("%s is not a file%n", leftFingerprintFile);
            System.exit(7);
        }
        if (!Files.isRegularFile(rightFingerprintFile)) {
            System.out.printf("%s is not a file%n", rightFingerprintFile);
            System.exit(7);
        }

        Fingerprint left, right;
        try (InputStream input = Files.newInputStream(leftFingerprintFile)) {
            left = new Fingerprint(input);
        }

        try (InputStream input = Files.newInputStream(rightFingerprintFile)) {
            right = new Fingerprint(input);
        }

        Diff diff = new Diff(left, right);

        // TODO: if we have redirected output
        diff.print(System.out);
    } else if (cmd.hasOption('t')) {
        throw new RuntimeException("Not yet implemented");
    } else if (cmd.hasOption('u')) {
        Path root = Paths.get(cmd.getOptionValue('u'));
        Fingerprint fp = new Fingerprint(root, "");
        Map<String, FilePrint> map = new HashMap<>();
        fp.stream().forEach(f -> {
            if (map.containsKey(f.getHash())) {
                System.out.println("  " + map.get(f.getHash()).getPath());
                System.out.println("= " + f.getPath());
                System.out.println("");
            } else {
                map.put(f.getHash(), f);
            }
        });
    } else {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("fingd", options, true);
    }
}

From source file:com.github.braully.graph.UtilResultCompare.java

public static void main(String... args) throws Exception {
    Options options = new Options();

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(false);/*from  w  w w .  ja v  a  2s  .  com*/
    options.addOption(input);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(false);
    options.addOption(output);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("UtilResult", options);

        System.exit(1);
        return;
    }

    String inputFilePath = cmd.getOptionValue("input");
    if (inputFilePath == null) {
        inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-quartic-ht.txt";

        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-mft-parcial-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-highlyirregular-ht.txt";
        //            inputFilePath = "/home/strike/Documentos/grafos-processados/mtf/resultado-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-hypo-parcial-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-eul-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-almhypo-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-Almost_hypohamiltonian_graphs_cubic-parcial-ht.txt";
    }
    if (inputFilePath != null) {
        if (inputFilePath.toLowerCase().endsWith(".txt")) {
            processFileTxt(inputFilePath);
        } else if (inputFilePath.toLowerCase().endsWith(".json")) {
            processFileJson(inputFilePath);
        }
    }
}

From source file:eu.edisonproject.utility.execute.Main.java

public static void main(String args[]) {
    Options options = new Options();
    Option operation = new Option("op", "operation", true,
            "type of operation to perform. " + "To move cached terms from org.mapdb.DB 'm'");
    operation.setRequired(true);/*from w  w w  .ja  v a 2  s .  co m*/
    options.addOption(operation);

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(true);
    options.addOption(input);

    String helpmasg = "Usage: \n";
    for (Object obj : options.getOptions()) {
        Option op = (Option) obj;
        helpmasg += op.getOpt() + ", " + op.getLongOpt() + "\t Required: " + op.isRequired() + "\t\t"
                + op.getDescription() + "\n";
    }

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        switch (cmd.getOptionValue("operation")) {
        case "m":
            DBTools.portTermCache2Hbase(cmd.getOptionValue("input"));
            DBTools.portBabelNetCache2Hbase(cmd.getOptionValue("input"));
            break;
        default:
            System.out.println(helpmasg);
        }

    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, helpmasg, ex);
    }
}

From source file:com.redhat.poc.jdg.bankofchina.util.GenerateUserIdCsv.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//ww w.  ja va2 s  .  c  o m
    Options options = new Options();
    options.addOption("s", true, "The start csv file number option");
    options.addOption("e", true, "The end csv file number option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("s")) {
            String start = commandLine.getOptionValue("s");
            if (start != null && start.length() > 0) {
                csvFileStart = Integer.parseInt(start);
            }
        }
        if (commandLine.hasOption("e")) {
            String end = commandLine.getOptionValue("e");
            if (end != null && end.length() > 0) {
                csvFileEnd = Integer.parseInt(end);
            }
        }
    }

    for (int i = csvFileStart; i <= csvFileEnd; i++) {
        ReadCsvFile(i);
    }

    System.out.println();
    System.out.println("%%%%%%%%%  " + csvFileStart + "-" + csvFileEnd
            + " ? userid.csv ,? %%%%%%%%%");
    System.out.println("%%%%%%%%% userid.csv  " + userIdList.size() + " ? %%%%%%%%%");
    CSVWriter writer = new CSVWriter(new FileWriter(CSV_FILE_PATH + "userid.csv"));
    writer.writeAll(userIdList);
    writer.flush();
    writer.close();
}

From source file:name.martingeisse.ecotools.simulator.ui.Main.java

/**
 * The main method./* w  w  w .  j a v a2 s  .  c o m*/
 * @param args command-line arguments
 * @throws Exception Any exceptions are passed to the environment.
 */
public static void main(String[] args) throws Exception {

    /** define command-line options **/
    Options options = new Options();
    options.addOption("i", false, "interactive mode (do not start simulation automatically)");
    options.addOption("l", true, "load program");
    options.addOption("r", true, "load ROM contents");
    options.addOption("d", true, "enable disk simulation with the specified disk image file");
    options.addOption("t", true, "enable terminal simulation with the specified number of terminals (0..2)");
    options.addOption("g", false, "enable graphics controller simulation");
    options.addOption("c", false, "enable console simulation");
    options.addOption("C", false, "enable block console simulation");
    options.addOption("o", true, "enable output device simulation and write output to the specified file");
    options.addOption("s", false, "enable null sound device");

    /** print help for the empty command line **/
    if (args.length == 0) {
        showUsgeAndExit(options);
    }

    /** parse the command line **/
    CommandLineParser commandLineParser = new PosixParser();
    CommandLine commandLine;
    try {
        commandLine = commandLineParser.parse(options, args);
    } catch (UnrecognizedOptionException e) {
        System.out.println("unrecognized option: " + e.getOption());
        showUsgeAndExit(options);
        return;
    }

    /** build the simulator configuration **/
    SimulatorConfiguration configuration = new SimulatorConfiguration();

    /** load configuration files **/
    for (String arg : commandLine.getArgs()) {
        configuration.loadConfigurationFile(arg);
    }

    /** interpret the options **/

    if (commandLine.hasOption("l")) {
        configuration.setProgramFilename(commandLine.getOptionValue("l"));
    }

    if (commandLine.hasOption("r")) {
        configuration.setRomFilename(commandLine.getOptionValue("r"));
    }

    if (commandLine.hasOption("d")) {
        configuration.setDiskFilename(commandLine.getOptionValue("d"));
    }

    if (commandLine.hasOption("t")) {
        String terminalCountSpecification = commandLine.getOptionValue("t");
        try {
            configuration.setTerminalCount(
                    (terminalCountSpecification == null) ? 0 : Integer.parseInt(terminalCountSpecification));
        } catch (NumberFormatException e) {
            System.out.println("number format error in number of terminals: " + terminalCountSpecification);
        }
    }

    if (commandLine.hasOption("i")) {
        configuration.setInteractive(true);
    }

    if (commandLine.hasOption("g")) {
        configuration.setGraphics(true);
    }

    if (commandLine.hasOption("c")) {
        configuration.setConsole(true);
    }

    if (commandLine.hasOption("C")) {
        configuration.setBlockConsole(true);
    }

    if (commandLine.hasOption("o")) {
        configuration.setOutputFilename(commandLine.getOptionValue("o"));
    }

    if (commandLine.hasOption("s")) {
        configuration.setSound(true);
    }

    configuration.checkConsistency();
    configuration.deriveSettings();

    /** setup simulation framework and run **/
    EcoSimulatorFramework framework = new EcoSimulatorFramework();
    configuration.applyPreCreate(framework);
    framework.create();
    configuration.applyPostCreate(framework);
    framework.open();
    framework.mainLoop();
    framework.dispose();
    framework.exit();

}

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

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(/*from ww w.  ja v a  2s .  com*/
            Option.builder().longOpt("source_path").desc("The directory which contains the final code.")
                    .hasArg().argName("SOURCE-PATH").required(true).build());
    options.addOption(
            Option.builder().longOpt("generated_path").desc("The directory which contains the generated code.")
                    .hasArg().argName("GENERATED-PATH").build());
    options.addOption(Option.builder().longOpt("baseline_path")
            .desc("The directory which contains the baseline code.").hasArg().argName("BASELINE-PATH").build());
    options.addOption(Option.builder().longOpt("auto_merge")
            .desc("If set, no GUI will be launched if merge can be completed automatically.")
            .argName("AUTO-MERGE").build());
    options.addOption(Option.builder().longOpt("auto_resolve")
            .desc("Whether to enable smart conflict resolution").argName("AUTO_RESOLVE").build());
    options.addOption(Option.builder().longOpt("ignore_base")
            .desc("If true, the baseline will be ignored and two-way merge will be used.")
            .argName("IGNORE_BASE").build());

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

    synchronize(cl.getOptionValue("source_path"), cl.getOptionValue("generated_path"),
            cl.getOptionValue("baseline_path"), cl.hasOption("auto_merge"), cl.hasOption("auto_resolve"),
            cl.hasOption("ignore_base"));
}

From source file:de.iritgo.aktario.framework.IritgoClient.java

/**
 * The client main method.//  w w  w. j  av  a 2s.  c o m
 *
 * @param args The program args.
 */
public static void main(String[] args) {
    if (null == System.getProperty("swing.aatext")) {
        System.setProperty("swing.aatext", "true");
    }

    Options options = new Options();

    IritgoEngine.create(IritgoEngine.START_CLIENT, options, args);
}

From source file:ezbake.thrift.VisibilityBase64Converter.java

public static void main(String[] args) {
    try {/* w  w w.j a v  a  2 s .  c om*/
        Options options = new Options();
        options.addOption("d", "deserialize", false,
                "deserialize base64 visibility, if not present tool will serialize");
        options.addOption("v", "visibility", true,
                "formalVisibility to serialize, or base64 encoded string to deserialize");
        options.addOption("h", "help", false, "display usage info");

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("thrift-visibility-converter", options);
            return;
        }

        String input = cmd.getOptionValue("v");
        boolean deserialize = cmd.hasOption("d");

        String output;
        if (deserialize) {
            if (input == null) {
                System.err.println("Cannot deserialize empty string");
                System.exit(1);
            }
            output = ThriftUtils.deserializeFromBase64(Visibility.class, input).toString();
        } else {
            Visibility visibility = new Visibility();
            if (input == null) {
                input = "(empty visibility)";
            } else {
                visibility.setFormalVisibility(input);
            }
            output = ThriftUtils.serializeToBase64(visibility);
        }
        String operation = deserialize ? "deserialize" : "serialize";
        System.out.println("operation: " + operation);
        System.out.println("input: " + input);
        System.out.println("output: " + output);
    } catch (TException | ParseException e) {
        System.out.println("An error occurred: " + e.getMessage());
        System.exit(1);
    }
}

From source file:com.canyapan.randompasswordgenerator.cli.Main.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("h", false, "prints help");
    options.addOption("def", false, "generates 8 character password with default options");
    options.addOption("p", true, "password length (default 8)");
    options.addOption("l", false, "include lower case characters");
    options.addOption("u", false, "include upper case characters");
    options.addOption("d", false, "include digits");
    options.addOption("s", false, "include symbols");
    options.addOption("lc", true, "minimum lower case character count (default 0)");
    options.addOption("uc", true, "minimum upper case character count (default 0)");
    options.addOption("dc", true, "minimum digit count (default 0)");
    options.addOption("sc", true, "minimum symbol count (default 0)");
    options.addOption("a", false, "avoid ambiguous characters");
    options.addOption("f", false, "force every character type");
    options.addOption("c", false, "continuous password generation");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;/*from   ww w . j a v a  2  s  . com*/
    boolean printHelp = false;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        printHelp = true;
    }

    if (printHelp || args.length == 0 || cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                "java -jar RandomPasswordGenerator.jar [-p <arg>] [-l] [-u] [-s] [-d] [-dc <arg>] [-a] [-f]",
                options);
        return;
    }

    RandomPasswordGenerator rpg = new RandomPasswordGenerator();

    if (cmd.hasOption("def")) {
        rpg.withDefault().withPasswordLength(Integer.parseInt(cmd.getOptionValue("p", "8")));
    } else {
        rpg.withPasswordLength(Integer.parseInt(cmd.getOptionValue("p", "8")))
                .withLowerCaseCharacters(cmd.hasOption("l")).withUpperCaseCharacters(cmd.hasOption("u"))
                .withDigits(cmd.hasOption("d")).withSymbols(cmd.hasOption("s"))
                .withAvoidAmbiguousCharacters(cmd.hasOption("a"))
                .withForceEveryCharacterType(cmd.hasOption("f"));

        if (cmd.hasOption("lc")) {
            rpg.withMinLowerCaseCharacterCount(Integer.parseInt(cmd.getOptionValue("lc", "0")));
        }

        if (cmd.hasOption("uc")) {
            rpg.withMinUpperCaseCharacterCount(Integer.parseInt(cmd.getOptionValue("uc", "0")));
        }

        if (cmd.hasOption("dc")) {
            rpg.withMinDigitCount(Integer.parseInt(cmd.getOptionValue("dc", "0")));
        }

        if (cmd.hasOption("sc")) {
            rpg.withMinSymbolCount(Integer.parseInt(cmd.getOptionValue("sc", "0")));
        }
    }

    Scanner scanner = new Scanner(System.in);

    try {
        do {
            final String password = rpg.generate();
            final PasswordMeter.Result result = PasswordMeter.check(password);
            System.out.printf("%s%nScore: %s%%%nComplexity: %s%n%n", password, result.getScore(),
                    result.getComplexity());

            if (cmd.hasOption("c")) {
                System.out.print("Another? y/N: ");
            }
        } while (cmd.hasOption("c") && scanner.nextLine().matches("^(?i:y(?:es)?)$"));
    } catch (RandomPasswordGeneratorException e) {
        System.err.println(e.getMessage());
    } catch (PasswordMeterException e) {
        System.err.println(e.getMessage());
    }
}

From source file:com.google.api.codegen.grpcmetadatagen.GrpcMetadataGeneratorTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    options.addOption(Option.builder().longOpt("descriptor_set")
            .desc("The descriptor set representing the compiled input protos.").hasArg()
            .argName("DESCRIPTOR-SET").required(true).build());
    options.addOption(/*from w ww  .  jav a2  s.  com*/
            Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.")
                    .hasArg().argName("SERVICE-YAML").required(true).build());
    options.addOption(
            Option.builder("i").longOpt("input").desc("The input directory containing the gRPC package.")
                    .hasArg().argName("INPUT-DIR").required(true).build());
    options.addOption(
            Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.")
                    .hasArg().argName("OUTPUT-DIR").required(true).build());
    options.addOption(
            Option.builder("l").longOpt("language").desc("The language for which to generate package metadata.")
                    .hasArg().argName("LANGUAGE").required(true).build());
    options.addOption(Option.builder("c").longOpt("metadata_config")
            .desc("The YAML file configuring the package metadata.").hasArg().argName("METADATA-CONFIG")
            .required(true).build());

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

    generate(cl.getOptionValue("descriptor_set"), cl.getOptionValues("service_yaml"),
            cl.getOptionValue("input"), cl.getOptionValue("output"), cl.getOptionValue("language"),
            cl.getOptionValue("metadata_config"));
}