Example usage for org.apache.commons.cli HelpFormatter printHelp

List of usage examples for org.apache.commons.cli HelpFormatter printHelp

Introduction

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

Prototype

public void printHelp(String cmdLineSyntax, Options options) 

Source Link

Document

Print the help for options with the specified command line syntax.

Usage

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.TotalFreqAmout.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("index").withDescription("The path to the web1t lucene index")
            .hasArg().isRequired().create());

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;//from   w w w  .  j a va  2s. co  m
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Error: " + e.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("countTotalFreq", options);
        return;
    }

    TotalFreqAmout amount = new TotalFreqAmout(new File(cmd.getOptionValue("index")));
    System.out.println("Total amount: " + amount.countFreq());
}

From source file:cd.what.DutchBot.Main.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException, IrcException, InterruptedException,
        ConfigurationException, InstantiationException, IllegalAccessException {
    String configfile = "irc.properties";
    DutchBot bot = null;/*ww w  .j  ava 2 s. com*/

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("config").withArgName("configfile").hasArg()
            .withDescription("Load configuration from configfile, or use the default irc.cfg").create("c"));
    options.addOption(OptionBuilder.withLongOpt("server").withArgName("<url>").hasArg()
            .withDescription("Connect to this server").create("s"));
    options.addOption(OptionBuilder.withLongOpt("port").hasArg().withArgName("port")
            .withDescription("Connect to the server with this port").create("p"));
    options.addOption(OptionBuilder.withLongOpt("password").hasArg().withArgName("password")
            .withDescription("Connect to the server with this password").create("pw"));
    options.addOption(OptionBuilder.withLongOpt("nick").hasArg().withArgName("nickname")
            .withDescription("Connect to the server with this nickname").create("n"));
    options.addOption(OptionBuilder.withLongOpt("nspass").hasArg().withArgName("password")
            .withDescription("Sets the password for NickServ").create("ns"));
    options.addOption("h", "help", false, "Displays this menu");

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cli = parser.parse(options, args);
        if (cli.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("DutchBot", options);
            return;
        }
        // check for override config file
        if (cli.hasOption("c"))
            configfile = cli.getOptionValue("c");

        bot = new DutchBot(configfile);

        // Read the cli parameters
        if (cli.hasOption("pw"))
            bot.setServerPassword(cli.getOptionValue("pw"));
        if (cli.hasOption("s"))
            bot.setServerAddress(cli.getOptionValue("s"));
        if (cli.hasOption("p"))
            bot.setIrcPort(Integer.parseInt(cli.getOptionValue("p")));
        if (cli.hasOption("n"))
            bot.setBotName(cli.getOptionValue("n"));
        if (cli.hasOption("ns"))
            bot.setNickservPassword(cli.getOptionValue("ns"));

    } catch (ParseException e) {
        System.err.println("Error parsing command line vars " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("DutchBot", options);
        System.exit(1);
    }

    boolean result = bot.tryConnect();

    if (result)
        bot.logMessage("Connected");
    else {
        System.out.println(" Connecting failed :O");
        System.exit(1);
    }
}

From source file:com.twitter.bazel.checkstyle.CppCheckstyle.java

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new DefaultParser();

    // create the Options
    Options options = new Options();
    options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file")
            .desc("bazel extra action protobuf file").build());
    options.addOption(Option.builder("c").required(true).hasArg().longOpt("cpplint_file")
            .desc("Executable cpplint file to invoke").build());

    try {/*from  www  .j  a v a 2s.co  m*/
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        String extraActionFile = line.getOptionValue("f");
        String cpplintFile = line.getOptionValue("c");

        Collection<String> sourceFiles = getSourceFiles(extraActionFile);
        if (sourceFiles.size() == 0) {
            LOG.fine("No cpp files found by checkstyle");
            return;
        }

        LOG.fine(sourceFiles.size() + " cpp files found by checkstyle");

        // Create and run the command
        List<String> commandBuilder = new ArrayList<>();
        commandBuilder.add(cpplintFile);
        commandBuilder.add("--linelength=100");
        // TODO: https://github.com/twitter/heron/issues/466,
        // Remove "runtime/references" when we fix all non-const references in our codebase.
        // TODO: https://github.com/twitter/heron/issues/467,
        // Remove "runtime/threadsafe_fn" when we fix all non-threadsafe libc functions
        commandBuilder.add("--filter=-build/header_guard,-runtime/references,-runtime/threadsafe_fn");
        commandBuilder.addAll(sourceFiles);
        runLinter(commandBuilder);

    } catch (ParseException exp) {
        LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java " + CLASSNAME, options);
    }
}

