当前位置: 首页>>代码示例>>Java>>正文


Java Parser类代码示例

本文整理汇总了Java中org.apache.commons.cli.Parser的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Parser类属于org.apache.commons.cli包,在下文中一共展示了Parser类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.apache.commons.cli.Parser; //导入依赖的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;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:18,代码来源:AddAuthCommand.java

示例2: parse

import org.apache.commons.cli.Parser; //导入依赖的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;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:DeleteAllCommand.java

示例3: test31148

import org.apache.commons.cli.Parser; //导入依赖的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'));
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:19,代码来源:BugsTest.java

示例4: handleHelp

import org.apache.commons.cli.Parser; //导入依赖的package包/类
private String[] handleHelp(String[] args, Options fullOptions) {
	Options options = new Options();
	options.addOption(fullOptions.getOption("help"));
	Parser p = new PosixParser();
	try {
		CommandLine line = p.parse(options, args, true);
		if (line.hasOption('?')) {
			showHelpAndExit(fullOptions, 0);
			new HelpFormatter().printHelp(getCommandLineSyntax(), fullOptions);
			System.exit(0);
		}
		return line.getArgs();
	} catch (ParseException e) {
		// ignore
	}
	return args;
}
 
开发者ID:conversant,项目名称:mara,代码行数:18,代码来源:ToolContext.java

示例5: parse

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    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;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:16,代码来源:GetAclCommand.java

示例6: parse

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    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;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:15,代码来源:RemoveWatchesCommand.java

示例7: parse

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws ParseException {
    Parser parser = new PosixParser();
    cl = parser.parse(options, cmdArgs);
    args = cl.getArgs();
    if (args.length < 2) {
        throw new ParseException(getUsageStr());
    }

    return this;
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:12,代码来源:GetAclCommand.java

示例8: parse

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws ParseException {
    Parser parser = new PosixParser();
    CommandLine cl = parser.parse(options, cmdArgs);
    args = cl.getArgs();
    if (args.length < 2) {
        throw new ParseException(getUsageStr());
    }

    return this;
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:12,代码来源:AddAuthCommand.java

示例9: parse

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws ParseException {
    Parser parser = new PosixParser();
    cl = parser.parse(options, cmdArgs);
    args = cl.getArgs();
    if (args.length < 2) {
        throw new ParseException(getUsageStr());
    }
    return this;
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:11,代码来源:RemoveWatchesCommand.java

示例10: test13425

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Test
public void test13425() throws Exception
{
    Options options = new Options();
    Option oldpass = OptionBuilder.withLongOpt( "old-password" )
        .withDescription( "Use this option to specify the old password" )
        .hasArg()
        .create( 'o' );
    Option newpass = OptionBuilder.withLongOpt( "new-password" )
        .withDescription( "Use this option to specify the new password" )
        .hasArg()
        .create( 'n' );

    String[] args = { 
        "-o", 
        "-n", 
        "newpassword" 
    };

    options.addOption( oldpass );
    options.addOption( newpass );

    Parser parser = new PosixParser();

    try {
        parser.parse( options, args );
        fail( "MissingArgumentException not caught." );
    } catch( MissingArgumentException expected ) {
    }
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:31,代码来源:BugsTest.java

示例11: getConfigOverrides

import org.apache.commons.cli.Parser; //导入依赖的package包/类
/**
 * Re-parse our options using the properties from the specified conf file.
 * @param properties		the command line override properties
 * @param args				command line arguments
 * @return					any left-over command line arguments
 * 			that haven't been parsed. This method sets up and parses
 * 			only the option file argument, so the return would be everything
 * 			from the command line args except the --file if provided.
 * @throws ParseException	if unable to parse the command line options
 * @throws IOException		if unable to read the file
 */
@SuppressWarnings("static-access")
protected String[] getConfigOverrides(Properties properties, String[] args) throws ParseException, IOException {
	// Parse with our config option only...
	Options options = new Options();
	options.addOption(
			OptionBuilder.withLongOpt(OPTION_OPTIONS_FILE)
			.withDescription("Configuration file of key/value pairs with option overrides.")
			.withArgName("file")
			.hasArg()
			.create());

	Parser parser = new IgnoreUnknownParser();
	CommandLine line = parser.parse(options, args, true);
	if (line.hasOption(OPTION_OPTIONS_FILE)) {
		File confFile = new File(line.getOptionValue(OPTION_OPTIONS_FILE));
		if (!confFile.exists()) {
			throw new IllegalArgumentException("Configuration file not found.");
		}
		Reader reader = null;
		try {
			reader = new FileReader(confFile);
			properties.load(reader);
		}
		finally {
			IOUtils.closeQuietly(reader);
		}
	}

	return line.getArgs();
}
 
开发者ID:conversant,项目名称:mara,代码行数:42,代码来源:ToolContext.java

示例12: parseFromArgs

import org.apache.commons.cli.Parser; //导入依赖的package包/类
/**
 * Parse the arguments.
 * 
 * @param args				the command line arguments
 * @throws Exception		if the process fails
 * @throws ParseException	if the command line parsing fails
 */
protected void parseFromArgs(String[] args) throws Exception {
	Options options = initOptions();

	// Notify our listener if there is one...
	if (this.contextListener != null) {
		this.contextListener.afterInitOptions(options);
	}

	try {
		args = handleHelp(args, options);

		Properties props = new Properties();
		args = getConfigOverrides(props, args);

		// Now parse the rest of 'em
		Parser parser = new PosixParserRequiredProps();
		CommandLine line = null;
		line = parser.parse(options, args, props, false);

		// Populate our context values from the parsed command line
		populateContext(line);

		// Notify our listener if there is one...
		if (this.contextListener != null) {
			this.contextListener.afterParseCommandLine(line);
		}
	}
	catch (ParseException e) {
		showHelpAndExit(options, 1, e.getMessage());
	}
}
 
开发者ID:conversant,项目名称:mara,代码行数:39,代码来源:ToolContext.java

示例13: testCLI_insufficientArg

import org.apache.commons.cli.Parser; //导入依赖的package包/类
@Test(expected=ParseException.class)
public void testCLI_insufficientArg() throws ParseException {
  UnitTestHelper.setLog4jLevel(Parser.class, Level.FATAL);
  CommandLine cli = new CLIBuilder().with(ParserTopologyCLI.ParserOptions.BROKER_URL, "mybroker")
                                    .with(ParserTopologyCLI.ParserOptions.ZK_QUORUM, "myzk")
                                    .build(true);
  UnitTestHelper.setLog4jLevel(Parser.class, Level.ERROR);
}
 
开发者ID:apache,项目名称:metron,代码行数:9,代码来源:ParserTopologyCLITest.java

示例14: createParser

import org.apache.commons.cli.Parser; //导入依赖的package包/类
Parser createParser() {
  Parser result = new BasicParser();
  return result;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:5,代码来源:Submitter.java


注:本文中的org.apache.commons.cli.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。