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

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

Introduction

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

Prototype

GnuParser

Source Link

Usage

From source file:mx.unam.fesa.mss.MSSMain.java

/**
 * @param args//from w  ww . ja v a2  s  .  c  o  m
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    //
    // managing command line options using commons-cli
    //

    Options options = new Options();

    // help option
    //
    options.addOption(
            OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP));

    // port option
    //
    options.addOption(OptionBuilder.withDescription("The port in which the MineSweeperServer will listen to.")
            .hasArg().withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT));

    // parsing options
    //
    int port = DEFAULT_PORT;
    try {
        // using GNU standard
        //
        CommandLine line = new GnuParser().parse(options, args);

        if (line.hasOption(OPT_HELP)) {
            new HelpFormatter().printHelp("mss [options]", options);
            return;
        }

        if (line.hasOption(OPT_PORT)) {
            try {
                port = (Integer) line.getOptionObject(OPT_PORT);
            } catch (Exception e) {
            }
        }
    } catch (ParseException e) {
        System.err.println("Could not parse command line options correctly: " + e.getMessage());
        return;
    }

    //
    // configuring logging services
    //

    try {
        LogManager.getLogManager()
                .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE));
    } catch (Exception e) {
        throw new Error("Could not load logging properties file", e);
    }

    //
    // setting up UDP server
    //      

    try {
        new MSServer(port);
    } catch (Exception e) {
        LoggerFactory.getLogger(MSSMain.class).error("Could not execute MineSweeper server: ", e);
    }
}

From source file:edu.gslis.ts.DumpThriftData.java

public static void main(String[] args) {
    try {//from www  . java2s .c  o  m
        // Get the commandline options
        Options options = createOptions();
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        String in = cmd.getOptionValue("i");
        String sentenceParser = cmd.getOptionValue("p");
        String query = cmd.getOptionValue("q");
        String externalCollection = cmd.getOptionValue("e");

        // Get background statistics
        CollectionStats bgstats = new IndexBackedCollectionStats();
        bgstats.setStatSource(externalCollection);

        // Set query
        GQuery gquery = new GQuery();
        gquery.setText(query);
        gquery.setFeatureVector(new FeatureVector(query, null));

        // Setup the filter
        DumpThriftData f = new DumpThriftData();

        if (in != null) {
            File infile = new File(in);
            if (infile.isDirectory()) {
                for (File file : infile.listFiles()) {
                    if (file.isDirectory()) {
                        for (File filefile : file.listFiles()) {
                            System.err.println(filefile.getAbsolutePath());
                            f.filter(filefile, sentenceParser, gquery, bgstats);
                        }
                    } else {
                        System.err.println(file.getAbsolutePath());
                        f.filter(file, sentenceParser, gquery, bgstats);
                    }
                }
            } else
                System.err.println(infile.getAbsolutePath());
            f.filter(infile, sentenceParser, gquery, bgstats);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:eu.optimis.monitoring.amazoncollector.Collector.java

public static void main(String[] args) {

    Collector collector = new Collector();
    Options options = new Options();
    Option id = OptionBuilder.withArgName("id").hasArg().withDescription("use given collector ID")
            .create(ID_OPT);/*from   w  ww . j  ava 2s.com*/
    Option conf = OptionBuilder.withArgName("configuration path").hasArg().withDescription("Configuration path")
            .create(PATH_OPT);
    options.addOption(id);
    options.addOption(conf);

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Incorrect parameters: " + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("collector", options);
        System.exit(2); //Incorrect usage
    }

    if (line.hasOption(ID_OPT)) {
        String cid = line.getOptionValue(ID_OPT);
        Measurement.setDefCollectorId(cid);
        System.out.println("Using Collector ID: " + cid);
    } else {
        System.out.println("Using default Collector ID: " + DEFAULT_ID + " (To use custom ID use -i argument)");
        Measurement.setDefCollectorId(DEFAULT_ID);
    }

    if (line.hasOption(PATH_OPT)) {
        collector.propertiesPath = line.getOptionValue(PATH_OPT);
        System.out.println("Using Properties file: " + collector.propertiesPath);
    } else {
        System.out.println("Using default Configuration file: " + DEFAULT_PROPERTIES_PATH
                + " (To use custom path use -c argument)");
        collector.propertiesPath = DEFAULT_PROPERTIES_PATH;
    }

    collector.getProperties();

    MeasurementsHelper helper = new MeasurementsHelper(collector.accessKey, collector.secretKey);
    List<Measurement> measurements = helper.getMeasurements();

    String xmlData = XMLHelper.createDocument(measurements);
    RESTHelper rest = new RESTHelper(collector.aggregatorURL);
    rest.sendDocument(xmlData);
}