From source file:com.ingby.socbox.bischeck.migration.Properties2ServerProperties.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new GnuParser();
    CommandLine line = null;//from  www  .ja  va 2s. com
    // create the Options
    Options options = new Options();
    options.addOption("u", "usage", false, "show usage.");
    options.addOption("v", "verbose", false, "verbose - do not write to files");
    options.addOption("s", "source", true, "directory old properties.xml is located");
    options.addOption("d", "destination", true, "directory where the new xml files while be stored");

    try {
        // parse the command line arguments
        line = parser.parse(options, args);

    } catch (org.apache.commons.cli.ParseException e) {
        System.out.println("Command parse error:" + e.getMessage());
        Util.ShellExit(1);
    }

    if (line.hasOption("usage")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("DB2XMLConvert", options);
        Util.ShellExit(0);
    }

    Properties2ServerProperties converter = new Properties2ServerProperties();

    if (line.hasOption("source")) {
        String sourcedir = line.getOptionValue("source");
        String destdir = ".";
        if (line.hasOption("destination")) {
            destdir = line.getOptionValue("destination");
        }

        converter.createXMLServerProperties(sourcedir, destdir);

    }
}

From source file:edu.ucsb.cs.eager.sa.cerebro.ProfessorX.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("i", "input-file", true, "Path to input xml file");
    options.addOption("r", "root-path", true, "Root path of all Git repositories");

    CommandLine cmd;/*from   ww w . j a v a  2  s. c om*/
    try {
        CommandLineParser parser = new BasicParser();
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Error: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Cerebro", options);
        return;
    }

    String inputFileName = cmd.getOptionValue("i");
    if (inputFileName == null) {
        System.err.println("input file path is required");
        return;
    }

    String rootPath = cmd.getOptionValue("r");
    if (rootPath == null) {
        System.err.println("root path is required");
        return;
    }

    File inputFile = new File(inputFileName);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    Document doc;
    try {
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(inputFile);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        return;
    }

    NodeList repoList = doc.getElementsByTagName("repo");
    for (int i = 0; i < repoList.getLength(); i++) {
        Element repo = (Element) repoList.item(i);
        String name = repo.getElementsByTagName("name").item(0).getTextContent();
        String classPath = repo.getElementsByTagName("classpath").item(0).getTextContent();
        Set<String> classes = new LinkedHashSet<String>();
        NodeList classesList = repo.getElementsByTagName("classes").item(0).getChildNodes();
        for (int j = 0; j < classesList.getLength(); j++) {
            if (!(classesList.item(j) instanceof Element)) {
                continue;
            }
            classes.add(classesList.item(j).getTextContent());
        }
        analyzeRepo(rootPath, name, classPath, classes);
    }
}

From source file:be.i8c.sag.wm.is.SwaggerImporter.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new DefaultParser();
    Options options = getOptions();//from   w  w  w .  jav a2 s . c o  m
    CommandLine cmd = parser.parse(options, args);
    HelpFormatter formatter = new HelpFormatter();
    if (cmd.hasOption("h")) {
        formatter.printHelp("", options);
    } else if (cmd.hasOption("is") && cmd.hasOption("u") && cmd.hasOption("p") && cmd.hasOption("swf")
            && cmd.hasOption("pkg")) {
        SwaggerParser swaggerParser = new SwaggerParser();
        Swagger swaggerModel = swaggerParser.read(cmd.getOptionValue("swf"));
        String[] conn = cmd.getOptionValue("is").split(":");
        String host = conn[0];
        String port = "80";
        if (conn.length > 1) {
            port = conn[1];
        }
        ServerConnection sc = new ServerConnection(host, port, cmd.getOptionValue("u"), cmd.getOptionValue("p"),
                false);
        try {
            logger.info("Connecting to server " + host + "(" + port + ")");
            sc.connect();
            logger.info("Connected to server");

            RestImplementation ri = new RestImplementation(sc, swaggerModel, cmd.getOptionValue("pkg"),
                    cmd.getOptionValue("acl"));

            ri.generateImplementation();

        } catch (Throwable e) {
            logger.error("Error: " + e.getMessage());
            //logger.error(e.getStackTrace());
            e.printStackTrace();
        } finally {
            logger.info("Disconnecting from server");
            sc.disconnect();
            ServerConnectionManager.getInstance().closeServerConnectionManager();
            logger.info("Disconnected from server");
            logger.info("BYE");
            System.exit(0);
        }
    }

}

From source file:at.tfr.securefs.client.SecurefsClient.java

public static void main(String[] args) throws Exception {

    SecurefsClient client = new SecurefsClient();
    try {//from w w w . j av a  2s  . c o  m
        client.parse(args);

        if (client.asyncTest) {
            ExecutorService executor = Executors.newFixedThreadPool(client.threads);
            for (int i = 0; i < client.threads; i++) {
                executor.submit(client);
            }
            executor.shutdown();
            executor.awaitTermination(10, TimeUnit.MINUTES);
        } else {
            client.run();
        }

    } catch (Throwable e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp(SecurefsClient.class.getSimpleName(), client.options);
        e.printStackTrace();
    }
}

From source file:com.vaadin.buildhelpers.CompileTheme.java

