导航设置
package com.sjj.advance.thirdlibrary.commons_cli;
import org.apache.commons.cli.*;
public class CommandDemo {
private static CommandLineParser parser = new BasicParser();
private static Options options;
public static void main(String[] args) {
initCommandLine();
try {
CommandLine commandline = parser.parse(options, args);
if(commandline.hasOption("h")){
showHelp();
}else if(commandline.hasOption("t")&& commandline.hasOption("")){
}
else {
showHelp();
}
} catch (ParseException e) {
System.out.println("解析命令行报错");
}
}
private static void initCommandLine() {
options = new Options();
Option helpOption = new Option("h","help",false,"Print the usage information");
options.addOption(helpOption);
Option tableOption = new Option("t","table",true,"import which table");
tableOption.setArgs(1);
tableOption.setArgName("tableNmae");
options.addOption(tableOption);
Option fileOption = new Option("f","file",true,"filePath location");
fileOption.setArgs(1);
fileOption.setArgName("filePath");
options.addOption(fileOption);
Option compressOption = new Option("c","compress",true,"compress type(NONE,ZLIB,SNAPPY,LZO,LZ4,ZSTD)");
compressOption.setArgs(1);
compressOption.setArgName("compressType");
options.addOption(compressOption);
Option sizeOption = new Option("s","size",true,"size of one orc file");
sizeOption.setArgs(1);
sizeOption.setArgName("orcSize");
options.addOption(compressOption);
}
private static void showHelp(){
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("sh dataImport.sh [option]",options);
}
}