Example usage for org.apache.commons.cli ParseException printStackTrace

List of usage examples for org.apache.commons.cli ParseException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:io.github.sn0cr.rapidRunner.CommandlineInterface.java

public static void main(String[] args) {
    // create Options object
    final Options options = new Options();
    // add t option
    // options.addOption("t", false, "display current time");
    final CommandLineParser parser = new PosixParser();
    try {/* w w  w . ja v a 2 s.c o  m*/
        final CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("t")) {
            System.out.println("has option " + cmd.getOptionValue("t"));
        } else {
            System.out.println("hasn't option");
        }
    } catch (final ParseException e) {
        e.printStackTrace();
    }
}

From source file:mosaicsimulation.MosaicLockstepServer.java

public static void main(String[] args) {
    Options opts = new Options();
    opts.addOption("s", "serverPort", true, "Listening TCP port used to initiate handshakes");
    opts.addOption("n", "nClients", true, "Number of clients that will participate in the session");
    opts.addOption("t", "tickrate", true, "Number of transmission session to execute per second");
    opts.addOption("m", "maxUDPPayloadLength", true, "Max number of bytes per UDP packet");
    opts.addOption("c", "connectionTimeout", true, "Timeout for UDP connections");

    DefaultParser parser = new DefaultParser();
    CommandLine commandLine = null;/*from ww w  .  j  a  v  a  2s .  c o m*/
    try {
        commandLine = parser.parse(opts, args);
    } catch (ParseException ex) {
        ex.printStackTrace();
        System.exit(1);
    }

    int serverPort = Integer.parseInt(commandLine.getOptionValue("serverPort"));
    int nClients = Integer.parseInt(commandLine.getOptionValue("nClients"));
    int tickrate = Integer.parseInt(commandLine.getOptionValue("tickrate"));
    int maxUDPPayloadLength = Integer.parseInt(commandLine.getOptionValue("maxUDPPayloadLength"));
    int connectionTimeout = Integer.parseInt(commandLine.getOptionValue("connectionTimeout"));

    Thread serverThread = LockstepServer.builder().clientsNumber(nClients).tcpPort(serverPort)
            .tickrate(tickrate).maxUDPPayloadLength(maxUDPPayloadLength).connectionTimeout(connectionTimeout)
            .build();

    serverThread.setName("Main-server-thread");
    serverThread.start();

    try {
        serverThread.join();
    } catch (InterruptedException ex) {
        LOG.error("Server interrupted while joining");
    }
}

From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java

