本文整理汇总了Java中org.apache.commons.cli.DefaultParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultParser.parse方法的具体用法?Java DefaultParser.parse怎么用?Java DefaultParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.cli.DefaultParser
的用法示例。
在下文中一共展示了DefaultParser.parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.commons.cli.DefaultParser; //导入方法依赖的package包/类
public static Map<String,String> parse(String[] argc) {
OPTIONS.addOption(HELP_OPTION);
OPTIONS.addOption(INPUT_FILE_OPTION);
OPTIONS.addOption(OUTPUT_DIR_OPTION);
Map<String,String> args = new HashMap<>();
DefaultParser parser = new DefaultParser();
CommandLine line = null;
try {
line = parser.parse(OPTIONS, argc);
} catch (ParseException e) {
e.printStackTrace();
System.exit(1);
}
if (line.hasOption(HELP_OPTION.getLongOpt()))
printUsage(OPTIONS);
if (!line.hasOption(INPUT_FILE_OPTION.getLongOpt())) {
System.err.println("You must supply -i");
printUsage(OPTIONS);
System.exit(1);
}
if (!line.hasOption(OUTPUT_DIR_OPTION.getLongOpt())) {
System.err.println("You must supply -o");
printUsage(OPTIONS);
System.exit(1);
}
args.put(INPUT_FILE, line.getOptionValue(INPUT_FILE_OPTION.getLongOpt()));
args.put(OUTPUT_DIR, line.getOptionValue(OUTPUT_DIR_OPTION.getLongOpt()));
return args;
}
示例2: parseRunCommand
import org.apache.commons.cli.DefaultParser; //导入方法依赖的package包/类
public static RunOptions parseRunCommand(String[] args) throws CliArgsException {
try {
DefaultParser parser = new DefaultParser();
CommandLine line = parser.parse(RUN_OPTIONS, args, true);
return new RunOptions(line);
}
catch (ParseException e) {
throw new CliArgsException(e.getMessage());
}
}
示例3: parse
import org.apache.commons.cli.DefaultParser; //导入方法依赖的package包/类
public static CommandLine parse(Options options, String[] args, boolean stopAtNonOptions) throws CliArgsException {
final DefaultParser parser = new DefaultParser();
try {
return parser.parse(options, args, stopAtNonOptions);
} catch (ParseException e) {
throw new CliArgsException(e.getMessage());
}
}
示例4: parseArguments
import org.apache.commons.cli.DefaultParser; //导入方法依赖的package包/类
public static CommandLine parseArguments(String[] args) throws ParseException {
DefaultParser commandLineParser = new DefaultParser();
CommandLine cl = commandLineParser.parse(getCMDOptions(), args);
/*Process Options*/
//print help menu
if (cl.hasOption('h')) {
CMDConfigurations.displayHelp();
}
return cl;
}
示例5: compile
import org.apache.commons.cli.DefaultParser; //导入方法依赖的package包/类
public boolean compile(String[] args) throws ParseException, IOException {
DefaultParser parser = new DefaultParser();
CommandLine cli = parser.parse(OPTIONS, args);
if (args.length == 0 || cli.hasOption("h")) {
printUsage();
return false;
}
if(cli.hasOption("gui")){
kalang.gui.Editor.main(args);
return true;
}else if(cli.hasOption("run")){
return run(cli);
}else{
JointFileSystemCompiler fsc = new JointFileSystemCompiler();
DiagnosisHandler oldHandler = fsc.getDiagnosisHandler();
fsc.setDiagnosisHandler(new DiagnosisHandler() {
@Override
public void handleDiagnosis(Diagnosis diagnosis) {
oldHandler.handleDiagnosis(diagnosis);
if(diagnosis.getKind().isError()) Compiler.this.hasError = true;
}
});
File[] cps = parseClassPath(cli);
if(cps!=null){
for (File cp : cps) {
fsc.addClassPath(cp);
}
}
String outPath = ".";
if (cli.hasOption("s")) {
String srcPath = cli.getOptionValue("s");
fsc.addKalangAndJavaSourceDir(new File(srcPath));
}
if (cli.hasOption("o")) {
outPath = cli.getOptionValue("o");
}
String outputFormat = "class";
if(cli.hasOption("f")){
outputFormat = cli.getOptionValue("f");
}
FileSystemOutputManager outputManager = new FileSystemOutputManager(new File(outPath), outputFormat);
switch(outputFormat){
case "class":
fsc.setJavaOutputManager(outputManager);
fsc.setCodeGenerator(new ClassWriter(outputManager));
break;
case "ast":
fsc.setCodeGenerator(new AstWriter(outputManager));
break;
default:
throw new UnsupportedOperationException("unknown format:" + outputFormat);
}
File currentDir = new File(".");
fsc.addJavaSourcePath(currentDir);
fsc.addSourcePath(currentDir);
String[] srcs = cli.getArgs();
for(String s:srcs){
File srcFile = new File(s);
if(srcFile.isDirectory()){
fsc.addKalangAndJavaSourceDir(srcFile);
}else{
//TODO here should be currenDir?
fsc.addKalangOrJavaSource(currentDir , srcFile);
}
}
hasError = false;
fsc.compile();
return !hasError;
}
}