package com.cli;
import org.apache.commons.cli.*;
import org.apache.commons.math3.random.AbstractRandomGenerator;
public class test {
public static void main(String[] args) throws ParseException {
CommandLine cmdlines = cmdLine(args);
//String[] optionValues = cmdlines.getOptionValues("c"); //获取数组
System.out.println(cmdlines.getOptionValue("h"));
System.out.println(cmdlines.getOptionValue("c"));
}
public static CommandLine cmdLine(String[] args) throws ParseException {
Options opts = new Options();
Option hopt = new Option("h","help",false,"xxxxx");
Option h2opt = new Option("c","com",true,"ccccc");
h2opt.setRequired(true);
h2opt.setType(Integer.class); // 值的类型
h2opt.setArgs(10); //Set option c to take maximum of 10 arguments
//Option build = Option.builder().build();
opts.addOption(hopt);
opts.addOption(h2opt);
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("整体的描述信息\n 1. 白云千载空悠悠\n 2. nihao m a??????xxxx\\00000",opts);
CommandLine parse = new DefaultParser().parse(opts,args);
return parse;
}
}