本文整理汇总了Java中org.apache.commons.cli.CommandLineParser类的典型用法代码示例。如果您正苦于以下问题:Java CommandLineParser类的具体用法?Java CommandLineParser怎么用?Java CommandLineParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandLineParser类属于org.apache.commons.cli包,在下文中一共展示了CommandLineParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
/**
* Main method.
*
* @param args
* @throws IOException
* @throws ParseException
*/
public static void main(String[] args) throws Exception {
java.util.logging.Logger l = java.util.logging.Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler");
l.setLevel(java.util.logging.Level.FINE);
l.setUseParentHandlers(false);
java.util.logging.ConsoleHandler ch = new java.util.logging.ConsoleHandler();
ch.setLevel(java.util.logging.Level.ALL);
l.addHandler(ch);
CommandLineParser parser = new GnuParser();
Options options = new Options();
options.addOption("h", "host", true, "Server hostname.");
options.addOption("p", "port", true, "TCP port to listen.");
options.addOption("s", "storage_path", true, "Storage path.");
options.addOption("w", "wat_gcube_token", true, "WAT gcube authentication token");
CommandLine line = parser.parse(options, args);
String serverUri = String.format("http://%s:%d/smaph", line.getOptionValue("host", "localhost"),
Integer.parseInt(line.getOptionValue("port", "8080")));
Path storage = Paths.get(line.getOptionValue("storage_path"));
startServer(serverUri, storage, line.getOptionValue("wat_gcube_token"));
}
示例2: parseCommandLine
import org.apache.commons.cli.CommandLineParser; //导入依赖的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;
}
示例3: main
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
public static void main(String[] args) throws ParseException {
Options options = new Options();
Option nameOption = new Option("n", true, "Name to resolve");
nameOption.setRequired(true);
options.addOption(nameOption);
CommandLineParser parser = new BasicParser();
CommandLine cmd = parser.parse(options, args);
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.DEBUG);
PodCIDRToNodeMapping plugin = new PodCIDRToNodeMapping();
Configuration conf = new Configuration();
plugin.setConf(conf);
String nameToResolve = cmd.getOptionValue(nameOption.getOpt());
List<String> networkPathDirs = plugin.resolve(Lists.newArrayList(nameToResolve));
log.info("Resolved " + nameToResolve + " to " + networkPathDirs);
}
示例4: MyOptions
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
public MyOptions(String[] args) {
seed = System.nanoTime();
try {
Options opts = buildOptions();
CommandLineParser parser = new GnuParser();
CommandLine line = parser.parse(opts, args, true);
processOptions(line, opts);
validateOptions();
}
catch (ParseException e) {
System.out.println(e.getMessage());
System.out.println("Try \"--help\" option for details.");
setStopProceed();
}
}
示例5: main
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
public static void main(String[] args) {
CommandLineParser parser = new DefaultParser();
try {
Options options = getOptions();
CommandLine line = parser.parse(options, args );
if (line.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
System.out.println(Constants.PROJECT_NAME + ", " + Constants.PROJECT_URL);
formatter.printHelp(Constants.PROJECT_NAME, options, true);
} else if (line.hasOption("version")) {
System.out.println("version: " + Constants.VERSION);
} else {
logger.info("Starting pm-home-station ({} v.{})...", Constants.PROJECT_URL, Constants.VERSION);
setLookAndFeel();
PlanTowerSensor planTowerSensor = new PlanTowerSensor();
Station station = new Station(planTowerSensor);
SwingUtilities.invokeLater(() -> { station.showUI(); });
}
} catch (ParseException e) {
logger.error("Ooops", e);
return;
}
}
示例6: parseCommandLine
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
/**
* Usage: BrokerStatsRetriever \
* --brokerstatszk datazk001:2181/data07 \
* --brokerstatstopic brokerstats \
* --broker kafkabroker001
*/
private static CommandLine parseCommandLine(String[] args) {
Option config = new Option(CONFIG, true, "operator config");
Option brokerStatsZookeeper =
new Option(BROKERSTATS_ZOOKEEPER, true, "zookeeper for brokerstats topic");
Option brokerStatsTopic = new Option(BROKERSTATS_TOPIC, true, "topic for brokerstats");
Option broker = new Option(BROKERNAME, true, "broker name");
options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic)
.addOption(broker);
if (args.length < 6) {
printUsageAndExit();
}
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException | NumberFormatException e) {
printUsageAndExit();
}
return cmd;
}
示例7: parse
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
public void parse() {
CommandLineParser parser = new BasicParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args, true);
if (cmd.hasOption("h")) {
help();
} else if (cmd.hasOption("o")) {
open();
} else if (!cmd.hasOption("g")) {
log.log(Level.SEVERE, "Missing g option");
help();
}
} catch (ParseException e) {
help();
}
}
示例8: parseCommandLine
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
/**
* Usage: OperatorActionRetriever \
* -zookeeper datazk001:2181/data07 \
* -topic operator_report -num_messages 1000
*/
private static CommandLine parseCommandLine(String[] args) {
Option zookeeper = new Option(ZOOKEEPER, true, "doctorkafka action zookeeper");
Option topic = new Option(TOPIC, true, "doctorkafka action topic");
Option num_messages = new Option(NUM_MESSAGES, true, "num of messages to retrieve");
options.addOption(zookeeper).addOption(topic).addOption(num_messages);
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;
}
示例9: parseCommandLine
import org.apache.commons.cli.CommandLineParser; //导入依赖的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;
}
示例10: testParse
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
@Test
public void testParse() throws Exception {
final CommandLineParser parser = new PosixParser();
final CommandLine input = parser.parse(new Options(), new String[]{});
final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Arrays.asList(new FTPTLSProtocol() {
@Override
public boolean isEnabled() {
return true;
}
}, new S3Protocol() {
@Override
public boolean isEnabled() {
return true;
}
})));
assertTrue(new Host(new S3Protocol(), "s3.amazonaws.com", 443, "/cyberduck-test/key", new Credentials("AWS456", null))
.compareTo(new CommandLineUriParser(input, factory).parse("s3://[email protected]/key")) == 0);
assertTrue(new Host(new FTPTLSProtocol(), "cyberduck.io", 55, "/folder", new Credentials("anonymous", null))
.compareTo(new CommandLineUriParser(input, factory).parse("ftps://cyberduck.io:55/folder")) == 0);
}
示例11: testProfile
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
@Test
public void testProfile() throws Exception {
final CommandLineParser parser = new PosixParser();
final CommandLine input = parser.parse(new Options(), new String[]{});
final Set<Protocol> list = new HashSet<>(Arrays.asList(
new SwiftProtocol(),
new ProfilePlistReader(new ProtocolFactory(Collections.singleton(new SwiftProtocol() {
@Override
public boolean isEnabled() {
return true;
}
})))
.read(new Local("../profiles/default/Rackspace US.cyberduckprofile"))
));
assertTrue(new Host(new ProtocolFactory(list).forName("rackspace"), "identity.api.rackspacecloud.com", 443, "/cdn.cyberduck.ch/", new Credentials("u", null))
.compareTo(new CommandLineUriParser(input, new ProtocolFactory(list)).parse("rackspace://[email protected]/")) == 0);
}
示例12: testFilter
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
@Test
public void testFilter() throws Exception {
final CommandLineParser parser = new PosixParser();
final Transfer transfer = new TerminalTransferFactory().create(parser.parse(TerminalOptionsBuilder.options(), new String[]{"--download", "rackspace://cdn.cyberduck.ch/remote/*.css"}),
new Host(new SwiftProtocol()), new Path("/remote/*.css", EnumSet.of(Path.Type.directory)), Collections.<TransferItem>emptyList());
assertEquals(Transfer.Type.download, transfer.getType());
final PathCache cache = new PathCache(1);
transfer.withCache(cache);
cache.clear();
cache.put(new Path("/remote", EnumSet.of(Path.Type.directory)), new AttributedList<Path>(Collections.singletonList(new Path("/remote/file.css", EnumSet.of(Path.Type.file)))));
assertFalse(transfer.list(null, null, new Path("/remote", EnumSet.of(Path.Type.directory)), new Local("/tmp"), new DisabledListProgressListener()).isEmpty());
cache.clear();
cache.put(new Path("/remote", EnumSet.of(Path.Type.directory)), new AttributedList<Path>(Collections.singletonList(new Path("/remote/file.png", EnumSet.of(Path.Type.file)))));
assertTrue(transfer.list(null, null, new Path("/remote", EnumSet.of(Path.Type.directory)), new Local("/tmp"), new DisabledListProgressListener()).isEmpty());
}
示例13: testParseProfile
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
@Test
public void testParseProfile() throws Exception {
final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new SwiftProtocol() {
@Override
public boolean isEnabled() {
return true;
}
})));
final ProfilePlistReader reader = new ProfilePlistReader(factory, new DeserializerFactory(PlistDeserializer.class.getName()));
final Profile profile = reader.read(
new Local("../profiles/default/Rackspace US.cyberduckprofile")
);
assertNotNull(profile);
final CommandLineParser parser = new PosixParser();
final CommandLine input = parser.parse(new Options(), new String[]{});
assertEquals(new Path("/cdn.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)),
new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))).parse("rackspace://[email protected]/"));
assertEquals(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)),
new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))).parse("rackspace:///"));
}
示例14: generateCommandLine
import org.apache.commons.cli.CommandLineParser; //导入依赖的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;
}
示例15: parseCommandLine
import org.apache.commons.cli.CommandLineParser; //导入依赖的package包/类
/**
* Usage: KafkaWriter \
* --zookeeper zookeeper001:2181/cluster1 --topic kafka_test \
* --message "this is a test message"
*/
private static CommandLine parseCommandLine(String[] args) {
Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string");
Option topic = new Option(TOPIC, true, "action report topic name");
Option message = new Option(MESSAGE, true, "messags that writes to kafka");
options.addOption(zookeeper).addOption(topic).addOption(message);
if (args.length < 6) {
printUsageAndExit();
}
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException | NumberFormatException e) {
printUsageAndExit();
}
return cmd;
}