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


Java CommandLine.getOptions方法代码示例

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


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

示例1: commandLine2Properties

import org.apache.commons.cli.CommandLine; //导入方法依赖的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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:17,代码来源:ServerUtil.java

示例2: parse

import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
public THashMap<String, String> parse(String[] input) {
	THashMap<String, String> result = new THashMap<>();
	try {
		CommandLine cmdLine = this.parse(this.getOptions(), input);
		for (Option option : cmdLine.getOptions()) {
			result.put(option.getOpt(), option.getValue());
		}
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return result;
}
 
开发者ID:HPI-Information-Systems,项目名称:metanome-algorithms,代码行数:13,代码来源:CLIParserBenchmarker.java

示例3: failover

import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
private int failover(CommandLine cmd)
    throws IOException, ServiceFailedException {
  boolean forceFence = cmd.hasOption(FORCEFENCE);
  boolean forceActive = cmd.hasOption(FORCEACTIVE);

  int numOpts = cmd.getOptions() == null ? 0 : cmd.getOptions().length;
  final String[] args = cmd.getArgs();

  if (numOpts > 3 || args.length != 2) {
    errOut.println("failover: incorrect arguments");
    printUsage(errOut, "-failover");
    return -1;
  }

  HAServiceTarget fromNode = resolveTarget(args[0]);
  HAServiceTarget toNode = resolveTarget(args[1]);
  
  // Check that auto-failover is consistently configured for both nodes.
  Preconditions.checkState(
      fromNode.isAutoFailoverEnabled() ==
        toNode.isAutoFailoverEnabled(),
        "Inconsistent auto-failover configs between %s and %s!",
        fromNode, toNode);
  
  if (fromNode.isAutoFailoverEnabled()) {
    if (forceFence || forceActive) {
      // -forceActive doesn't make sense with auto-HA, since, if the node
      // is not healthy, then its ZKFC will immediately quit the election
      // again the next time a health check runs.
      //
      // -forceFence doesn't seem to have any real use cases with auto-HA
      // so it isn't implemented.
      errOut.println(FORCEFENCE + " and " + FORCEACTIVE + " flags not " +
          "supported with auto-failover enabled.");
      return -1;
    }
    try {
      return gracefulFailoverThroughZKFCs(toNode);
    } catch (UnsupportedOperationException e){
      errOut.println("Failover command is not supported with " +
          "auto-failover enabled: " + e.getLocalizedMessage());
      return -1;
    }
  }
  
  FailoverController fc = new FailoverController(getConf(),
      requestSource);
  
  try {
    fc.failover(fromNode, toNode, forceFence, forceActive); 
    out.println("Failover from "+args[0]+" to "+args[1]+" successful");
  } catch (FailoverFailedException ffe) {
    errOut.println("Failover failed: " + ffe.getLocalizedMessage());
    return -1;
  }
  return 0;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:58,代码来源:HAAdmin.java

示例4: validate

import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
public boolean validate(final CommandLine input) {
    for(Option o : input.getOptions()) {
        if(Option.UNINITIALIZED == o.getArgs()) {
            continue;
        }
        if(o.hasOptionalArg()) {
            continue;
        }
        if(o.getArgs() != o.getValuesList().size()) {
            console.printf("Missing argument for option %s%n", o.getLongOpt());
            return false;
        }
    }
    final TerminalAction action = TerminalActionFinder.get(input);
    if(null == action) {
        console.printf("%s%n", "Missing argument");
        return false;
    }
    if(input.hasOption(TerminalOptionsBuilder.Params.existing.name())) {
        final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name());
        if(null == TransferAction.forName(arg)) {
            final Set<TransferAction> actions = new HashSet<TransferAction>(TransferAction.forTransfer(Transfer.Type.download));
            actions.add(TransferAction.cancel);
            console.printf("Invalid argument '%s' for option %s. Must be one of %s%n",
                arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray()));
            return false;
        }
        switch(action) {
            case download:
                if(!validate(arg, Transfer.Type.download)) {
                    return false;
                }
                break;
            case upload:
                if(!validate(arg, Transfer.Type.upload)) {
                    return false;
                }
                break;
            case synchronize:
                if(!validate(arg, Transfer.Type.sync)) {
                    return false;
                }
                break;
            case copy:
                if(!validate(arg, Transfer.Type.copy)) {
                    return false;
                }
                break;
        }
    }
    // Validate arguments
    switch(action) {
        case list:
        case download:
            if(!validate(input.getOptionValue(action.name()))) {
                return false;
            }
            break;
        case upload:
        case copy:
        case synchronize:
            if(!validate(input.getOptionValue(action.name()))) {
                return false;
            }
            break;
    }
    return true;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:69,代码来源:TerminalOptionsInputValidator.java

示例5: main

import org.apache.commons.cli.CommandLine; //导入方法依赖的package包/类
/**
 * See class {@code Example} 
 * @param args
 * @throws MalformedURLException
 */
public static void main( String[] args ) throws MalformedURLException, IOException {
   	CommandLineParser clParser = new DefaultParser();		
	Options opts = new Options();

	opts.addOption("h", "help", false, "display help");
	opts.addOption("m", "mzml", true, "mzml file");
	
	Option indexOpts = Option.builder("i")
			.hasArgs()
			.desc("indices of spectra to report")
			.argName("index")
			.build();
	opts.addOption(indexOpts);
	
	CommandLine cmd = null;
	HelpFormatter formatter = new HelpFormatter();
	try {
		cmd = clParser.parse(opts, args);
		if( cmd.hasOption("help") || (cmd.getOptions().length == 0)) {
			formatter.printHelp("help", opts);
			System.exit(-1);
		}
	} catch (ParseException e) {
		e.printStackTrace();
	}
	
	Path mzml = cmd.hasOption("m") ? Paths.get(cmd.getOptionValue("m")) : null;
	if(mzml == null ) {
		System.err.println("MZML file was not specified");
		System.exit(-1);
	}
		
   	List<Integer> indices = cmd.hasOption("i") 
   			? Stream.of(cmd.getOptionValues("i")).map(s -> Integer.parseInt(s)).collect(Collectors.toList())
   			: Collections.EMPTY_LIST;
	
   	// Creates a parser producing Spectrum instances and uses XMLSpectrumBuilder via method referencing
	MzMLStAXParser<Spectrum> parser = new MzMLStAXParser<Spectrum>(mzml, XMLSpectrumBuilder::new);
   	
   	if(indices.size() == 0) {
   		// if no indices supplied, sequentially iterate over the file
   		int maxCount = 10;
   		for(Spectrum spectrum : parser) {
   			if(maxCount == 0)
   				return;
   			
   			System.out.println(spectrum.toString());
   			maxCount--;
   		}
   	} else {
   		// if indices are supplied, access spectra by jumping to the position in file
   		for(int i : indices){
   			System.out.println(parser.getSpectrumByIndex(i).toString());
   		}
   	}
   	
   	parser.close();
   }
 
开发者ID:digitalproteomics,项目名称:dp-mzml,代码行数:64,代码来源:Example.java


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