本文整理汇总了Java中org.apache.commons.cli.DefaultParser类的典型用法代码示例。如果您正苦于以下问题:Java DefaultParser类的具体用法?Java DefaultParser怎么用?Java DefaultParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultParser类属于org.apache.commons.cli包,在下文中一共展示了DefaultParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseCommandLine
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
/**
* Usage: URPChecker \
* -brokerstatszk datazk001:2181/data07 \
* -brokerstatstopic brokerstats \
* -clusterzk m10nzk001:2181,...,m10nzk007:2181/m10n07
*/
private static CommandLine parseCommandLine(String[] args) {
Option zookeeper = new Option(ZOOKEEPER, true, "cluster zookeeper");
options.addOption(zookeeper);
if (args.length < 2) {
printUsageAndExit();
}
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException | NumberFormatException e) {
printUsageAndExit();
}
return cmd;
}
示例2: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Options options = getOptions();
try {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String[] streamId = StringUtils.split(cmd.getOptionValue("stream", DEFAULT_STREAM_ID), '/');
if(streamId.length != 2) {
throw new IllegalArgumentException("Stream spec must be in the form [scope]/[stream]");
}
final URI controllerURI = URI.create(cmd.getOptionValue("uri", DEFAULT_CONTROLLER_URI));
new NoopReader().run(streamId[0], streamId[1], controllerURI);
}
catch (ParseException e) {
System.out.format("%s.%n", e.getMessage());
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("NoopReader", options);
System.exit(1);
}
}
示例3: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
CommandLineParser parser = new DefaultParser();
CommandLine line = parser.parse(CLI_OPTIONS, args);
if (!line.hasOption("conf")) {
System.err.println("No configuration file is specified");
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("athenax-server", CLI_OPTIONS);
System.exit(1);
}
try {
String confFile = line.getOptionValue("conf");
AthenaXConfiguration conf = AthenaXConfiguration.load(Paths.get(confFile).toFile());
new AthenaXServer().start(conf);
} catch (IOException | ClassNotFoundException e) {
System.err.println("Failed to parse configuration.");
throw e;
}
}
示例4: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public final static void main(String[] args) throws Exception {
logger.debug(format("%s called with arguments: '%s'.", GetChangeStatus.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
Options options = new Options();
Commands.Helpers.addStandardParameters(options);
if(helpRequested(args)) {
handleHelpOption(format("%s <changeId>", getCommandName(GetChangeStatus.class)),
"Returns 'true' if the change specified by <changeId> is in development. Otherwise 'false'.", new Options()); return;
}
CommandLine commandLine = new DefaultParser().parse(options, args);
new GetChangeStatus(
getHost(commandLine),
getUser(commandLine),
getPassword(commandLine),
getChangeId(commandLine)).execute();
}
示例5: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
protected static void main(Class<? extends TransportRelated> clazz, String[] args, String usage, String helpText) throws Exception {
logger.debug(format("%s called with arguments: %s", clazz.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
Options options = new Options();
Commands.Helpers.addStandardParameters(options);
if(helpRequested(args)) {
handleHelpOption(usage, helpText, new Options()); return;
}
CommandLine commandLine = new DefaultParser().parse(options, args);
newInstance(clazz, getHost(commandLine),
getUser(commandLine),
getPassword(commandLine),
getChangeId(commandLine),
getTransportId(commandLine)).execute();
}
示例6: getCommandName
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
private static String getCommandName(String[] args) throws ParseException {
Options opts = new Options();
asList(CMOptions.HELP, CMOptions.VERSION, CMOptions.HOST, CMOptions.USER, CMOptions.PASSWORD).stream().map(
new Function<Option, Option>() {
@Override
public Option apply(Option o) {
Option c = CMOptions.clone(o);
c.setRequired(false);
return c;
}
}).forEach(o -> opts.addOption(o));
CommandLine parser = new DefaultParser().parse(opts, args, true);
if(parser.getArgs().length == 0) {
throw new CMCommandLineException(format("Canmnot extract command name from arguments: '%s'.",
getArgsLogString(args)));
}
String commandName = parser.getArgs()[0];
logger.debug(format("Command name '%s' extracted from command line '%s'.", commandName, getArgsLogString(args)));
return commandName;
}
示例7: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public final static void main(String[] args) throws Exception {
logger.debug(format("%s called with arguments: '%s'.", GetChangeTransports.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
Options options = new Options();
Commands.Helpers.addStandardParameters(options);
options.addOption(modifiableOnlyOption);
if(helpRequested(args)) {
handleHelpOption(format("%s [SUBCOMMAND_OPTIONS] <changeId>", getCommandName(GetChangeTransports.class)),
"Returns the ids of the transports for the change represented by <changeId>.",
new Options().addOption(modifiableOnlyOption)); return;
}
CommandLine commandLine = new DefaultParser().parse(options, args);
new GetChangeTransports(
getHost(commandLine),
getUser(commandLine),
getPassword(commandLine),
getChangeId(commandLine),
commandLine.hasOption(modifiableOnlyOption.getOpt())).execute();
}
示例8: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public final static void main(String[] args) throws Exception {
logger.debug(format("%s called with arguments: '%s'.", ReleaseTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
Options options = new Options();
Commands.Helpers.addStandardParameters(options);
if(helpRequested(args)) {
handleHelpOption(
format("%s <changeId> <transportId>", getCommandName(ReleaseTransport.class)),
"Releases the transport specified by <changeId>, <transportId>.", new Options()); return;
}
CommandLine commandLine = new DefaultParser().parse(options, args);
new ReleaseTransport(getHost(commandLine),
getUser(commandLine),
getPassword(commandLine),
getChangeId(commandLine),
TransportRelated.getTransportId(commandLine)).execute();
}
示例9: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public final static void main(String[] args) throws Exception {
logger.debug(format("%s called with arguments: '%s'.", UploadFileToTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
Options options = new Options();
Commands.Helpers.addStandardParameters(options);
if(helpRequested(args)) {
handleHelpOption(format("%s <changeId> <transportId> <applicationId> <filePath>", getCommandName(UploadFileToTransport.class)),
"Uploads the file specified by <filePath> to transport <transportId> for change <changeId>. "
+ "<applicationId> specifies how the file needs to be handled on server side.", new Options()); return;
}
CommandLine commandLine = new DefaultParser().parse(options, args);
new UploadFileToTransport(
getHost(commandLine),
getUser(commandLine),
getPassword(commandLine),
getChangeId(commandLine),
getArg(commandLine, 2, "transportId"),
getArg(commandLine, 3, "applicationId"),
getArg(commandLine, 4, "filePath")).execute();
}
示例10: generateCommandLine
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
/**
* "Parsing" stage of command-line processing demonstrated with
* Apache Commons CLI.
*
* @param options Options from "definition" stage.
* @param commandLineArguments Command-line arguments provided to application.
* @return Instance of CommandLine as parsed from the provided Options and
* command line arguments; may be {@code null} if there is an exception
* encountered while attempting to parse the command line options.
*/
private static CommandLine generateCommandLine(
final Options options, final String[] commandLineArguments)
{
final CommandLineParser cmdLineParser = new DefaultParser();
CommandLine commandLine = null;
try
{
commandLine = cmdLineParser.parse(options, commandLineArguments);
}
catch (ParseException parseException)
{
out.println(
"ERROR: Unable to parse command-line arguments "
+ Arrays.toString(commandLineArguments) + " due to: "
+ parseException);
}
return commandLine;
}
示例11: processArguments
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
private void processArguments(String[] args) throws org.apache.commons.cli.ParseException {
Options opts = new Options(); // Setting CLI options
opts.addOption("gui", "Whether to use the GUI or not. ('yes' or 'no')");
opts.addOption("help", "Shows this page");
opts.addOption("license", "Show license info.");
CommandLine cl = new DefaultParser().parse(opts, args); // Parsing
// CLI
// options
if (cl.hasOption("help"))
showHelp();
if (cl.hasOption("license"))
showLicense();
setGui(cl.hasOption("gui"));
}
示例12: main
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
public static void main(String[] args) {
Options options = new Options();
options.addOption("h", true, "Messaging host");
options.addOption("p", true, "Messaging port");
options.addOption("q", true, "Queue");
options.addOption("u", false, "Print this help");
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("u")) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("Sender", options);
} else {
String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
String address = cmd.getOptionValue("q", QUEUE);
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort));
props.put("queue.myDestinationLookup", address);
LOG.info("Starting server : connecting to [{}:{}]", messagingHost, messagingPort);
Server sender = new Server();
sender.run(props);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
示例13: parseForHelp
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
static void parseForHelp(String[] args) {
// parse for help options
try {
Options helpOnly = new Options();
helpOnly.addOption(options.getOption("h"));
CommandLine cli = new DefaultParser().parse(helpOnly, args, true);
// no -h option - do nothing
if (!cli.hasOption("h")) {
return;
}
} catch (ParseException pe) {
System.err.println(pe.getMessage());
System.exit(-1);
}
// print help text
new HelpFormatter().printHelp("java -jar sgc-xxx.jar", "Simple Glacier Client (sgc) | Version: 0.1\n\n", options, "\n"+"See: https://github.com/arjuan/simple-glacier-client"+"\n\n", true);
}
示例14: parseCommandLine
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
private static CommandLine parseCommandLine(String[] args) {
if (args.length < 4) {
printUsageAndExit();
}
Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string");
Option statsTopic = new Option(STATS_TOPIC, true, "kafka topic for broker stats");
options.addOption(zookeeper).addOption(statsTopic);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException | NumberFormatException e) {
printUsageAndExit();
}
return cmd;
}
示例15: parseCommandLine
import org.apache.commons.cli.DefaultParser; //导入依赖的package包/类
private static CommandLine parseCommandLine(String[] args) {
Option host = new Option(BROKER_NAME, true, "kafka broker");
Option jmxPort = new Option(JMX_PORT, true, "kafka jmx port number");
jmxPort.setArgName("kafka jmx port number");
Option metric = new Option(METRICS_NAME, true, "jmx metric name");
options.addOption(jmxPort).addOption(host).addOption(metric);
if (args.length < 4) {
printUsageAndExit();
}
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException | NumberFormatException e) {
printUsageAndExit();
}
return cmd;
}