本文整理汇总了Java中org.apache.commons.cli.PosixParser类的典型用法代码示例。如果您正苦于以下问题:Java PosixParser类的具体用法?Java PosixParser怎么用?Java PosixParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PosixParser类属于org.apache.commons.cli包,在下文中一共展示了PosixParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExecute
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
@Test
public void testExecute() {
UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
Options options = ServerUtil.buildCommandlineOptions(new Options());
String[] subargs = new String[] {
"-b 127.0.0.1:10911",
"-c default-cluster",
"-t unit-test",
"-r 8",
"-w 8",
"-p 6",
"-o false",
"-u false",
"-s false"};
final CommandLine commandLine =
ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster");
assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:27,代码来源:UpdateTopicSubCommandTest.java
示例2: testParse
import org.apache.commons.cli.PosixParser; //导入依赖的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);
}
示例3: testProfile
import org.apache.commons.cli.PosixParser; //导入依赖的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);
}
示例4: testFilter
import org.apache.commons.cli.PosixParser; //导入依赖的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());
}
示例5: testParseProfile
import org.apache.commons.cli.PosixParser; //导入依赖的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:///"));
}
示例6: parse
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
Parser parser = new PosixParser();
CommandLine cl;
try {
cl = parser.parse(options, cmdArgs);
} catch (ParseException ex) {
throw new CliParseException(ex);
}
args = cl.getArgs();
if (args.length < 2) {
throw new CliParseException(getUsageStr());
}
return this;
}
示例7: parse
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
Parser parser = new PosixParser();
CommandLine cl;
try {
cl = parser.parse(options, cmdArgs);
} catch (ParseException ex) {
throw new CliParseException(ex);
}
args = cl.getArgs();
if (args.length < 2) {
throw new CliParseException(getUsageStr());
}
return this;
}
示例8: parseHelpArgument
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
/**
* Parse the arguments for commands
*
* @param args the argument to be parsed
* @param helpDescription help information to be printed out
* @param out Printer
* @param printGenericCommandUsage whether to print the
* generic command usage defined in ToolRunner
* @return true when the argument matches help option, false if not
*/
public static boolean parseHelpArgument(String[] args,
String helpDescription, PrintStream out, boolean printGenericCommandUsage) {
if (args.length == 1) {
try {
CommandLineParser parser = new PosixParser();
CommandLine cmdLine = parser.parse(helpOptions, args);
if (cmdLine.hasOption(helpOpt.getOpt())
|| cmdLine.hasOption(helpOpt.getLongOpt())) {
// should print out the help information
out.println(helpDescription + "\n");
if (printGenericCommandUsage) {
ToolRunner.printGenericCommandUsage(out);
}
return true;
}
} catch (ParseException pe) {
return false;
}
}
return false;
}
示例9: main
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
public static void main(String[] args) throws ParseException {
CommandLineParser parser = new PosixParser();
Options options = createOptions();
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption(CMD_HELP)) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("NutchServer", options, true);
return;
}
if (commandLine.hasOption(CMD_PORT)) {
port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));
}
if (commandLine.hasOption(CMD_HOST)) {
host = commandLine.getOptionValue(CMD_HOST);
}
startServer();
}
示例10: setFromCommandLineArgs
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
public static void setFromCommandLineArgs(Options options, String[] args) {
CommandLineParser parser = new PosixParser();
try {
CommandLine cl = parser.parse(options, args);
// 参数默认值
THE_INSTANCE.windowLength = new Duration(
Integer.parseInt(cl.getOptionValue(AppMain.WINDOW_LENGTH, "30")) * 1000);
THE_INSTANCE.slideInterval = new Duration(
Integer.parseInt(cl.getOptionValue(AppMain.SLIDE_INTERVAL, "5")) * 1000);
THE_INSTANCE.kafka_broker = cl.getOptionValue(AppMain.KAFKA_BROKER, "kafka:9092");
THE_INSTANCE.kafka_topic = cl.getOptionValue(AppMain.KAFKA_TOPIC, "apache");
THE_INSTANCE.parquet_file = cl.getOptionValue(AppMain.PARQUET_FILE, "/user/spark/");
THE_INSTANCE.initialized = true;
} catch (ParseException e) {
THE_INSTANCE.initialized = false;
System.err.println("Parsing failed. Reason: " + e.getMessage());
}
}
示例11: main
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Options options = getOptions();
try {
CommandLineParser parser = new PosixParser();
GenericOptionsParser hadoopCmd = new GenericOptionsParser(args);
CommandLine cmd = parser.parse(options, hadoopCmd.getRemainingArgs());
if (cmd.getArgs().length < 2 || cmd.getArgs().length > 3 || cmd.hasOption('h')) {
printMan(options);
} else if (!cmd.hasOption('k')) {
System.err.println("-k parameter is mandatory");
System.exit(1);
} else if (cmd.hasOption('g')) {
hadoop(args);
} else {
standalone(cmd);
}
} catch (ParseException e) {
printMan(options);
}
}
示例12: testCLI13
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
@Test
public void testCLI13() throws ParseException
{
final String debugOpt = "debug";
@SuppressWarnings("static-access")
Option debug = OptionBuilder
.withArgName( debugOpt )
.withDescription( "turn on debugging" )
.withLongOpt( debugOpt )
.hasArg()
.create( 'd' );
Options options = new Options();
options.addOption( debug );
CommandLine commandLine = new PosixParser().parse( options, new String[]{"-d", "true"} );
assertEquals("true", commandLine.getOptionValue( debugOpt ));
assertEquals("true", commandLine.getOptionValue( 'd' ));
assertTrue(commandLine.hasOption( 'd'));
assertTrue(commandLine.hasOption( debugOpt));
}
示例13: test15046
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
@Test
public void test15046() throws Exception
{
CommandLineParser parser = new PosixParser();
String[] CLI_ARGS = new String[] {"-z", "c"};
Options options = new Options();
options.addOption(new Option("z", "timezone", true, "affected option"));
parser.parse(options, CLI_ARGS);
//now add conflicting option
options.addOption("c", "conflict", true, "conflict option");
CommandLine line = parser.parse(options, CLI_ARGS);
assertEquals( line.getOptionValue('z'), "c" );
assertTrue( !line.hasOption("c") );
}
示例14: test31148
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
@Test
public void test31148() throws ParseException
{
Option multiArgOption = new Option("o","option with multiple args");
multiArgOption.setArgs(1);
Options options = new Options();
options.addOption(multiArgOption);
Parser parser = new PosixParser();
String[] args = new String[]{};
Properties props = new Properties();
props.setProperty("o","ovalue");
CommandLine cl = parser.parse(options,args,props);
assertTrue(cl.hasOption('o'));
assertEquals("ovalue",cl.getOptionValue('o'));
}
示例15: main
import org.apache.commons.cli.PosixParser; //导入依赖的package包/类
public static void main(String[] args) {
// startup checks and logging
EnvironmentInformation.logEnvironmentInfo(LOG, MesosSessionClusterEntrypoint.class.getSimpleName(), args);
SignalHandler.register(LOG);
JvmShutdownSafeguard.installAsShutdownHook(LOG);
// load configuration incl. dynamic properties
CommandLineParser parser = new PosixParser();
CommandLine cmd;
try {
cmd = parser.parse(ALL_OPTIONS, args);
}
catch (Exception e){
LOG.error("Could not parse the command-line options.", e);
System.exit(STARTUP_FAILURE_RETURN_CODE);
return;
}
Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd);
Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG);
MesosSessionClusterEntrypoint clusterEntrypoint = new MesosSessionClusterEntrypoint(configuration, dynamicProperties);
clusterEntrypoint.startCluster();
}