atitit.基于CommonsCLI的命令行原理與開發(fā)
1.命令行支持的格式有以下幾種:1
2.json化,map化的命令行參數(shù)內(nèi)部表示1
3.Aticli2
4.CLI庫支持不同格式的選項(xiàng): 2
5.參考3
1.命令行支持的格式有以下幾種:基于ApacheCommonsCLI的命令行開發(fā)
ApacheCommonsCLI簡介
ApacheCommonsCLI是Apache下面的一個(gè)解析命令行輸入的工具包,該工具包還提供了自動生成輸出幫助文檔的功能。
ApacheCommonsCLI支持多種輸入?yún)?shù)格式,主要支持的格式有以下幾種:
1.POSIX(PortableOperatingSystemInterfaceofUnix)中的參數(shù)形式,例如tar-zxvffoo.tar.gz
2.GNU中的長參數(shù)形式,例如du--human-readable--max-depth=1
3.java命令中的參數(shù)形式,例如java-Djava.net.useSystemPRoxies=trueFoo
4.短杠參數(shù)帶參數(shù)值的參數(shù)形式,例如gcc-O2foo.c
5.長杠參數(shù)不帶參數(shù)值的形式,例如ant–projecthelp
作者::老哇的爪子Attilax艾龍,EMAIL:1466519819@QQ.com
轉(zhuǎn)載請注明來源:http://www.survivalescaperooms.com/attilax/
2.json化,map化的命令行參數(shù)內(nèi)部表示直接使用json會把個(gè)雙引號消去。。不能解析了。。
ApacheCommonsCLI庫提供API,可以幫助程序去解析傳遞給程序的命令行參數(shù)。他也可以打印幫助信息,來說明可以運(yùn)用于命令行的有效參數(shù)。
3.AticliOptionsopts=newOptions();
opts.addOption("gene",false,"help:misparamdir");
opts.addOption("dir",true,"help:misparamdir");
opts.addOption("gene_txtfile",true,"help:misparamgene_batfile");
opts.addOption("gene_batfile",true,"help:misparamgene_batfile");
CommandLineParserparser=newPosixParser();
cmd=parser.parse(opts,args);
if(cmd.hasOption("gene"))
geneBat(cmd.getOptionValue("dir"),
cmd.getOptionValue("gene_txtfile"));
else
execClr(cmd.getOptionValue("dir"),
cmd.getOptionValue("gene_txtfile"));
System.out.println("--f");
4.CLI庫支持不同格式的選項(xiàng):1.POSIX格式的選項(xiàng)(比如:tar-zxvffoo.tar.gz)
2.GNU格式的長參數(shù)選項(xiàng)(比如:du--human-readable--max-depth=1)
3.Java格式的屬性(比如:java-Djava.awt.headless=true-Djava.net.useSystemProxies=trueFoo)
4.帶值的單選項(xiàng)(比如:gcc-O2foo.c)
5.單-號的長參數(shù)選項(xiàng)(比如:ant-projecthelp)
BasicParser類來解析用戶輸入的參數(shù),當(dāng)參數(shù)中包含–h時(shí)程序打印命令行的幫助
5.參考使用ApacheCommonsCLI開發(fā)命令行工具.htm
ApacheCommons系列簡介之CLI-為程序員服務(wù).htm
使用ApacheCommonsCLI開發(fā)命令行工具.htm
新聞熱點(diǎn)
疑難解答
圖片精選