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


Java Parser.parse方法代码示例

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


在下文中一共展示了Parser.parse方法的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: run

import org.apache.commons.cli.Parser; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {
	CommandLineParser cli = new CommandLineParser();
	if (args.length == 0) {
		cli.printUsage();
		return 1;
	}
	
	cli.addOption("input", false, "input path to the maps", "path");
	cli.addOption("output", false, "output path from the reduces", "path");
	
	cli.addOption("cpubin", false, "URI to application cpu executable", "class");
	cli.addOption("gpubin", false, "URI to application gpu executable", "class");
	
	Parser parser = cli.createParser();
	try {
		GenericOptionsParser genericParser = new GenericOptionsParser(getConf(), args);
		CommandLine results = 
			parser.parse(cli.options, genericParser.getRemainingArgs());
		JobConf job = new JobConf(getConf());
		
		if (results.hasOption("input")) {
			FileInputFormat.setInputPaths(job, (String) results.getOptionValue("input"));
		}
        if (results.hasOption("output")) {
        	FileOutputFormat.setOutputPath(job, new Path((String) results.getOptionValue("output")));
        }
        if (results.hasOption("cpubin")) {
        	setCPUExecutable(job, (String) results.getOptionValue("cpubin"));
        }
        if (results.hasOption("gpubin")) {
        	setGPUExecutable(job, (String) results.getOptionValue("gpubin"));
        }
        // if they gave us a jar file, include it into the class path
        String jarFile = job.getJar();
        if (jarFile != null) {
        	final URL[] urls = new URL[] { FileSystem.getLocal(job).
        			pathToFile(new Path(jarFile)).toURL() };
            //FindBugs complains that creating a URLClassLoader should be
            //in a doPrivileged() block. 
            ClassLoader loader =
                AccessController.doPrivileged(
                    new PrivilegedAction<ClassLoader>() {
                      public ClassLoader run() {
                        return new URLClassLoader(urls);
                      }
                    }
                  );
              job.setClassLoader(loader);
        }
        runJob(job);
        return 0;
	} catch (ParseException pe) {
		LOG.info("Error :" + pe);
		cli.printUsage();
		return 1;
	}
}
 
开发者ID:koichi626,项目名称:hadoop-gpu,代码行数:59,代码来源:SubmitterToAccels.java

示例14: parse

import org.apache.commons.cli.Parser; //导入方法依赖的package包/类
/**
 * Return a commandLine object by specifies {@link Parser},{@link Options},
 * <code>arguments</code>,<code>stopAtNonOption</code>
 * 
 * @param parser
 *            see abstract {@link Parser},and interface
 *            {@link CommandLineParser}
 * @param options
 *            the <code>Options</code>
 * @param arguments
 *            the <code>arguments</code>
 * @param stopAtNonOption
 *            specifies whether to stop interpreting the arguments when a
 *            non option has been encountered and to add them to the
 *            CommandLines args list.
 * @return the <code>CommandLine</code>
 * @throws ParseException
 *             ParseException if an error occurs when parsing the arguments.
 */
public static CommandLine parse(Parser parser, Options options,
		String[] arguments, boolean stopAtNonOption) throws ParseException {

	CommandLine line = parser.parse(options, arguments, stopAtNonOption);
	return line;
}
 
开发者ID:rockagen,项目名称:commons-lib,代码行数:26,代码来源:CmdUtil.java


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