View Javadoc

1   package com.lexicalscope.jewel.cli;
2   
3   import java.util.List;
4   
5   /*
6    * Copyright 2011 Tim Wood
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License. 
19   */
20  
21  class HelpMessageOptionSummaryBuilderImpl implements OptionHelpMessage {
22      final StringBuilder result;
23  
24      public HelpMessageOptionSummaryBuilderImpl(final StringBuilder message) {
25          result = message;
26      }
27  
28      public HelpMessageOptionSummaryBuilderImpl() {
29          this(new StringBuilder());
30      }
31  
32      @Override public void startOptionalOption() {
33          result.append("[");
34      }
35  
36      @Override public void startMandatoryOption() {
37  
38      }
39  
40      @Override public void longName(final List<String> longNames) {
41          String sepatator = "";
42          for (final String longName : longNames) {
43              result.append(sepatator).append("--").append(longName);
44              sepatator = " ";
45          }
46      }
47  
48      @Override public void shortName(final List<String> shortNames) {
49          for (final String shortName : shortNames) {
50              result.append(" -").append(shortName);
51          }
52      }
53  
54      private void multiValued() {
55          result.append("...");
56      }
57  
58      @Override public void multiValuedWithCustomPattern(final String pattern) {
59          singleValuedWithCustomPattern(pattern);
60          multiValued();
61      }
62  
63      @Override public void multiValuedWithCustomPattern() {
64          singleValued();
65          multiValued();
66      }
67  
68      @Override public void singleValuedWithCustomPattern(final String pattern) {
69          result.append(" /").append(pattern).append("/");
70      }
71  
72      @Override public void singleValued() {
73          result.append(" value");
74      }
75  
76      @Override public void noValued() {
77          // OK
78      }
79  
80      @Override public void endOptionalOption() {
81          result.append("]");
82      }
83  
84      @Override public void endOptionalOption(final String description) {
85          endOptionalOption();
86          optionDescription(description);
87      }
88  
89      @Override public void endMandatoryOption() {
90  
91      }
92  
93      @Override public void endMandatoryOption(final String description) {
94          optionDescription(description);
95      }
96  
97      private void optionDescription(final String description) {
98          result.append(" : ").append(description);
99      }
100 
101     @Override public String toString()
102     {
103         return result.toString();
104     }
105 }