2017-01-09 71 views
1

我正在嘗試使用Apache Commons CLI來識別我的java程序的參數。所以,有很多選項(例如「-p」),但大多數情況下,應該用作java程序輸入的文件名稱。請注意,所有選項都沒有訂單限制。Commons CLI:識別文件名* .deca

decac -p -r 5 test.deca

我解析-p和-r(與參數「5」)的選擇沒有問題,但我如何創建「測試選項:啓動程序的

例.deca「知道它可以是任何東西。它也可能是像pathTo/anotherTest.deca

+0

後來就被用來描述使用的參數選項@亞倫看來它會解決我的問題。仍然不會以更一般的方式解決問題(多個文件名),但應該爲我工作!謝謝! – Fitz

+0

不客氣,我覺得很奇怪,這是沒有記錄在他們的使用場景 – Aaron

+0

我認爲它以一般方式解決了這個問題:這個列表應該包含任何不能被'CommandLineParser'解析的標記,所以對於'decac -p other.file -r 5 test.deca and.another',它應該包含'other.file','test.deca'和'and.another'。 – Aaron

回答

0

我認爲這是不可能與ApacheCommonsCLI開箱即用。你可以根據this answer做一些技巧,也可以作爲apache CLI documentation

Option decafile = OptionBuilder.withArgName("file.deca") 
          .hasArg() 
          .withDescription( "target deca file") 
          .create("decafile"); 

,可以用-dfile.deca或--decafile = file.deca

+0

不是我的解決方案,因爲我無法改變輸入參數的方式。感謝你的回答! – Fitz