Skip to content

Commit 8677d16

Browse files
committed
Rename to HelpAppendable since it extends Appendable
- FilterHelpAppendable implements HelpAppendable: Same naming as FilterOutputStream extends OutputStream which delegates to an OutputStream - Was HelpWriter extends Appendable - Was AbstractHelpWriter implements HelpAppendable - These are are not kinds of java.io.Writer
1 parent c113423 commit 8677d16

12 files changed

Lines changed: 88 additions & 87 deletions

src/main/java/org/apache/commons/cli/help/AbstractHelpFormatter.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3232
import org.apache.commons.cli.Options;
3333

3434
/**
35-
* The class for help formatters provides the framework to link the {@link HelpWriter} with the {@link OptionFormatter} and a default {@link TableDefinition} so
36-
* to produce a standard format help page.
35+
* The class for help formatters provides the framework to link the {@link HelpAppendable} with the {@link OptionFormatter} and a default
36+
* {@link TableDefinition} so to produce a standard format help page.
3737
*
3838
* @since 1.10.0
3939
*/
@@ -53,9 +53,9 @@ public abstract class AbstractHelpFormatter {
5353
public static final Comparator<Option> DEFAULT_COMPARATOR = (opt1, opt2) -> opt1.getKey().compareToIgnoreCase(opt2.getKey());
5454

5555
/**
56-
* The {@link HelpWriter} that produces the final output.
56+
* The {@link HelpAppendable} that produces the final output.
5757
*/
58-
protected final HelpWriter helpWriter;
58+
protected final HelpAppendable helpAppendable;
5959
/**
6060
* The OptionFormatter.Builder used to display options within the help page
6161
*/
@@ -74,14 +74,14 @@ public abstract class AbstractHelpFormatter {
7474
/**
7575
* Constructs the base formatter.
7676
*
77-
* @param helpWriter the helpWriter to output with
77+
* @param helpAppendable the helpAppendable to output with
7878
* @param optionFormatBuilder the builder of {@link OptionFormatter} to format options for display.
7979
* @param comparator The comparator to use for sorting options.
8080
* @param optionGroupSeparator the string to separate option groups.
8181
*/
82-
protected AbstractHelpFormatter(final HelpWriter helpWriter, final OptionFormatter.Builder optionFormatBuilder, final Comparator<Option> comparator,
82+
protected AbstractHelpFormatter(final HelpAppendable helpAppendable, final OptionFormatter.Builder optionFormatBuilder, final Comparator<Option> comparator,
8383
final String optionGroupSeparator) {
84-
this.helpWriter = Objects.requireNonNull(helpWriter, "helpWriter");
84+
this.helpAppendable = Objects.requireNonNull(helpAppendable, "helpAppendable");
8585
this.optionFormatBuilder = Objects.requireNonNull(optionFormatBuilder, "optionFormatBuilder");
8686
this.comparator = Objects.requireNonNull(comparator, "comparator");
8787
this.optionGroupSeparator = Util.defaultValue(optionGroupSeparator, "");
@@ -107,12 +107,12 @@ public final OptionFormatter getOptionFormatter(final Option option) {
107107
}
108108

109109
/**
110-
* Gets the {@link HelpWriter} associated with this help formatter.
110+
* Gets the {@link HelpAppendable} associated with this help formatter.
111111
*
112-
* @return The {@link HelpWriter} associated with this help formatter.
112+
* @return The {@link HelpAppendable} associated with this help formatter.
113113
*/
114-
public final HelpWriter getSerializer() {
115-
return helpWriter;
114+
public final HelpAppendable getSerializer() {
115+
return helpAppendable;
116116
}
117117

118118
/**
@@ -140,24 +140,24 @@ public final String getSyntaxPrefix() {
140140
* @param options the collection of {@link Option} objects to print.
141141
* @param footer the banner to display at the end of the help
142142
* @param autoUsage whether to print an automatically generated usage statement
143-
* @throws IOException If the output could not be written to the {@link HelpWriter}
143+
* @throws IOException If the output could not be written to the {@link HelpAppendable}
144144
*/
145145
public void printHelp(final String cmdLineSyntax, final String header, final Iterable<Option> options, final String footer, final boolean autoUsage)
146146
throws IOException {
147147
if (Util.isEmpty(cmdLineSyntax)) {
148148
throw new IllegalArgumentException("cmdLineSyntax not provided");
149149
}
150150
if (autoUsage) {
151-
helpWriter.appendParagraph(format("%s %s %s", syntaxPrefix, cmdLineSyntax, toSyntaxOptions(options)));
151+
helpAppendable.appendParagraph(format("%s %s %s", syntaxPrefix, cmdLineSyntax, toSyntaxOptions(options)));
152152
} else {
153-
helpWriter.appendParagraph(format("%s %s", syntaxPrefix, cmdLineSyntax));
153+
helpAppendable.appendParagraph(format("%s %s", syntaxPrefix, cmdLineSyntax));
154154
}
155155
if (!Util.isEmpty(header)) {
156-
helpWriter.appendParagraph(header);
156+
helpAppendable.appendParagraph(header);
157157
}
158-
helpWriter.appendTable(getTableDefinition(options));
158+
helpAppendable.appendTable(getTableDefinition(options));
159159
if (!Util.isEmpty(footer)) {
160-
helpWriter.appendParagraph(footer);
160+
helpAppendable.appendParagraph(footer);
161161
}
162162
}
163163

@@ -169,41 +169,41 @@ public void printHelp(final String cmdLineSyntax, final String header, final Ite
169169
* @param options the {@link Options} to print
170170
* @param footer the banner to display at the end of the help
171171
* @param autoUsage whether to print an automatically generated usage statement
172-
* @throws IOException If the output could not be written to the {@link HelpWriter}
172+
* @throws IOException If the output could not be written to the {@link HelpAppendable}
173173
*/
174174
public final void printHelp(final String cmdLineSyntax, final String header, final Options options, final String footer, final boolean autoUsage)
175175
throws IOException {
176176
printHelp(cmdLineSyntax, header, options.getOptions(), footer, autoUsage);
177177
}
178178

179179
/**
180-
* Prints the option table for a collection of {@link Option} objects to the {@link HelpWriter}.
180+
* Prints the option table for a collection of {@link Option} objects to the {@link HelpAppendable}.
181181
*
182182
* @param options the collection of Option objects to print in the table.
183-
* @throws IOException If the output could not be written to the {@link HelpWriter}
183+
* @throws IOException If the output could not be written to the {@link HelpAppendable}
184184
*/
185185
public final void printOptions(final Iterable<Option> options) throws IOException {
186186
printOptions(getTableDefinition(options));
187187
}
188188

189189
/**
190-
* Prints the option table for the specified {@link Options} to the {@link HelpWriter}.
190+
* Prints the option table for the specified {@link Options} to the {@link HelpAppendable}.
191191
*
192192
* @param options the Options to print in the table.
193-
* @throws IOException If the output could not be written to the {@link HelpWriter}
193+
* @throws IOException If the output could not be written to the {@link HelpAppendable}
194194
*/
195195
public final void printOptions(final Options options) throws IOException {
196196
printOptions(options.getOptions());
197197
}
198198

199199
/**
200-
* Prints a {@link TableDefinition} to the {@link HelpWriter}.
200+
* Prints a {@link TableDefinition} to the {@link HelpAppendable}.
201201
*
202202
* @param tableDefinition the {@link TableDefinition} to print.
203-
* @throws IOException If the output could not be written to the {@link HelpWriter}
203+
* @throws IOException If the output could not be written to the {@link HelpAppendable}
204204
*/
205205
public final void printOptions(final TableDefinition tableDefinition) throws IOException {
206-
helpWriter.appendTable(tableDefinition);
206+
helpAppendable.appendTable(tableDefinition);
207207
}
208208

209209
/**

src/main/java/org/apache/commons/cli/help/AbstractHelpWriter.java renamed to src/main/java/org/apache/commons/cli/help/FilterHelpAppendable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1919
import java.io.IOException;
2020

2121
/**
22-
* An abstract implementation of {@link HelpWriter} that writes output to an {@link Appendable} instance.
22+
* An abstract implementation of {@link HelpAppendable} that writes output to an {@link Appendable} instance.
2323
*
2424
* @since 1.10.0
2525
*/
26-
public abstract class AbstractHelpWriter implements HelpWriter {
26+
public abstract class FilterHelpAppendable implements HelpAppendable {
2727

2828
/**
2929
* The Appendable instance to write to.
@@ -35,7 +35,7 @@ public abstract class AbstractHelpWriter implements HelpWriter {
3535
*
3636
* @param output the Appendable instance to write to.
3737
*/
38-
protected AbstractHelpWriter(final Appendable output) {
38+
protected FilterHelpAppendable(final Appendable output) {
3939
this.output = output;
4040
}
4141

src/main/java/org/apache/commons/cli/help/HelpWriter.java renamed to src/main/java/org/apache/commons/cli/help/HelpAppendable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2929
*
3030
* @since 1.10.0
3131
*/
32-
public interface HelpWriter extends Appendable {
32+
public interface HelpAppendable extends Appendable {
3333

3434
/**
3535
* Appends a header.

src/main/java/org/apache/commons/cli/help/HelpFormatter.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class HelpFormatter extends AbstractHelpFormatter {
6767
* A builder for the HelpFormatter. Intended to make more complex uses of the HelpFormatter class easier. Default values are:
6868
* <ul>
6969
* <li>showSince = true</li>
70-
* <li>helpWriter = a {@link TextHelpWriter} writing to {@code System.out}</li>
70+
* <li>helpAppendable = a {@link TextHelpAppendable} writing to {@code System.out}</li>
7171
* <li>optionFormatter.Builder = the default {@link OptionFormatter.Builder}</li>
7272
* </ul>
7373
*/
@@ -76,8 +76,8 @@ public static class Builder {
7676
/** If {@code true} show the "Since" column, otherwise ignore it. */
7777
private boolean showSince;
7878

79-
/** The {@link HelpWriter} to use */
80-
private HelpWriter helpWriter;
79+
/** The {@link HelpAppendable} to use */
80+
private HelpAppendable helpAppendable;
8181

8282
/** The {@link OptionFormatter.Builder} to use to format options in the table. */
8383
private OptionFormatter.Builder optionFormatBuilder;
@@ -144,13 +144,13 @@ public Builder setOptionGroupSeparator(final String optionGroupSeparator) {
144144
}
145145

146146
/**
147-
* Sets the {@link HelpWriter}.
147+
* Sets the {@link HelpAppendable}.
148148
*
149-
* @param helpWriter the {@link HelpWriter} to use.
149+
* @param helpAppendable the {@link HelpAppendable} to use.
150150
* @return this
151151
*/
152-
public Builder setSerializer(final HelpWriter helpWriter) {
153-
this.helpWriter = helpWriter;
152+
public Builder setSerializer(final HelpAppendable helpAppendable) {
153+
this.helpAppendable = helpAppendable;
154154
return this;
155155
}
156156

@@ -171,8 +171,8 @@ public Builder setShowSince(final boolean showSince) {
171171
* @return this.
172172
*/
173173
private Builder validate() {
174-
if (helpWriter == null) {
175-
helpWriter = new TextHelpWriter(System.out);
174+
if (helpAppendable == null) {
175+
helpAppendable = new TextHelpAppendable(System.out);
176176
}
177177
if (optionFormatBuilder == null) {
178178
optionFormatBuilder = new OptionFormatter.Builder();
@@ -211,18 +211,18 @@ public HelpFormatter() {
211211
* @param builder the Builder to build from.
212212
*/
213213
private HelpFormatter(final Builder builder) {
214-
super(builder.helpWriter, builder.optionFormatBuilder, builder.comparator, builder.optionGroupSeparator);
214+
super(builder.helpAppendable, builder.optionFormatBuilder, builder.comparator, builder.optionGroupSeparator);
215215

216216
this.showSince = builder.showSince;
217217
}
218218

219219
/**
220-
* Convenience constructor to create an instance using the specified {@link HelpWriter} and the remaining default {@link Builder}.
220+
* Convenience constructor to create an instance using the specified {@link HelpAppendable} and the remaining default {@link Builder}.
221221
*
222-
* @param helpWriter the {@link HelpWriter} to use.
222+
* @param helpAppendable the {@link HelpAppendable} to use.
223223
*/
224-
public HelpFormatter(final HelpWriter helpWriter) {
225-
this(new Builder().setSerializer(helpWriter).validate());
224+
public HelpFormatter(final HelpAppendable helpAppendable) {
225+
this(new Builder().setSerializer(helpAppendable).validate());
226226
}
227227

228228
/**

src/main/java/org/apache/commons/cli/help/TextHelpWriter.java renamed to src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3232
*
3333
* @since 1.10.0
3434
*/
35-
public class TextHelpWriter extends AbstractHelpWriter {
35+
public class TextHelpAppendable extends FilterHelpAppendable {
3636

3737
/** Default number of characters per line */
3838
public static final int DEFAULT_WIDTH = 74;
@@ -118,7 +118,7 @@ public static int findWrapPos(final CharSequence text, final int width, final in
118118
* Construct from an output.
119119
* @param output the Appendable to write the output to.
120120
*/
121-
public TextHelpWriter(final Appendable output) {
121+
public TextHelpAppendable(final Appendable output) {
122122
super(output);
123123
styleBuilder = new TextStyle.Builder().setMaxWidth(DEFAULT_WIDTH)
124124
.setLeftPad(DEFAULT_LEFT_PAD).setIndent(DEFAULT_INDENT);
@@ -349,7 +349,7 @@ private void printQueue(final Queue<String> queue) throws IOException {
349349
}
350350

351351
/**
352-
* Print wrapped text using the TextHelpWriter output style.
352+
* Print wrapped text using the TextHelpAppendable output style.
353353
* @param text the text to wrap
354354
* @throws IOException on output error.
355355
*/

src/main/java/org/apache/commons/cli/help/TextStyle.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2020

2121
/**
2222
* The definition for styling recommendations blocks of text. Most common usage is to style columns in a table, but may also be used to specify default styling
23-
* for a {@link HelpWriter}. HelpWriters are free to ignore the TextStyle recommendations particularly where they are not supported or contradict common usage.
23+
* for a {@link HelpAppendable}. HelpWriters are free to ignore the TextStyle recommendations particularly where they are not supported or contradict common
24+
* usage.
2425
*
2526
* @since 1.10.0
2627
*/
@@ -53,7 +54,7 @@ public static final class Builder implements Supplier<TextStyle> {
5354
/** The subsequent line indentation. */
5455
private int indent;
5556

56-
/** The scalable flag. Identifies text blocks that can be made narrower or wider as needed by the HelpWriter. */
57+
/** The scalable flag. Identifies text blocks that can be made narrower or wider as needed by the HelpAppendable. */
5758
private boolean scalable;
5859

5960
/** The minimum width. */
@@ -134,7 +135,7 @@ public int getMinWidth() {
134135
}
135136

136137
/**
137-
* Specifies if the column can be made wider or to narrower width to fit constraints of the HelpWriter and formatting.
138+
* Specifies if the column can be made wider or to narrower width to fit constraints of the HelpAppendable and formatting.
138139
*
139140
* @return The currently specified scaling value.
140141
*/
@@ -198,7 +199,7 @@ public Builder setMinWidth(final int minWidth) {
198199
}
199200

200201
/**
201-
* Specifies if the column can be made wider or to narrower width to fit constraints of the HelpWriter and formatting.
202+
* Specifies if the column can be made wider or to narrower width to fit constraints of the HelpAppendable and formatting.
202203
*
203204
* @param scalable if {@code true} the text width can be adjusted.
204205
* @return this.
@@ -295,7 +296,7 @@ public int getMinWidth() {
295296
}
296297

297298
/**
298-
* Specifies if the column can be made wider or to narrower width to fit constraints of the HelpWriter and formatting.
299+
* Specifies if the column can be made wider or to narrower width to fit constraints of the HelpAppendable and formatting.
299300
*
300301
* @return the scaling value.
301302
*/

src/test/java/org/apache/commons/cli/help/HelpFormatterTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2929
import org.apache.commons.cli.Option;
3030
import org.apache.commons.cli.OptionGroup;
3131
import org.apache.commons.cli.Options;
32-
import org.apache.commons.example.cli.XhtmlHelpWriter;
32+
import org.apache.commons.example.cli.XhtmlHelpAppendable;
3333
import org.apache.commons.io.IOUtils;
3434
import org.junit.jupiter.api.Test;
3535

@@ -59,17 +59,17 @@ private Options getTestGroups() {
5959
@Test
6060
public void testDefault() {
6161
final StringBuilder sb = new StringBuilder();
62-
final TextHelpWriter serializer = new TextHelpWriter(sb);
62+
final TextHelpAppendable serializer = new TextHelpAppendable(sb);
6363
final HelpFormatter formatter = new HelpFormatter(serializer);
64-
assertEquals(serializer, formatter.getSerializer(), "Unexpected helpWriter tests may fail unexpectedly");
64+
assertEquals(serializer, formatter.getSerializer(), "Unexpected helpAppendable tests may fail unexpectedly");
6565
assertEquals(AbstractHelpFormatter.DEFAULT_COMPARATOR, formatter.getComparator(), "Unexpected comparator tests may fail unexpectedly");
6666
assertEquals(AbstractHelpFormatter.DEFAULT_SYNTAX_PREFIX, formatter.getSyntaxPrefix(), "Unexpected syntax prefix tests may fail unexpectedly");
6767
}
6868

6969
@Test
7070
public void testPrintHelp() throws IOException {
7171
final StringBuilder sb = new StringBuilder();
72-
final TextHelpWriter serializer = new TextHelpWriter(sb);
72+
final TextHelpAppendable serializer = new TextHelpAppendable(sb);
7373
HelpFormatter formatter = new HelpFormatter(serializer);
7474

7575
final Options options = new Options().addOption(Option.builder("a").since("1853").hasArg().desc("aaaa aaaa aaaa aaaa aaaa").build());
@@ -147,7 +147,7 @@ public void testPrintHelp() throws IOException {
147147
@Test
148148
public void testPrintHelpXML() throws IOException {
149149
final StringBuilder sb = new StringBuilder();
150-
final XhtmlHelpWriter serializer = new XhtmlHelpWriter(sb);
150+
final XhtmlHelpAppendable serializer = new XhtmlHelpAppendable(sb);
151151
final HelpFormatter formatter = new HelpFormatter(serializer);
152152

153153
final Options options = new Options().addOption("a", false, "aaaa aaaa aaaa aaaa aaaa");
@@ -178,16 +178,16 @@ public void testPrintHelpXML() throws IOException {
178178
@Test
179179
public void testPrintOptions() throws IOException {
180180
final StringBuilder sb = new StringBuilder();
181-
final TextHelpWriter serializer = new TextHelpWriter(sb);
181+
final TextHelpAppendable serializer = new TextHelpAppendable(sb);
182182
final HelpFormatter formatter = new HelpFormatter.Builder().setSerializer(serializer).setShowSince(false).build();
183183

184184
// help format default column styles
185-
// col options description helpWriter
185+
// col options description helpAppendable
186186
// styl FIXED VARIABLE VARIABLE
187187
// LPad 0 5 1
188188
// indent 1 1 3
189189
//
190-
// default helpWriter
190+
// default helpAppendable
191191

192192
Options options;
193193
List<String> expected = new ArrayList<>();
@@ -292,7 +292,7 @@ public void testSortOptionsTest() {
292292
@Test
293293
public void testSyntaxPrefix() {
294294
final StringBuilder sb = new StringBuilder();
295-
final TextHelpWriter serializer = new TextHelpWriter(sb);
295+
final TextHelpAppendable serializer = new TextHelpAppendable(sb);
296296
final HelpFormatter formatter = new HelpFormatter(serializer);
297297
formatter.setSyntaxPrefix("Something new");
298298
assertEquals("Something new", formatter.getSyntaxPrefix());
@@ -302,7 +302,7 @@ public void testSyntaxPrefix() {
302302
@Test
303303
public void testToArgNameTest() {
304304
final StringBuilder sb = new StringBuilder();
305-
final TextHelpWriter serializer = new TextHelpWriter(sb);
305+
final TextHelpAppendable serializer = new TextHelpAppendable(sb);
306306
final HelpFormatter formatter = new HelpFormatter(serializer);
307307

308308
assertEquals("<some Arg>", formatter.toArgName("some Arg"));

0 commit comments

Comments
 (0)