View Javadoc

1   package com.lexicalscope.jewel.cli;
2   
3   /*
4    * Copyright 2011 Tim Wood
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License. 
17   */
18  
19  class HelpMessageBuilderImpl implements HelpMessage {
20      private final StringBuilder message = new StringBuilder();
21  
22      @Override public void noUsageInformation() {
23          message.append("The options available are:");
24      }
25  
26      @Override public void hasUsageInformation(final String applicationName) {
27          hasUsageInformation();
28          message.append(String.format("%s ", applicationName));
29      }
30  
31      @Override public void hasUsageInformation() {
32          message.append("Usage: ");
33      }
34  
35      @Override public void hasOnlyOptionalOptions() {
36          message.append("[");
37          message.append("options");
38          message.append("]");
39      }
40  
41      @Override public void hasSomeMandatoryOptions() {
42          message.append("options");
43      }
44  
45      @Override public void hasUnparsedMultiValuedOption(final String valueName) {
46          message.append(" ");
47          message.append(valueName);
48          message.append("...");
49      }
50  
51      @Override public void hasUnparsedOption(final String valueName) {
52          message.append(" ");
53          message.append(valueName);
54      }
55  
56      private final String lineSeparator = System.getProperty("line.separator");
57      private String separator = "";
58  
59      @Override public void startOfOptions() {
60          message.append(lineSeparator);
61      }
62  
63      @Override public OptionHelpMessage option() {
64          message.append(separator).append("\t");
65          separator = lineSeparator;
66          return new HelpMessageOptionSummaryBuilderImpl(message);
67      }
68  
69      @Override public void endOfOptions() {
70          // OK
71      }
72  
73      @Override public String toString() {
74          return message.toString();
75      }
76  }