/**
 * @param args//  w w  w .  ja  v  a  2 s.com
 * @throws IOException
 * @throws ParseException
 */
public static void main(String[] args) throws IOException, ParseException {
    Options options = new Options();
    options.addOption("t", "theme", true, "the theme to compile");
    options.addOption("v", "theme-version", true, "the version to add to the compiled theme");
    options.addOption("f", "theme-folder", true, "the folder containing the theme");
    CommandLineParser parser = new PosixParser();
    CommandLine params = parser.parse(options, args);
    if (!params.hasOption("theme") || !params.hasOption("theme-folder")) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(CompileTheme.class.getName(), options);
        return;
    }
    String themeName = params.getOptionValue("theme");
    String themeFolder = params.getOptionValue("theme-folder");
    String themeVersion = params.getOptionValue("theme-version");

    // Regular theme
    try {
        processSassTheme(themeFolder, themeName, "styles", themeVersion);
        System.out.println("Compiling theme " + themeName + " styles successful");
    } catch (Exception e) {
        System.err.println("Compiling theme " + themeName + " styles failed");
        e.printStackTrace();
    }
    // Legacy theme w/o .themename{} wrapping
    try {
        processSassTheme(themeFolder, themeName, "legacy-styles", themeVersion);
        System.out.println("Compiling theme " + themeName + " legacy-styles successful");
    } catch (Exception e) {
        System.err.println("Compiling theme " + themeName + " legacy-styles failed");
        e.printStackTrace();
    }
}

From source file:com.mebigfatguy.roomstore.RoomStore.java

public static void main(String[] args) {
    Options options = createOptions();/*from   w w w  . ja  va  2s  .c  o  m*/

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cmdLine = parser.parse(options, args);
        String nickname = cmdLine.getOptionValue(NICK_NAME);
        String server = cmdLine.getOptionValue(IRCSERVER);
        String[] channels = cmdLine.getOptionValues(CHANNELS);
        String[] endPoints = cmdLine.getOptionValues(ENDPOINTS);
        String rf = cmdLine.getOptionValue(RF);

        if ((endPoints == null) || (endPoints.length == 0)) {
            endPoints = new String[] { "127.0.0.1" };
        }

        int replicationFactor;
        try {
            replicationFactor = Integer.parseInt(rf);
        } catch (Exception e) {
            replicationFactor = 1;
        }

        final IRCConnector connector = new IRCConnector(nickname, server, channels);

        Cluster cluster = new Cluster.Builder().addContactPoints(endPoints).build();
        final Session session = cluster.connect();

        CassandraWriter writer = new CassandraWriter(session, replicationFactor);
        connector.setWriter(writer);

        connector.startRecording();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                connector.stopRecording();
                session.close();
            }
        }));

    } catch (ParseException pe) {
        System.out.println("Parse Error on command line options:");
        System.out.println(commandLineRepresentation(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("roomstore", options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.k42b3.quantum.Entry.java

public static void main(String[] args) throws Exception {
    // logging//from  w  w  w.  jav a2 s  .c om
    Layout layout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN);

    Logger.getLogger("com.k42b3.quantum").addAppender(new WriterAppender(layout, System.out));

    // options
    Options options = new Options();
    options.addOption("p", "port", false, "Port for the web server default is 8080");
    options.addOption("i", "interval", false,
            "The interval how often each worker gets triggered in minutes default is 2");
    options.addOption("d", "database", false, "Path to the sqlite database default is \"quantum.db\"");
    options.addOption("l", "log", false,
            "Defines the log level default is ERROR possible is (ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)");
    options.addOption("v", "version", false, "Shows the current version");
    options.addOption("h", "help", false, "Shows the help");

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

    // start app
    Quantum app = new Quantum();

    if (cmd.hasOption("p")) {
        try {
            int port = Integer.parseInt(cmd.getOptionValue("p"));

            app.setPort(port);
        } catch (NumberFormatException e) {
            Logger.getLogger("com.k42b3.quantum").info("Port must be an integer");
        }
    }

    if (cmd.hasOption("i")) {
        try {
            int pollInterval = Integer.parseInt(cmd.getOptionValue("i"));

            app.setPollInterval(pollInterval);
        } catch (NumberFormatException e) {
            Logger.getLogger("com.k42b3.quantum").info("Interval must be an integer");
        }
    }

    if (cmd.hasOption("d")) {
        String dbPath = cmd.getOptionValue("d");

        if (!dbPath.isEmpty()) {
            app.setDbPath(dbPath);
        }
    }

    if (cmd.hasOption("l")) {
        Logger.getLogger("com.k42b3.quantum").setLevel(Level.toLevel(cmd.getOptionValue("l")));
    } else {
        Logger.getLogger("com.k42b3.quantum").setLevel(Level.ERROR);
    }

    if (cmd.hasOption("v")) {
        System.out.println("Version: " + Quantum.VERSION);
        System.exit(0);
    }

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

    app.run();
}