本文整理匯總了Java中org.apache.commons.cli.Option類的典型用法代碼示例。如果您正苦於以下問題:Java Option類的具體用法?Java Option怎麽用?Java Option使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Option類屬於org.apache.commons.cli包,在下文中一共展示了Option類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildCommandlineOptions
import org.apache.commons.cli.Option; //導入依賴的package包/類
@Override
public Options buildCommandlineOptions(Options options) {
Option opt = new Option("g", "groupName", true, "consumer group name");
opt.setRequired(false);
options.addOption(opt);
return options;
}
示例2: main
import org.apache.commons.cli.Option; //導入依賴的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);
}
示例3: initCli
import org.apache.commons.cli.Option; //導入依賴的package包/類
/**
* Initialize the command line interface.
*/
private static void initCli() {
options = new Options();
options.addOption("b", BYGONE, false, "Signals a historical conversion");
options.addOption("v", SKIP_VALIDATION, false, "Skip validations");
options.addOption("d", SKIP_DEFAULTS, false,"Skip defaulted transformations");
options.addOption("h", HELP, false,"This help message");
Option templateScope = Option.builder("t")
.longOpt(TEMPLATE_SCOPE)
.argName("scope1,scope2,...")
.hasArg()
.desc("Comma delimited scope values to use for context. Valid values: "
+ Arrays.toString(QrdaScope.getNames()))
.build();
options.addOption(templateScope);
formatter = new HelpFormatter();
}
示例4: getOptions
import org.apache.commons.cli.Option; //導入依賴的package包/類
private static Options getOptions() {
Options options = new Options();
options.addOption("b", "bind", true,
"Address to bind the Thrift server to. [default: 0.0.0.0]");
options.addOption("p", "port", true, "Port to bind to [default: " + DEFAULT_LISTEN_PORT + "]");
options.addOption("f", "framed", false, "Use framed transport");
options.addOption("c", "compact", false, "Use the compact protocol");
options.addOption("w", "workers", true, "How many worker threads to use.");
options.addOption("h", "help", false, "Print help information");
options.addOption(null, "infoport", true, "Port for web UI");
options.addOption("t", READ_TIMEOUT_OPTION, true,
"Amount of time in milliseconds before a server thread will timeout " +
"waiting for client to send data on a connected socket. Currently, " +
"only applies to TBoundedThreadPoolServer");
OptionGroup servers = new OptionGroup();
servers.addOption(
new Option("nonblocking", false, "Use the TNonblockingServer. This implies the framed transport."));
servers.addOption(new Option("hsha", false, "Use the THsHaServer. This implies the framed transport."));
servers.addOption(new Option("threadpool", false, "Use the TThreadPoolServer. This is the default."));
options.addOptionGroup(servers);
return options;
}
示例5: buildOptions
import org.apache.commons.cli.Option; //導入依賴的package包/類
public static Options buildOptions() {
Options options = new Options();
optionLCI.setArgs(1);
optionLCI.setArgs(1);
optionUCI.setArgs(1);
optionUCO.setArgs(1);
optionK.setArgs(Option.UNLIMITED_VALUES);
optionK.setRequired(true);
options.addOption(optionLCI);
options.addOption(optionLCO);
options.addOption(optionUCI);
options.addOption(optionUCO);
options.addOption(optionD);
options.addOption(optionR);
options.addOption(optionK);
options.addOption(optionS);
return options;
}
示例6: createOption
import org.apache.commons.cli.Option; //導入依賴的package包/類
/**
* Small helper for creating some of the long parameter settings we frequently
* use here.
*
* @param optName name of the parameter/option
* @param description description for the help text
* @param isRequired whether this parameter is strictly required
* @param unlimitedArgs whether it supports multiple arguments, default is on argument
*/
public static Option createOption(String optName, String description,
boolean isRequired, boolean unlimitedArgs) {
Option.Builder builder = Option.builder()
.longOpt(optName)
.hasArg()
.valueSeparator(',')
.required(isRequired)
.desc(description);
if (unlimitedArgs) {
builder.hasArgs();
}
return builder.build();
}
示例7: parseCommandLine
import org.apache.commons.cli.Option; //導入依賴的package包/類
/**
* Usage: ReplicaStatsRetriever \
* -brokerstatszk datazk001:2181/data07 \
* -brokerstatstopic brokerstats \
* -clusterzk m10nzk001:2181,...,m10nzk007:2181/m10n07 \
* -seconds 43200
*/
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 clusterZookeeper = new Option(CLUSTER_ZOOKEEPER, true, "cluster zookeeper");
Option seconds = new Option(SECONDS, true, "examined time window in seconds");
options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic)
.addOption(clusterZookeeper).addOption(seconds);
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;
}
示例8: parseCommandLine
import org.apache.commons.cli.Option; //導入依賴的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;
}
示例9: parseCommandLine
import org.apache.commons.cli.Option; //導入依賴的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: commandLine2Properties
import org.apache.commons.cli.Option; //導入依賴的package包/類
public static Properties commandLine2Properties(final CommandLine commandLine) {
Properties properties = new Properties();
Option[] opts = commandLine.getOptions();
if (opts != null) {
for (Option opt : opts) {
String name = opt.getLongOpt();
String value = commandLine.getOptionValue(name);
if (value != null) {
properties.setProperty(name, value);
}
}
}
return properties;
}
示例11: buildCommandlineOptions
import org.apache.commons.cli.Option; //導入依賴的package包/類
@Override
public Options buildCommandlineOptions(Options options) {
Option opt = new Option("b", "brokerName", true, "broker name");
opt.setRequired(true);
options.addOption(opt);
return options;
}
示例12: createOptions
import org.apache.commons.cli.Option; //導入依賴的package包/類
/**
* Create the CLI Options
*
* @return the CLI Options
* @throws IllegalArgumentException
*/
private static Options createOptions() throws IllegalArgumentException {
Options options = new Options();
// add an option
options.addOption("help", false, "print this message");
options.addOption("start", false, "start the SQL Web server");
options.addOption("stop", false, "stop the SQL Web server");
options.addOption("version", false, "print version");
String propertiesOptionMesssage = getPropertiesOptionMessage();
@SuppressWarnings("static-access")
Option propertiesOption = OptionBuilder.withArgName("file").hasArg().withDescription(propertiesOptionMesssage)
.create("properties");
@SuppressWarnings("static-access")
Option hostOption = OptionBuilder.withArgName("hostname").hasArg().withDescription("hostname of the Web server")
.create("host");
@SuppressWarnings("static-access")
Option portOption = OptionBuilder.withArgName("port number").hasArg()
.withDescription("port number of the Web server. Defaults to " + WebServerApi.DEFAULT_PORT)
.create("port");
options.addOption(propertiesOption);
options.addOption(hostOption);
options.addOption(portOption);
return options;
}
示例13: constructPosixOptions
import org.apache.commons.cli.Option; //導入依賴的package包/類
/**
* Construct and provide Posix-compatible Options.
*
* @return Options expected from command-line of Posix form.
*/
private static Options constructPosixOptions() {
final Options posixOptions = new Options();
posixOptions.addOption(
Option.builder(VERBOSE_OPTION).desc("Enable verbose mode").hasArg(false).required(false).build());
posixOptions.addOption(
Option.builder(PASSWORD_OPTION).desc("User defined password").hasArg(true).required(false).build());
posixOptions.addOption(Option.builder(CIPHERED_FILE_OPTION)
.desc("Input ciphered file (or directory) to decipher").hasArg(true).required(true).build());
posixOptions.addOption(Option.builder(PLAIN_FILE_OPTION).desc("Output plain file (or directory)").hasArg(true)
.required(true).build());
posixOptions.addOption(
Option.builder(RECURSIVE_OPTION).desc("Enable recursive mode (WARNING : MAY TAKE A LONG TIME !)")
.hasArg(false).required(false).build());
return posixOptions;
}
示例14: getCommandName
import org.apache.commons.cli.Option; //導入依賴的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;
}
示例15: printPrelude
import org.apache.commons.cli.Option; //導入依賴的package包/類
public void printPrelude(Option task) {
String applicationName = Settings.getString(SettingCodes.APPLICATION_NAME, Bundle.SETTINGS, null);
String applicationVersion = Settings.getString(SettingCodes.APPLICATION_VERSION, Bundle.SETTINGS, null);
String instanceName = Settings.getInstanceName();
if (!CommonUtil.isEmptyString(applicationName)) {
println(applicationName);
}
if (!CommonUtil.isEmptyString(applicationVersion)) {
println("version: " + applicationVersion);
}
if (!CommonUtil.isEmptyString(instanceName)) {
println("instance: " + instanceName);
}
println("jvm: " + System.getProperty("java.version"));
if (task != null && !CommonUtil.isEmptyString(task.getDescription())) {
println(task.getDescription());
}
}