2016-12-15 1 views
2

Common-CLI API를 사용하여 명령에 도움말을 표시하고 있습니다. 다음 기능은 명령의 도움말을 표시합니다.명령 줄 인수가 순서가 맞지 않습니다.

public static void printHelp(final Options options, final int width, final String cmdLineSyntax, 
     final String header, final String footer, final int leftPad, final int descPad, final boolean autoUsage, 
     final OutputStream out) { 
    PrintWriter writer = new PrintWriter(out); 
    final HelpFormatter helpFormatter = new HelpFormatter(); 
    helpFormatter.printHelp(writer, width, cmdLineSyntax, header, options, leftPad, descPad, footer, autoUsage); 
    writer.flush(); 
} 

다음 순서로 옵션을 추가했습니다.

Option option1 = Option.builder("A").longOpt("almost-all").desc("do not list implied . and ..").hasArg(false) 
       .build(); 

     Option option2 = Option.builder("b").longOpt("block-size").argName("SIZE> <CAPACITY> <LINE").numberOfArgs(3) 
       .desc("use SIZE-byte blocks").hasArg(true).build(); 

     Option option3 = Option.builder("c") 
       .desc("with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime") 
       .hasArg(false).build(); 

     Options options = new Options(); 
     options.addOption(option1); 
     options.addOption(option2); 
     options.addOption(Option.builder().longOpt("escape").desc("print octal escapes for nongraphic characters") 
       .hasArg(false).build()); 

     options.addOption(option3); 

옵션 개체에 printHelp 함수를 호출하면 출력이 다음과 같이 표시됩니다.

usage: ls [-A] [-b <SIZE> <CAPACITY> <LINE>] [-c] [--escape] 
    -A,--almost-all        do not list implied . and .. 
    -b,--block-size <SIZE> <CAPACITY> <LINE>  use SIZE-byte blocks 
    -c           with -lt: sort by, and show, ctime (time of last 
                modification of file status information) with 
                -l:show ctime and sort by name otherwise: sort by 
                ctime 
     --escape         print octal escapes for nongraphic characters 

그러나 나는 다음과 같이 기대하고 있습니다.

usage: ls [-A] [-b <SIZE> <CAPACITY> <LINE>] [-c] [--escape] 
    -A,--almost-all        do not list implied . and .. 
    -b,--block-size <SIZE> <CAPACITY> <LINE>  use SIZE-byte blocks 
     --escape         print octal escapes for nongraphic characters 
    -c           with -lt: sort by, and show, ctime (time of last 
                modification of file status information) with 
                -l:show ctime and sort by name otherwise: sort by 
                ctime 

예상되는 결과를 얻는 방법은 무엇입니까?

+0

나는 "아파치 - 평민 - CLI"에 익숙하지 오전하지만이 옵션을 만드는 순서는 관련이 보인다 인쇄 명령. 따라서 위의 마지막 옵션을 만들어야합니다. – Seelenvirtuose

+0

옵션 개체에 순서대로 옵션을 추가하려고합니다. –

+0

예, 옵션 개체에 넣는 것과 다른 순서로 만들었습니다. 대답은 분명히 이것을 설명합니다. – Seelenvirtuose

답변

2

나는 this을 찾고 있습니다.

public void setOptionComparator (Comparator comparator) 도움말 텍스트로 출력 할 때 옵션을 정렬하는 데 사용되는 비교기를 설정합니다. null 비교기를 전달하면 옵션이 이 선언 된 순서대로 유지됩니다. 매개 변수 : 비교기 - 비교기는 옵션

정렬 에 사용하는

참조 : https://commons.apache.org/proper/commons-cli/javadocs/api-release/org/apache/commons/cli/HelpFormatter.html

관련 문제