From source file:BasApp.java

public static void main(String[] args) throws Exception {
    Options options = getOptions();//from   ww  w.j  a  va2s. c o m
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("h")) {
        showHelp(options);
        return; // only show help and exit
    }

    final VOConfig cfg;
    if (cmd.hasOption("config")) {
        Serializer serializer = new Persister();
        final String config = cmd.getOptionValue("config");
        FileInputStream fis = new FileInputStream(config);
        cfg = serializer.read(VOConfig.class, fis);
        fis.close();
    } else {
        cfg = new VOConfig();
    }

    cfg.setCmd(cmd);

    CipherProvider dataCipherProvider = new CipherProvider();
    dataCipherProvider.setPassword(cmd.getOptionValue("passwd", null));
    CipherProvider metaCipherProvider = new CipherProvider();
    metaCipherProvider.setPassword(cmd.getOptionValue("passwd-meta", null));

    String repoPathStr = cfg.getRepository();
    Repository repository = new Repository(repoPathStr, dataCipherProvider, metaCipherProvider);

    if (cmd.hasOption("dump-config")) {
        Serializer serializer = new Persister();
        final FileOutputStream fos = new FileOutputStream(cmd.getOptionValue("dump-config"));
        serializer.write(cfg, fos);
        fos.close();
    }

    if (cmd.hasOption("backup")) {
        BackupService backup = new BackupService(cfg, repository);
        backup.run();
    }

    if (cmd.hasOption("restore")) {
        //noinspection unchecked
        String restoreTo = null;
        if (cmd.hasOption("restore-to")) {
            restoreTo = cmd.getOptionValue("restore-to");
        }

        RestoreService restore = new RestoreService(cmd.getOptionValue("r"), repository, cmd.getArgList(),
                restoreTo);
        restore.run();
    }

    if (cmd.hasOption("check")) {
        CheckService check = new CheckService(cmd.getOptionValue("check"), repository);
        check.run();
    }
}

From source file:edu.gslis.ts.ChunkToFile.java