public static void main(String[] args) {
    try {/*from w w  w . j av a 2 s  .  c  o  m*/
        final Options helpOptions = new Options();
        helpOptions.addOption("h", false, "Print help for this application");

        final DefaultParser parser = new DefaultParser();
        final CommandLine commandLine = parser.parse(helpOptions, args);

        if (commandLine.hasOption('h')) {
            final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n";
            String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm";

            final HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true);

        } else {
            final List<String> remainingArgs = commandLine.getArgList();
            if (remainingArgs.size() < 2) {
                throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified.");
            }

            final String mpegFileName = remainingArgs.get(0);
            final String dicomFileName = remainingArgs.get(1);
            final File mpegFile = new File(mpegFileName);
            final File dicomOutputFile = new File(dicomFileName);
            MpegFileConverter.convert(mpegFile, dicomOutputFile);
        }
    } catch (org.apache.commons.cli.ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.sr.eb.compiler.Main.java

public static void main(String[] args) throws Throwable {
    try {/*from   w  ww.ja  v a 2s  .co m*/
        Options options = new Options();

        options.addOption("v", "verbose", false, "Enables verbose compiler output.");
        options.addOption("ee", "easterEgg", false, "Enables compiler easter eggs, DO NOT USE!");

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

        if (cmd.getArgs().length > 0) {
            int start = -1;
            while (true) {
                start++;
                if (options.getOption(cmd.getArgs()[start]) == null)
                    break;
            }

            String[] sourceFiles = Arrays.copyOfRange(cmd.getArgs(), start, cmd.getArgs().length);

            // TODO
        } else {
            System.out.println("Expected source files, got none!");
            System.out.println("Usage: ebc [options] <source files>");
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    /* ----- Testing ----- */
    Lexer lexer = Lexer.newInstance();
    Parser parser = Parser.newInstance();

    try (InputStream in = new FileInputStream("test.eb")) {
        lexer.reset(Utils.readAll(in));
    }

    List<Token> tokens = lexer.tokenize();
    parser.reset(tokens);
    SyntaxTree t = parser.parse();

    ASTPrettyPrinter.print(t);
}

From source file:dk.statsbiblioteket.jpar2.filecompare.FileCompare.java

/**
 * Main method. //from   w ww  .  ja v a 2  s .  c  o  m
 * @param args
 */
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("s", "slices", true, "The number of slices to use in the comparison");

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        args = cmd.getArgs();
        if (!cmd.hasOption("s") || args.length != 2) {
            System.exit(2);
        }
        int slices = Integer.parseInt(cmd.getOptionValue("s").trim());

        File f1 = new File(args[0]);
        File f2 = new File(args[1]);
        if (f1.length() == f2.length()) {
            int sliceSize = (int) (f1.length() / slices);//rounding here...

            DataFile df1 = new DataFile(f1, sliceSize);
            DataFile df2 = new DataFile(f2, sliceSize);

            List<Integer> defectIndexes = df1.compareWithIndex(df2);

            for (int index : defectIndexes) {
                System.out.println("index " + index + ", from " + index * sliceSize + " to "
                        + (index + 1) * sliceSize + " is defect");
            }
            if (defectIndexes.size() == 0) {
                System.out.println("Files are identical");
            }

        } else {
            System.out.println("Files differ in length, cannot help you");
        }
    } catch (ParseException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

}

From source file:de.akadvh.view.Main.java

/**
 * @param args/*from  w  w  w  .j a v a 2  s . co  m*/
 */
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("u", "user", true, "Benutzername");
    options.addOption("p", "pass", true, "Passwort");
    options.addOption("c", "console", false, "Consolenmodus");
    options.addOption("v", "verbose", false, "Mehr Ausgabe");
    options.addOption("m", "modul", true, "Modul");
    options.addOption("n", "noten", false, "Notenuebersicht erstellen");
    options.addOption("t", "termin", false, "Terminuebersicht (angemeldete Module) downloaden");
    options.addOption("version", false, "Version");
    options.addOption("h", "help", false, "Hilfe");

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

        if (cmd.hasOption("help")) {

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar akadvh.jar", options);
            System.exit(0);
        }

        if (cmd.hasOption("version")) {

            System.out.println("Akadvh Version: " + Akadvh.getVersion());
            System.exit(0);

        }

        if (cmd.hasOption("console")) {

            ConsoleView cv = new ConsoleView(cmd.getOptionValue("user"), cmd.getOptionValue("pass"),
                    cmd.getOptionValue("modul"), cmd.hasOption("noten"), cmd.hasOption("termin"),
                    cmd.hasOption("verbose"));

        } else {

            SwingView sv = new SwingView(cmd.getOptionValue("user"), cmd.getOptionValue("pass"));

        }

    } catch (UnrecognizedOptionException e1) {
        System.out.println(e1.getMessage());
        System.out.println("--help fuer Hilfe");
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:com.basingwerk.utilisation.Utilisation.java

public static void main(final String[] args) {
    String dataFile = null;/*w w  w  . j  a v a  2 s . com*/

    Options options = new Options();

    Option helpOption = new Option("h", "help", false, "print this help");
    Option serverURLOption = new Option("l", "logfile", true, "log file");

    options.addOption(helpOption);
    options.addOption(serverURLOption);

    CommandLineParser argsParser = new PosixParser();

    try {
        CommandLine commandLine = argsParser.parse(options, args);

        if (commandLine.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

        dataFile = commandLine.getOptionValue(serverURLOption.getOpt());
        String[] otherArgs = commandLine.getArgs();

        if (dataFile == null || otherArgs.length > 1) {
            System.out.println("Please specify a logfile");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
    }

    final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile));
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}

From source file:com.matthatem.ai.search.applications.MSASolver.java

public static void main(String[] args) {
    Options options = createOptions();//from  w ww .j  av a2 s . c  o m
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
        System.exit(1);
    }

    MSA msa = createMSAInstance(cmd);
    SearchAlgorithm algo = createSearchAlgorithm(cmd, msa);

    System.gc();

    long t = System.currentTimeMillis();
    SearchResult<MSAState> result = algo.search();
    long td = System.currentTimeMillis();

    result.setAlgorithm(algoString);
    result.setInitialH((int) msa.getHeuristic().getInitH());
    result.setStartTime(t);
    result.setEndTime(td);

    System.out.println(result);
    //System.out.println(msa.alignmentToString());
    System.out.println(msa.alignmentToMSFString());
}

From source file:com.thoughtworks.xstream.benchmark.cache.CacheBenchmark.java

public static void main(String[] args) {
    int counter = 10000;
    Product product = null;/*from   w w w.j av  a  2 s.  c  o  m*/

    Options options = new Options();
    options.addOption("p", "product", true, "Class name of the product to use for benchmark");
    options.addOption("n", true, "Number of repetitions");

    Parser parser = new PosixParser();
    try {
        CommandLine commandLine = parser.parse(options, args);
        if (commandLine.hasOption('p')) {
            product = (Product) Class.forName(commandLine.getOptionValue('p')).newInstance();
        }
        if (commandLine.hasOption('n')) {
            counter = Integer.parseInt(commandLine.getOptionValue('n'));
        }
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    Harness harness = new Harness();
    // harness.addMetric(new SerializationSpeedMetric(1) {
    // public String toString() {
    // return "Initial run serialization";
    // }
    // });
    // harness.addMetric(new DeserializationSpeedMetric(1, false) {
    // public String toString() {
    // return "Initial run deserialization";
    // }
    // });
    harness.addMetric(new SerializationSpeedMetric(counter));
    harness.addMetric(new DeserializationSpeedMetric(counter, false));
    if (product == null) {
        harness.addProduct(new NoCache());
        harness.addProduct(new Cache122());
        harness.addProduct(new RealClassCache());
        harness.addProduct(new SerializedClassCache());
        harness.addProduct(new AliasedAttributeCache());
        harness.addProduct(new DefaultImplementationCache());
        harness.addProduct(new NoCache());
    } else {
        harness.addProduct(product);
    }
    harness.addTarget(new BasicTarget());
    harness.addTarget(new ExtendedTarget());
    harness.addTarget(new ReflectionTarget());
    harness.addTarget(new SerializableTarget());
    harness.run(new TextReporter(new PrintWriter(System.out, true)));
    System.out.println("Done.");
}

From source file:com.cloudera.flume.handlers.debug.TextToCollector.java

static public void main(String[] argv) throws IOException {

    Options opts = new Options();
    opts.addOption("m", false, "Load events into memory");
    opts.addOption("t", false, "Simple text file format loader");
    opts.addOption("l", false, "Log4j text file format loader");

    try {//from   ww  w . j  a  va2 s  .c  o m
        if (argv.length < 1) {
            HelpFormatter fmt = new HelpFormatter();
            fmt.printHelp("TextToCollector", opts, true);
            System.exit(-1);
        }

        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(opts, argv);

        core(cmd);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}