Search in sources :

Example 96 with ParseException

use of org.apache.commons.cli.ParseException in project java-jotasync by trixon.

the class Main method main.

/**
 * @param args the command line arguments
 * @throws java.rmi.RemoteException
 */
public static void main(String[] args) throws RemoteException, IOException {
    SystemHelper.enableRmiServer();
    Options options = initOptions();
    CommandLineParser parser = new DefaultParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            displayHelp(options);
        } else if (cmd.hasOption("version")) {
            displayVersion();
        } else {
            Server server = new Server(cmd);
        }
    } catch (ParseException ex) {
        Xlog.timedErr(ex.getMessage());
        System.out.println(sBundle.getString("parse_help_server"));
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 97 with ParseException

use of org.apache.commons.cli.ParseException in project rocketmq by apache.

the class ServerUtil method parseCmdLine.

public static CommandLine parseCmdLine(final String appName, String[] args, Options options, CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }
    return commandLine;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException)

Example 98 with ParseException

use of org.apache.commons.cli.ParseException in project rocketmq by apache.

the class Consumer method buildCommandline.

public static CommandLine buildCommandline(String[] args) {
    final Options options = new Options();
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("g", "consumerGroup", true, "Consumer Group Name");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("t", "topic", true, "Topic Name");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("s", "subscription", true, "subscription");
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message");
    opt.setRequired(true);
    options.addOption(opt);
    PosixParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp("producer", options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp("producer", options, true);
        return null;
    }
    return commandLine;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) Option(org.apache.commons.cli.Option) ParseException(org.apache.commons.cli.ParseException)

Example 99 with ParseException

use of org.apache.commons.cli.ParseException in project rocketmq by apache.

the class Producer method buildCommandline.

public static CommandLine buildCommandline(String[] args) {
    final Options options = new Options();
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("g", "producerGroup", true, "Producer Group Name");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("t", "topic", true, "Topic Name");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("a", "tags", true, "Tags Name");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("k", "keys", true, "Keys Name");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("c", "msgCount", true, "Message Count");
    opt.setRequired(true);
    options.addOption(opt);
    PosixParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp("producer", options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp("producer", options, true);
        return null;
    }
    return commandLine;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) Option(org.apache.commons.cli.Option) ParseException(org.apache.commons.cli.ParseException)

Example 100 with ParseException

use of org.apache.commons.cli.ParseException in project Angelia-core by Maxopoly.

the class PluginManager method parseOptions.

private Map<String, List<String>> parseOptions(AngeliaPlugin plugin, String[] args) {
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    for (Option opt : plugin.getOptions()) {
        options.addOption(opt);
    }
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args, true);
    } catch (MissingArgumentException e) {
        Option opt = e.getOption();
        connection.getLogger().warn("An incorrect amount of argument(s) was supplied for the option " + opt.getArgName() + ". Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
        return null;
    } catch (MissingOptionException e) {
        List<String> missingOptions = e.getMissingOptions();
        StringBuilder sb = new StringBuilder();
        for (String opt : missingOptions) {
            sb.append(opt + " ");
        }
        connection.getLogger().warn("The required argument(s) " + sb.toString() + "were not supplied. Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
        return null;
    } catch (UnrecognizedOptionException e) {
        connection.getLogger().warn("The supplied option " + e.getOption() + " could not be recognized. Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
        return null;
    } catch (ParseException e) {
        connection.getLogger().error("An unknown exception occured while trying to parse arguments", e);
        return null;
    }
    Map<String, List<String>> parsedValues = new HashMap<String, List<String>>();
    for (Option option : cmd.getOptions()) {
        if (option.hasArg()) {
            parsedValues.put(option.getOpt(), Arrays.asList(cmd.getOptionValues(option.getOpt())));
        } else {
            parsedValues.put(option.getOpt(), new LinkedList<String>());
        }
    }
    return parsedValues;
}
Also used : Options(org.apache.commons.cli.Options) HashMap(java.util.HashMap) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) List(java.util.List) LinkedList(java.util.LinkedList) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) MissingOptionException(org.apache.commons.cli.MissingOptionException) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

ParseException (org.apache.commons.cli.ParseException)586 CommandLine (org.apache.commons.cli.CommandLine)488 CommandLineParser (org.apache.commons.cli.CommandLineParser)380 Options (org.apache.commons.cli.Options)370 DefaultParser (org.apache.commons.cli.DefaultParser)220 HelpFormatter (org.apache.commons.cli.HelpFormatter)204 GnuParser (org.apache.commons.cli.GnuParser)173 IOException (java.io.IOException)124 Option (org.apache.commons.cli.Option)109 File (java.io.File)90 PosixParser (org.apache.commons.cli.PosixParser)65 Path (org.apache.hadoop.fs.Path)50 ArrayList (java.util.ArrayList)42 Properties (java.util.Properties)35 BasicParser (org.apache.commons.cli.BasicParser)31 FileInputStream (java.io.FileInputStream)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)26 List (java.util.List)25 URI (java.net.URI)21