public static void main(String[] args) {
    try {/*from  w  w w.ja v a2s.  co  m*/
        // Get the commandline options
        Options options = createOptions();
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        String inputPath = cmd.getOptionValue("input");
        String indexPath = cmd.getOptionValue("index");
        String eventsPath = cmd.getOptionValue("events");
        String stopPath = cmd.getOptionValue("stop");
        String outputPath = cmd.getOptionValue("output");

        IndexWrapper index = IndexWrapperFactory.getIndexWrapper(indexPath);
        Stopper stopper = new Stopper(stopPath);
        Map<Integer, FeatureVector> queries = readEvents(eventsPath, stopper);

        // Setup the filter
        ChunkToFile f = new ChunkToFile();
        if (inputPath != null) {
            File infile = new File(inputPath);
            if (infile.isDirectory()) {
                Iterator<File> files = FileUtils.iterateFiles(infile, null, true);

                while (files.hasNext()) {
                    File file = files.next();
                    System.err.println(file.getAbsolutePath());
                    f.filter(file, queries, index, stopper, outputPath);
                }
            } else
                System.err.println(infile.getAbsolutePath());
            f.filter(infile, queries, index, stopper, outputPath);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.zib.chordsharp.Main.java

/**
 * Queries the command line options for an action to perform.
 * /*from w  ww.  jav a 2 s. c  o m*/
 * <pre>
 * {@code
 * > java -jar chordsharp.jar -help
 * usage: chordsharp
 *  -getsubscribers <topic>   get subscribers of a topic
 *  -help                     print this message
 *  -publish <params>         publish a new message for a topic: <topic> <message>
 *  -read <key>               read an item
 *  -subscribe <params>       subscribe to a topic: <topic> <url>
 *  -unsubscribe <params>     unsubscribe from a topic: <topic> <url>
 *  -write <params>           write an item: <key> <value>
 *  -minibench                run mini benchmark
 * }
 * </pre>
 * 
 * @param args command line arguments
 */
public static void main(String[] args) {
    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(getOptions(), args);
    } catch (ParseException e) {
        System.err.println("Parsing failed. Reason: " + e.getMessage());
        System.exit(0);
    }

    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("chordsharp", getOptions());
        System.exit(0);
    }

    if (line.hasOption("minibench")) {
        minibench();
        System.exit(0);
    }

    if (line.hasOption("read")) {
        try {
            System.out.println("read(" + line.getOptionValue("read") + ") == "
                    + ChordSharp.read(line.getOptionValue("read")));
        } catch (ConnectionException e) {
            System.err.println("read failed: " + e.getMessage());
        } catch (TimeoutException e) {
            System.err.println("read failed with timeout: " + e.getMessage());
        } catch (NotFoundException e) {
            System.err.println("read failed with not found: " + e.getMessage());
        } catch (UnknownException e) {
            System.err.println("read failed with unknown: " + e.getMessage());
        }
    }
    if (line.hasOption("write")) {
        try {
            System.out.println("write(" + line.getOptionValues("write")[0] + ", "
                    + line.getOptionValues("write")[1] + ")");
            ChordSharp.write(line.getOptionValues("write")[0], line.getOptionValues("write")[1]);
        } catch (ConnectionException e) {
            System.err.println("write failed with connection error: " + e.getMessage());
        } catch (TimeoutException e) {
            System.err.println("write failed with timeout: " + e.getMessage());
        } catch (UnknownException e) {
            System.err.println("write failed with unknown: " + e.getMessage());
        }
    }
    if (line.hasOption("publish")) {
        try {
            System.out.println("publish(" + line.getOptionValues("publish")[0] + ", "
                    + line.getOptionValues("publish")[1] + ")");
            ChordSharp.publish(line.getOptionValues("publish")[0], line.getOptionValues("publish")[1]);
        } catch (ConnectionException e) {
            System.err.println("publish failed with connection error: " + e.getMessage());
            //         } catch (TimeoutException e) {
            //            System.err.println("publish failed with timeout: "
            //                  + e.getMessage());
            //         } catch (UnknownException e) {
            //            System.err.println("publish failed with unknown: "
            //                  + e.getMessage());
        }
    }
    if (line.hasOption("subscribe")) {
        try {
            System.out.println("subscribe(" + line.getOptionValues("subscribe")[0] + ", "
                    + line.getOptionValues("subscribe")[1] + ")");
            ChordSharp.subscribe(line.getOptionValues("subscribe")[0], line.getOptionValues("subscribe")[1]);
        } catch (ConnectionException e) {
            System.err.println("subscribe failed with connection error: " + e.getMessage());
        } catch (TimeoutException e) {
            System.err.println("subscribe failed with timeout: " + e.getMessage());
        } catch (UnknownException e) {
            System.err.println("subscribe failed with unknown: " + e.getMessage());
        }
    }
    if (line.hasOption("unsubscribe")) {
        try {
            System.out.println("unsubscribe(" + line.getOptionValues("unsubscribe")[0] + ", "
                    + line.getOptionValues("unsubscribe")[1] + ")");
            ChordSharp.unsubscribe(line.getOptionValues("unsubscribe")[0],
                    line.getOptionValues("unsubscribe")[1]);
        } catch (ConnectionException e) {
            System.err.println("unsubscribe failed with connection error: " + e.getMessage());
        } catch (TimeoutException e) {
            System.err.println("unsubscribe failed with timeout: " + e.getMessage());
        } catch (NotFoundException e) {
            System.err.println("unsubscribe failed with not found: " + e.getMessage());
        } catch (UnknownException e) {
            System.err.println("unsubscribe failed with unknown: " + e.getMessage());
        }
    }
    if (line.hasOption("getsubscribers")) {
        try {
            System.out.println("getSubscribers(" + line.getOptionValues("getsubscribers")[0] + ") == "
                    + ChordSharp.getSubscribers(line.getOptionValues("getsubscribers")[0]));
        } catch (ConnectionException e) {
            System.err.println("getSubscribers failed with connection error: " + e.getMessage());
            //         } catch (TimeoutException e) {
            //            System.err.println("getSubscribers failed with timeout: "
            //                  + e.getMessage());
        } catch (UnknownException e) {
            System.err.println("getSubscribers failed with unknown error: " + e.getMessage());
        }
    }
}

From source file:ar.com.ergio.uncoma.cei.MiniPas.java

/**
 * @param args/* w  w w. ja  v a2s . com*/
 * @throws IOException 
 */
@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {
    // Config logging system -- TODO improve this
    Handler console = new ConsoleHandler();
    ROOT_LOG.addHandler(console);

    // Create cmdline options - TODO - I18N
    final Options options = new Options();
    options.addOption(new Option("help", "Muestra este mensaje"));
    options.addOption(new Option("version", "Muestra la informaci\u00f3 de versi\u00f3n y termina"));
    options.addOption(new Option("debug", "Muestra informaci\u00f3n para depuraci\u00f3n"));
    options.addOption(
            OptionBuilder.withArgName("file").hasArg().withDescription("Archivo de log").create("logFile"));

    final CommandLineParser cmdlineParser = new GnuParser();
    final HelpFormatter formatter = new HelpFormatter();
    try {
        final CommandLine cmdline = cmdlineParser.parse(options, args);

        // Process command line args  -- TODO Improve this
        if (args.length == 0 || cmdline.hasOption("help")) {
            formatter.printHelp("minipas", options, true);
        } else if (cmdline.hasOption("version")) {
            System.out.println("MiniPas versi\u00f3n: 0.0.1");
        } else if (cmdline.hasOption("debug")) {
            ROOT_LOG.setLevel(Level.FINE);
        } else {
            ROOT_LOG.fine("Arguments: " + Arrays.toString(args));
            final Scanner scanner = new Scanner(args[0]);
            while (scanner.hasTokens()) {
                System.out.println(scanner.nextToken());
            }
        }

    } catch (ParseException e) {
        formatter.printHelp("minipas", options, true);
    }
}

From source file:de.dfki.dmas.owls2wsdl.core.OWLS2WSDL.java

public static void main(String[] args) {
    // http://jakarta.apache.org/commons/cli/usage.html
    System.out.println("ARG COUNT: " + args.length);

    OWLS2WSDLSettings.getInstance();/*  w w  w.ja  v  a2 s .c  o m*/

    Options options = new Options();
    Option help = new Option("help", "print help message");
    options.addOption(help);

    // create the parser
    CommandLineParser parser = new GnuParser();
    CommandLine cmdLine = null;

    for (int i = 0; i < args.length; i++) {
        System.out.println("ARG: " + args[i].toString());
    }

    if (args.length > 0) {
        if (args[args.length - 1].toString().endsWith(".owl")) {
            // -kbdir d:\tmp\KB http://127.0.0.1/ontology/ActorDefault.owl
            Option test = new Option("test", "parse only, don't save");
            @SuppressWarnings("static-access")
            Option kbdir = OptionBuilder.withArgName("dir").hasArg()
                    .withDescription("knowledgebase directory; necessary").create("kbdir");
            options.addOption(test);
            options.addOption(kbdir);

            try {
                cmdLine = parser.parse(options, args);
                if (cmdLine.hasOption("help")) {
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.printHelp("owls2wsdl [options] FILE.owl", options);
                    System.exit(0);
                }
            } catch (ParseException exp) {
                // oops, something went wrong
                System.out.println("Error: Parsing failed, reason: " + exp.getMessage());
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("owls2wsdl", options, true);
            }

            if (args.length == 1) {
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("owls2wsdl [options] FILE.owl", options);
                System.out.println("Error: Option -kbdir is missing.");
                System.exit(0);
            } else {
                String ontURI = args[args.length - 1].toString();
                String persistentName = "KB_"
                        + ontURI.substring(ontURI.lastIndexOf("/") + 1, ontURI.lastIndexOf(".")) + "-MAP.xml";

                try {
                    if (cmdLine.hasOption("kbdir")) {
                        String kbdirValue = cmdLine.getOptionValue("kbdir");
                        if (new File(kbdirValue).isDirectory()) {
                            DatatypeParser p = new DatatypeParser();
                            p.parse(args[args.length - 1].toString());
                            p.getAbstractDatatypeKBData();
                            if (!cmdLine.hasOption("test")) {
                                System.out.println("AUSGABE: " + kbdirValue + File.separator + persistentName);
                                FileOutputStream ausgabeStream = new FileOutputStream(
                                        kbdirValue + File.separator + persistentName);
                                AbstractDatatypeKB.getInstance().marshallAsXML(ausgabeStream, true); // System.out);
                            }
                        }
                    }
                } catch (java.net.MalformedURLException murle) {
                    System.err.println("MalformedURLException: " + murle.getMessage());
                    System.err.println("Try something like: http://127.0.0.1/ontology/my_ontology.owl");
                } catch (Exception e) {
                    System.err.println("Exception: " + e.toString());
                }
            }
        } else if (args[args.length - 1].toString().endsWith(".xml")) {
            // -owlclass http://127.0.0.1/ontology/Student.owl#HTWStudent
            // -xsd -d 1 -h D:\tmp\KB\KB_Student-MAP.xml
            Option xsd = new Option("xsd", "generate XML Schema");
            Option info = new Option("info", "print datatype information");
            @SuppressWarnings("static-access")
            Option owlclass = OptionBuilder.withArgName("class").hasArg()
                    .withDescription("owl class to translate; necessary").create("owlclass");
            Option keys = new Option("keys", "list all owlclass keys");
            options.addOption(keys);
            options.addOption(owlclass);
            options.addOption(info);
            options.addOption(xsd);
            options.addOption("h", "hierarchy", false, "use hierarchy pattern");
            options.addOption("d", "depth", true, "set recursion depth");
            options.addOption("b", "behavior", true, "set inheritance bevavior");
            options.addOption("p", "primitive", true, "set default primitive type");

            try {
                cmdLine = parser.parse(options, args);
                if (cmdLine.hasOption("help")) {
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.printHelp("owls2wsdl [options] FILE.xml", options);
                    System.exit(0);
                }
            } catch (ParseException exp) {
                // oops, something went wrong
                System.out.println("Error: Parsing failed, reason: " + exp.getMessage());
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("owls2wsdl", options, true);
            }

            if (args.length == 1) {
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("owls2wsdl [options] FILE.xml", options);
                System.exit(0);
            } else if (cmdLine.hasOption("keys")) {
                File f = new File(args[args.length - 1].toString());
                try {
                    AbstractDatatypeMapper.getInstance().loadAbstractDatatypeKB(f);
                } catch (Exception e) {
                    System.err.println("Error: " + e.getMessage());
                    System.exit(1);
                }
                AbstractDatatypeKB.getInstance().getAbstractDatatypeKBData().printRegisteredDatatypes();
                System.exit(0);
            } else if (!cmdLine.hasOption("owlclass")) {
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("owls2wsdl [options] FILE.xml", "", options,
                        "Info: owl class not set.\n e.g. -owlclass http://127.0.0.1/ontology/Student.owl#Student");
                System.exit(0);
            } else {
                File f = new File(args[args.length - 1].toString());
                try {
                    AbstractDatatypeMapper.getInstance().loadAbstractDatatypeKB(f);
                } catch (Exception e) {
                    System.err.println("Error: " + e.getMessage());
                    System.exit(1);
                }

                String owlclassString = cmdLine.getOptionValue("owlclass");
                if (!AbstractDatatypeKB.getInstance().getAbstractDatatypeKBData().containsKey(owlclassString)) {
                    System.err.println("Error: Key " + owlclassString + " not in knowledgebase.");
                    System.exit(1);
                }

                if (cmdLine.hasOption("info")) {
                    AbstractDatatypeKB.getInstance().getAbstractDatatypeKBData().get(owlclassString)
                            .printDatatype();
                }
                if (cmdLine.hasOption("xsd")) {
                    boolean hierachy = false;
                    int depth = 0;
                    String inheritanceBehavior = AbstractDatatype.InheritanceByNone;
                    String defaultPrimitiveType = "http://www.w3.org/2001/XMLSchema#string";

                    if (cmdLine.hasOption("h")) {
                        hierachy = true;
                    }
                    if (cmdLine.hasOption("d")) {
                        depth = Integer.parseInt(cmdLine.getOptionValue("d"));
                    }
                    if (cmdLine.hasOption("b")) {
                        System.out.print("Set inheritance behaviour to: ");
                        if (cmdLine.getOptionValue("b")
                                .equals(AbstractDatatype.InheritanceByParentsFirstRDFTypeSecond)) {
                            System.out.println(AbstractDatatype.InheritanceByParentsFirstRDFTypeSecond);
                            inheritanceBehavior = AbstractDatatype.InheritanceByNone;
                        } else if (cmdLine.getOptionValue("b")
                                .equals(AbstractDatatype.InheritanceByRDFTypeFirstParentsSecond)) {
                            System.out.println(AbstractDatatype.InheritanceByRDFTypeFirstParentsSecond);
                            inheritanceBehavior = AbstractDatatype.InheritanceByRDFTypeFirstParentsSecond;
                        } else if (cmdLine.getOptionValue("b")
                                .equals(AbstractDatatype.InheritanceByRDFTypeOnly)) {
                            System.out.println(AbstractDatatype.InheritanceByRDFTypeOnly);
                            inheritanceBehavior = AbstractDatatype.InheritanceByRDFTypeOnly;
                        } else if (cmdLine.getOptionValue("b")
                                .equals(AbstractDatatype.InheritanceBySuperClassOnly)) {
                            System.out.println(AbstractDatatype.InheritanceBySuperClassOnly);
                            inheritanceBehavior = AbstractDatatype.InheritanceBySuperClassOnly;
                        } else {
                            System.out.println(AbstractDatatype.InheritanceByNone);
                            inheritanceBehavior = AbstractDatatype.InheritanceByNone;
                        }
                    }
                    if (cmdLine.hasOption("p")) {
                        defaultPrimitiveType = cmdLine.getOptionValue("p");
                        if (defaultPrimitiveType.split("#")[0].equals("http://www.w3.org/2001/XMLSchema")) {
                            System.err.println("Error: Primitive Type not valid: " + defaultPrimitiveType);
                            System.exit(1);
                        }
                    }
                    XsdSchemaGenerator xsdgen = new XsdSchemaGenerator("SCHEMATYPE", hierachy, depth,
                            inheritanceBehavior, defaultPrimitiveType);

                    try {
                        AbstractDatatypeKB.getInstance().toXSD(owlclassString, xsdgen, System.out);
                    } catch (Exception e) {
                        System.err.println("Error: " + e.getMessage());
                    }
                }

            }
        } else {
            try {
                cmdLine = parser.parse(options, args);
                if (cmdLine.hasOption("help")) {
                    printDefaultHelpMessage();
                }
            } catch (ParseException exp) {
                // oops, something went wrong
                System.out.println("Error: Parsing failed, reason: " + exp.getMessage());
                printDefaultHelpMessage();
            }
        }
    } else {
        OWLS2WSDLGui.createAndShowGUI();
    }

    // for(Iterator it=options.getOptions().iterator(); it.hasNext(); ) {
    // String optString = ((Option)it.next()).getOpt();
    // if(cmdLine.hasOption(optString)) {
    // System.out.println("Option set: "+optString);
    // }
    // }

}

From source file:de.robert_heim.unfuddle2bitbucket.UnfuddleToBitbucket.java

public static void main(String[] args) {

    // create the command line parser
    CommandLineParser parser = new GnuParser();

    Options helpOptions = HelpOptions.create();
    Options runtimeOptions = RuntimeOptions.create(helpOptions);

    try {/* w  ww  .ja  va  2  s.  com*/
        // parse the command line arguments for help or version
        HelpOrVersionRunner.parseAndRunCLIHelpOrVersion(parser, helpOptions, runtimeOptions, args,
                APPLICATION_NAME, VERSION_FILE);

        // parse the command line arguments for runtime
        ProgramRunner.parseAndRunCLIRuntime(parser, helpOptions, runtimeOptions, args);

    } catch (ParseException exp) {
        System.out.println("Error: " + exp.getMessage());
        UsagePrinter.printUsageAndHelp(APPLICATION_NAME, runtimeOptions, System.out);
    } catch (JAXBException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}

From source file:cnxchecker.Server.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("p", "port", true, "TCP port to bind to (random by default)");
    options.addOption("h", "help", false, "Print help");

    CommandLineParser parser = new GnuParser();
    try {/*from   w  w  w. j  a  v  a2 s. co  m*/
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp("server", options);
            System.exit(0);
        }

        int port = 0;
        if (cmd.hasOption("p")) {
            try {
                port = Integer.parseInt(cmd.getOptionValue("p"));
            } catch (NumberFormatException e) {
                printAndExit("Invalid port number " + cmd.getOptionValue("p"));
            }

            if (port < 0 || port > 65535) {
                printAndExit("Invalid port number " + port);
            }
        }

        Server server = new Server(port);
        server.doit();
    } catch (ParseException e) {
        printAndExit("Failed to parse options: " + e.getMessage());
    }
}