This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-cli.git
The following commit(s) were added to refs/heads/master by this push: new 62d1ba73 Normalize builder pattern 62d1ba73 is described below commit 62d1ba73661f7d3b2f4e36bc2db139bf5c6b068d Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Oct 16 16:07:10 2024 -0400 Normalize builder pattern - Don't mix builder patterns - Reduce new public API footprint - Remove unused elements - Refactor magic number into a constant - Javadoc package info - Don't need both an array constant and a set constant - Make that set immutable - Javadoc semantic fixes - Use same naming pattern as Java: indexOf... - Don't need Javadoc since tag on a method when the class has it for the same version - Rename example package - Reuse StringUtils from tests - Fix generics compiler warnings in tests - Remove dangling commas in array declarations --- .../commons/cli/help/AbstractHelpFormatter.java | 147 +++++++++++++++-- .../commons/cli/help/FilterHelpAppendable.java | 6 +- .../org/apache/commons/cli/help/HelpFormatter.java | 131 +++------------ .../apache/commons/cli/help/OptionFormatter.java | 11 +- .../apache/commons/cli/help/TableDefinition.java | 8 +- .../commons/cli/help/TextHelpAppendable.java | 180 +++++++++++---------- .../org/apache/commons/cli/help/TextStyle.java | 53 ++++-- .../java/org/apache/commons/cli/help/Util.java | 19 ++- .../org/apache/commons/cli/help/package-info.java | 17 +- .../cli => cli/example}/AptHelpAppendable.java | 25 +-- .../cli => cli/example}/AptHelpAppendableTest.java | 16 +- .../cli => cli/example}/WeirdOptionFormat.java | 5 +- .../cli => cli/example}/XhtmlHelpAppendable.java | 5 +- .../example}/XhtmlHelpAppendableTest.java | 16 +- .../apache/commons/cli/help/HelpFormatterTest.java | 34 ++-- .../commons/cli/help/OptionFormatterTest.java | 3 +- .../commons/cli/help/TextHelpAppendableTest.java | 60 ++++--- .../apache/commons/cli/help/TextStyleTests.java | 2 +- 18 files changed, 383 insertions(+), 355 deletions(-) diff --git a/src/main/java/org/apache/commons/cli/help/AbstractHelpFormatter.java b/src/main/java/org/apache/commons/cli/help/AbstractHelpFormatter.java index 6312fa8a..b930944f 100644 --- a/src/main/java/org/apache/commons/cli/help/AbstractHelpFormatter.java +++ b/src/main/java/org/apache/commons/cli/help/AbstractHelpFormatter.java @@ -16,8 +16,6 @@ */ package org.apache.commons.cli.help; -import static java.lang.String.format; - import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -26,32 +24,149 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.function.Function; +import java.util.function.Supplier; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionGroup; import org.apache.commons.cli.Options; /** - * The class for help formatters provides the framework to link the {@link HelpAppendable} with the {@link OptionFormatter} and a default - * {@link TableDefinition} so to produce a standard format help page. + * Helps formatters provides the framework to link a {@link HelpAppendable} with a {@link OptionFormatter} and a default {@link TableDefinition} so to produce + * standardized format help output. * * @since 1.10.0 */ public abstract class AbstractHelpFormatter { - /** The string to display at the beginning of the usage statement */ - public static final String DEFAULT_SYNTAX_PREFIX = "usage: "; - /** - * The default separator between {@link OptionGroup} elements. + * Abstracts building instances for subclasses. + * <ul> + * <li>helpAppendable = a {@link TextHelpAppendable} writing to {@code System.out}</li> + * <li>optionFormatter.Builder = the default {@link OptionFormatter.Builder}</li> + * </ul> + * + * @param <B> The builder type. + * @param <T> The type to build. */ - public static final String DEFAULT_OPTION_GROUP_SEPARATOR = " | "; + public abstract static class Builder<B extends Builder<B, T>, T extends AbstractHelpFormatter> implements Supplier<T> { + + /** The comparator to sort lists of options */ + private Comparator<Option> comparator = DEFAULT_COMPARATOR; + + /** The {@link HelpAppendable} to use */ + private HelpAppendable helpAppendable = defaultTextHelpAppendable(); + + /** The {@link OptionFormatter.Builder} to use to format options in the table. */ + private OptionFormatter.Builder optionFormatBuilder = defaultOptionFormatterBuilder(); + + /** The string to separate option groups with */ + private String optionGroupSeparator = DEFAULT_OPTION_GROUP_SEPARATOR; + + /** + * Constructs a new instace. + * <p> + * Sets {@code showSince} to {@code true}. + * </p> + */ + protected Builder() { + // empty + } + + /** + * Returns this instance cast to {@code B}. + * + * @return this instance cast to {@code B}. + */ + @SuppressWarnings("unchecked") + protected B asThis() { + return (B) this; + } + + protected OptionFormatter.Builder defaultOptionFormatterBuilder() { + return new OptionFormatter.Builder(); + } + + protected TextHelpAppendable defaultTextHelpAppendable() { + return new TextHelpAppendable(System.out); + } + + protected Comparator<Option> getComparator() { + return comparator; + } + + protected HelpAppendable getHelpAppendable() { + return helpAppendable; + } + + protected OptionFormatter.Builder getOptionFormatBuilder() { + return optionFormatBuilder; + } + + protected String getOptionGroupSeparator() { + return optionGroupSeparator; + } + + /** + * Sets the comparator to use for sorting options. If set to {@code null} no sorting is performed. + * + * @param comparator The comparator to use for sorting options. + * @return this + */ + public B setComparator(final Comparator<Option> comparator) { + this.comparator = comparator; + return asThis(); + } + + /** + * Sets the {@link HelpAppendable}. + * + * @param helpAppendable the {@link HelpAppendable} to use. + * @return this + */ + public B setHelpAppendable(final HelpAppendable helpAppendable) { + this.helpAppendable = helpAppendable != null ? helpAppendable : defaultTextHelpAppendable(); + return asThis(); + } + + /** + * Sets the {@link OptionFormatter.Builder}. + * + * @param optionFormatBuilder the {@link OptionFormatter.Builder} to use. + * @return this + */ + public B setOptionFormatBuilder(final OptionFormatter.Builder optionFormatBuilder) { + this.optionFormatBuilder = optionFormatBuilder != null ? optionFormatBuilder : defaultOptionFormatterBuilder(); + return asThis(); + } + + /** + * Sets the OptionGroup separator. Normally " | " or something similar to denote that only one option may be chosen. + * + * @param optionGroupSeparator the string to separate option group elements with. + * @return this + */ + public B setOptionGroupSeparator(final String optionGroupSeparator) { + this.optionGroupSeparator = Util.defaultValue(optionGroupSeparator, ""); + return asThis(); + } + + } /** * The default comparator for {@link Option} implementations. */ public static final Comparator<Option> DEFAULT_COMPARATOR = (opt1, opt2) -> opt1.getKey().compareToIgnoreCase(opt2.getKey()); + /** + * The default separator between {@link OptionGroup} elements. + */ + public static final String DEFAULT_OPTION_GROUP_SEPARATOR = " | "; + + /** The string to display at the beginning of the usage statement */ + public static final String DEFAULT_SYNTAX_PREFIX = "usage: "; + + /** The comparator for sorting {@link Option} collections */ + protected Comparator<Option> comparator; /** * The {@link HelpAppendable} that produces the final output. */ @@ -60,17 +175,15 @@ public abstract class AbstractHelpFormatter { * The OptionFormatter.Builder used to display options within the help page */ protected final OptionFormatter.Builder optionFormatBuilder; + + /** The separator between {@link OptionGroup} components. */ + protected final String optionGroupSeparator; + /** * The phrase printed before the syntax line. */ protected String syntaxPrefix = DEFAULT_SYNTAX_PREFIX; - /** The comparator for sorting {@link Option} collections */ - protected Comparator<Option> comparator; - - /** The separator between {@link OptionGroup} components. */ - protected final String optionGroupSeparator; - /** * Constructs the base formatter. * @@ -148,9 +261,9 @@ public abstract class AbstractHelpFormatter { throw new IllegalArgumentException("cmdLineSyntax not provided"); } if (autoUsage) { - helpAppendable.appendParagraph(format("%s %s %s", syntaxPrefix, cmdLineSyntax, toSyntaxOptions(options))); + helpAppendable.appendParagraph(String.format("%s %s %s", syntaxPrefix, cmdLineSyntax, toSyntaxOptions(options))); } else { - helpAppendable.appendParagraph(format("%s %s", syntaxPrefix, cmdLineSyntax)); + helpAppendable.appendParagraph(String.format("%s %s", syntaxPrefix, cmdLineSyntax)); } if (!Util.isEmpty(header)) { helpAppendable.appendParagraph(header); diff --git a/src/main/java/org/apache/commons/cli/help/FilterHelpAppendable.java b/src/main/java/org/apache/commons/cli/help/FilterHelpAppendable.java index d37f7913..222ec903 100644 --- a/src/main/java/org/apache/commons/cli/help/FilterHelpAppendable.java +++ b/src/main/java/org/apache/commons/cli/help/FilterHelpAppendable.java @@ -49,19 +49,19 @@ public abstract class FilterHelpAppendable implements HelpAppendable { } @Override - public Appendable append(final char ch) throws IOException { + public FilterHelpAppendable append(final char ch) throws IOException { output.append(ch); return this; } @Override - public Appendable append(final CharSequence text) throws IOException { + public FilterHelpAppendable append(final CharSequence text) throws IOException { output.append(text); return this; } @Override - public Appendable append(final CharSequence csq, final int start, final int end) throws IOException { + public FilterHelpAppendable append(final CharSequence csq, final int start, final int end) throws IOException { output.append(csq, start, end); return this; } diff --git a/src/main/java/org/apache/commons/cli/help/HelpFormatter.java b/src/main/java/org/apache/commons/cli/help/HelpFormatter.java index 89ddb98c..91c6c8ac 100644 --- a/src/main/java/org/apache/commons/cli/help/HelpFormatter.java +++ b/src/main/java/org/apache/commons/cli/help/HelpFormatter.java @@ -19,7 +19,6 @@ package org.apache.commons.cli.help; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import org.apache.commons.cli.Option; @@ -71,22 +70,10 @@ public class HelpFormatter extends AbstractHelpFormatter { * <li>optionFormatter.Builder = the default {@link OptionFormatter.Builder}</li> * </ul> */ - public static class Builder { + public static class Builder extends AbstractHelpFormatter.Builder<Builder, HelpFormatter> { /** If {@code true} show the "Since" column, otherwise ignore it. */ - private boolean showSince; - - /** The {@link HelpAppendable} to use */ - private HelpAppendable helpAppendable; - - /** The {@link OptionFormatter.Builder} to use to format options in the table. */ - private OptionFormatter.Builder optionFormatBuilder; - - /** The string to separate option groups with */ - private String optionGroupSeparator; - - /** The comparator to sort lists of options */ - private Comparator<Option> comparator; + private boolean showSince = true; /** * Constructs a new instace. @@ -94,64 +81,8 @@ public class HelpFormatter extends AbstractHelpFormatter { * Sets {@code showSince} to {@code true}. * </p> */ - public Builder() { - showSince = true; - comparator = DEFAULT_COMPARATOR; - optionGroupSeparator = DEFAULT_OPTION_GROUP_SEPARATOR; - } - - /** - * Constructs the {@link HelpFormatter}. - * - * @return this. - */ - public HelpFormatter build() { - validate(); - return new HelpFormatter(this); - } - - /** - * Sets the comparator to use for sorting opitons. If set to {@code null} no sorting is performed. - * - * @param comparator The comparator to use for sorting opitons. - * @return this - */ - public Builder setComparator(final Comparator<Option> comparator) { - this.comparator = comparator; - return this; - } - - /** - * Sets the {@link OptionFormatter.Builder}. - * - * @param optionFormatBuilder the {@link OptionFormatter.Builder} to use. - * @return this - */ - public Builder setOptionFormatBuilder(final OptionFormatter.Builder optionFormatBuilder) { - this.optionFormatBuilder = optionFormatBuilder; - return this; - } - - /** - * Sets the OptionGroup separator. Normally " | " or something similar to denote that only one option may be chosen. - * - * @param optionGroupSeparator the string to separate option group elements with. - * @return this - */ - public Builder setOptionGroupSeparator(final String optionGroupSeparator) { - this.optionGroupSeparator = Util.defaultValue(optionGroupSeparator, ""); - return this; - } - - /** - * Sets the {@link HelpAppendable}. - * - * @param helpAppendable the {@link HelpAppendable} to use. - * @return this - */ - public Builder setSerializer(final HelpAppendable helpAppendable) { - this.helpAppendable = helpAppendable; - return this; + protected Builder() { + // empty } /** @@ -165,19 +96,9 @@ public class HelpFormatter extends AbstractHelpFormatter { return this; } - /** - * Performs a sanity check and sets default values if they are not set. - * - * @return this. - */ - private Builder validate() { - if (helpAppendable == null) { - helpAppendable = new TextHelpAppendable(System.out); - } - if (optionFormatBuilder == null) { - optionFormatBuilder = new OptionFormatter.Builder(); - } - return this; + @Override + public HelpFormatter get() { + return new HelpFormatter(this); } } @@ -187,44 +108,31 @@ public class HelpFormatter extends AbstractHelpFormatter { /** Default padding to the left of each line */ public static final int DEFAULT_LEFT_PAD = 1; - /** Number of space characters to be prefixed to each description line */ - public static final int DEFAULT_INDENT = 3; - /** The default number of spaces between columns in the options table */ public static final int DEFAULT_COLUMN_SPACING = 5; - /** If {@code true} show the "Since" column, otherwise ignore it. */ - private final boolean showSince; - /** - * Constructs a new instance using the default {@link Builder}. + * Constructs a new builder. * - * @see Builder + * @return a new builder. */ - public HelpFormatter() { - this(new Builder().validate()); + public static Builder builder() { + return new Builder(); } + /** If {@code true} show the "Since" column, otherwise ignore it. */ + private final boolean showSince; + /** * Constructs the Help formatter. * * @param builder the Builder to build from. */ - private HelpFormatter(final Builder builder) { - super(builder.helpAppendable, builder.optionFormatBuilder, builder.comparator, builder.optionGroupSeparator); - + protected HelpFormatter(final Builder builder) { + super(builder.getHelpAppendable(), builder.getOptionFormatBuilder(), builder.getComparator(), builder.getOptionGroupSeparator()); this.showSince = builder.showSince; } - /** - * Convenience constructor to create an instance using the specified {@link HelpAppendable} and the remaining default {@link Builder}. - * - * @param helpAppendable the {@link HelpAppendable} to use. - */ - public HelpFormatter(final HelpAppendable helpAppendable) { - this(new Builder().setSerializer(helpAppendable).validate()); - } - /** * Gets the table definition for the options. * @@ -234,7 +142,7 @@ public class HelpFormatter extends AbstractHelpFormatter { @Override public TableDefinition getTableDefinition(final Iterable<Option> options) { // set up the base TextStyle for the columns configured for the Option opt and arg values.. - final TextStyle.Builder builder = new TextStyle.Builder().setAlignment(TextStyle.Alignment.LEFT).setIndent(DEFAULT_LEFT_PAD).setScalable(false); + final TextStyle.Builder builder = TextStyle.builder().setAlignment(TextStyle.Alignment.LEFT).setIndent(DEFAULT_LEFT_PAD).setScalable(false); final List<TextStyle> styles = new ArrayList<>(); styles.add(builder.get()); // set up showSince column @@ -246,7 +154,6 @@ public class HelpFormatter extends AbstractHelpFormatter { // set up the description column. builder.setAlignment(TextStyle.Alignment.LEFT); styles.add(builder.get()); - // setup the rows for the table. final List<List<String>> rows = new ArrayList<>(); final StringBuilder sb = new StringBuilder(); @@ -270,9 +177,7 @@ public class HelpFormatter extends AbstractHelpFormatter { row.add(formatter.getDescription()); rows.add(row); } - // return the TableDefinition with the proper column headers. - return showSince ? TableDefinition.from("", styles, Arrays.asList("Options", "Since", "Description"), rows) - : TableDefinition.from("", styles, Arrays.asList("Options", "Description"), rows); + return TableDefinition.from("", styles, showSince ? Arrays.asList("Options", "Since", "Description") : Arrays.asList("Options", "Description"), rows); } } diff --git a/src/main/java/org/apache/commons/cli/help/OptionFormatter.java b/src/main/java/org/apache/commons/cli/help/OptionFormatter.java index 182bd9b8..66313ecf 100644 --- a/src/main/java/org/apache/commons/cli/help/OptionFormatter.java +++ b/src/main/java/org/apache/commons/cli/help/OptionFormatter.java @@ -19,6 +19,7 @@ package org.apache.commons.cli.help; import java.util.Arrays; import java.util.function.BiFunction; import java.util.function.Function; +import java.util.function.Supplier; import org.apache.commons.cli.DeprecatedAttributes; import org.apache.commons.cli.Option; @@ -33,7 +34,7 @@ public final class OptionFormatter { /** * Builds instances of {@link OptionFormatter}. */ - public static final class Builder { + public static final class Builder implements Supplier<OptionFormatter> { /** The argument name delimiters */ private final String[] argNameDelimiters; @@ -216,6 +217,12 @@ public final class OptionFormatter { public String toArgName(final String argName) { return argNameDelimiters[0] + Util.defaultValue(argName, "") + argNameDelimiters[1]; } + + @Override + public OptionFormatter get() { + // TODO Auto-generated method stub + return null; + } } /** The default delimiters for optional arguments */ @@ -291,7 +298,7 @@ public final class OptionFormatter { * @return an OptionFormatter for the specified @{code option}. */ public static OptionFormatter from(final Option option) { - return new OptionFormatter.Builder().build(option); + return new Builder().build(option); } /** diff --git a/src/main/java/org/apache/commons/cli/help/TableDefinition.java b/src/main/java/org/apache/commons/cli/help/TableDefinition.java index 2cfb37d1..dea550b7 100644 --- a/src/main/java/org/apache/commons/cli/help/TableDefinition.java +++ b/src/main/java/org/apache/commons/cli/help/TableDefinition.java @@ -38,10 +38,10 @@ public interface TableDefinition { /** * A helper function to create a table instance from the various components. * - * @param caption The caption, May be {@code null} + * @param caption The caption, may be {@code null}. * @param columnStyle a list of TextStyle elements defining the columns. * @param headers the list of column headers. - * @param rows a collection of Rows. + * @param rows a collection of rows. * @return A TableDefinition returning the parameters as appropriate. */ static TableDefinition from(final String caption, final List<TextStyle> columnStyle, final List<String> headers, final Iterable<List<String>> rows) { @@ -53,7 +53,7 @@ public interface TableDefinition { } @Override - public List<TextStyle> columnStyle() { + public List<TextStyle> columnTextStyles() { return columnStyle; } @@ -81,7 +81,7 @@ public interface TableDefinition { * * @return the list of TextStyles. */ - List<TextStyle> columnStyle(); + List<TextStyle> columnTextStyles(); /** * Gets the list of header strings. One for each column in order. diff --git a/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java b/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java index 922ac61e..009da692 100644 --- a/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java +++ b/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java @@ -20,7 +20,9 @@ import static java.lang.String.format; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -34,55 +36,45 @@ import java.util.Set; */ public class TextHelpAppendable extends FilterHelpAppendable { - /** Default number of characters per line */ + /** The default number of characters per line: {@value}. */ public static final int DEFAULT_WIDTH = 74; - /** Default padding to the left of each line */ + /** The default padding to the left of each line: {@value}. */ public static final int DEFAULT_LEFT_PAD = 1; - /** Number of space characters to be prefixed to each description line */ + /** The number of space characters to be prefixed to each description line: {@value}. */ public static final int DEFAULT_INDENT = 3; - /** Number of space characters before a list continuation line */ + /** The number of space characters before a list continuation line: {@value}. */ public static final int DEFAULT_LIST_INDENT = 7; - /** A blank line in the output */ + /** A blank line in the output: {@value}. */ private static final String BLANK_LINE = ""; - /** An array of chars that are breaks in text */ + /** The set of characters that are breaks in text. */ // @formatter:off - private static final char[] BREAK_CHARS = {'\t', '\n', '\f', '\r', - Character.LINE_SEPARATOR, - Character.PARAGRAPH_SEPARATOR, - '\u000B', // VERTICAL TABULATION. - '\u001C', // FILE SEPARATOR. - '\u001D', // GROUP SEPARATOR. - '\u001E', // RECORD SEPARATOR. - '\u001F', // UNIT SEPARATOR. - }; - // @formatter:off - - /** The list of characters that are breaks in text. */ - private static final Set<Character> BREAK_CHAR_SET = new HashSet<>(); - - static { - for (final char c : BREAK_CHARS) { - BREAK_CHAR_SET.add(c); - } - } + private static final Set<Character> BREAK_CHAR_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList('\t', '\n', '\f', '\r', + (char) Character.LINE_SEPARATOR, + (char) Character.PARAGRAPH_SEPARATOR, + '\u000b', // VERTICAL TABULATION. + '\u001c', // FILE SEPARATOR. + '\u001d', // GROUP SEPARATOR. + '\u001e', // RECORD SEPARATOR. + '\u001f' // UNIT SEPARATOR. + ))); + // @formatter:on /** - * Finds the next text wrap position after {@code startPos} for the text in {@code text} with the column width - * {@code width}. The wrap point is the last position before startPos+width having a whitespace character (space, - * \n, \r). If there is no whitespace character before startPos+width, it will return startPos+width. + * Finds the next text wrap position after {@code startPos} for the text in {@code text} with the column width {@code width}. The wrap point is the last + * position before startPos+width having a whitespace character (space, \n, \r). If there is no whitespace character before startPos+width, it will return + * startPos+width. * - * @param text The text being searched for the wrap position - * @param width width of the wrapped text + * @param text The text being searched for the wrap position + * @param width width of the wrapped text * @param startPos position from which to start the lookup whitespace character * @return position on which the text must be wrapped or @{code text.length()} if the wrap position is at the end of the text. - * @since 1.10.0 */ - public static int findWrapPos(final CharSequence text, final int width, final int startPos) { + public static int indexOfWrap(final CharSequence text, final int width, final int startPos) { if (width < 1) { throw new IllegalArgumentException("Width must be greater than 0"); } @@ -95,7 +87,6 @@ public class TextHelpAppendable extends FilterHelpAppendable { return idx; } } - if (startPos + width >= text.length()) { return text.length(); } @@ -112,7 +103,7 @@ public class TextHelpAppendable extends FilterHelpAppendable { } /** Defines the TextStyle for paragraph, and associated output formats. */ - private final TextStyle.Builder styleBuilder; + private final TextStyle.Builder textStyleBuilder; /** * Constructs an appendable filter built on top of the specified underlying appendable. @@ -122,32 +113,37 @@ public class TextHelpAppendable extends FilterHelpAppendable { */ public TextHelpAppendable(final Appendable output) { super(output); - styleBuilder = new TextStyle.Builder().setMaxWidth(DEFAULT_WIDTH) - .setLeftPad(DEFAULT_LEFT_PAD).setIndent(DEFAULT_INDENT); + // @formatter:off + textStyleBuilder = TextStyle.builder() + .setMaxWidth(DEFAULT_WIDTH) + .setLeftPad(DEFAULT_LEFT_PAD) + .setIndent(DEFAULT_INDENT); + // @formatter:on } /** * Adjust the table format. * <p> - * Given the width of the page and the size of the table attempt to resize the columns to fit the page width - * if necessary. Adjustments are made as follows: + * Given the width of the page and the size of the table attempt to resize the columns to fit the page width if necessary. Adjustments are made as follows: * </p> * <ul> - * <li>The minimum size for a column may not be smaller than the length of the column header</li> - * <li>The maximum size is set to the maximum of the length of the header or the longest line length.</li> - * <li>If the total size of the columns is greater than the page wight, adjust the size of VARIABLE columns - * to attempt reduce the width to the the maximum size. + * <li>The minimum size for a column may not be smaller than the length of the column header</li> + * <li>The maximum size is set to the maximum of the length of the header or the longest line length.</li> + * <li>If the total size of the columns is greater than the page wight, adjust the size of VARIABLE columns to attempt reduce the width to the the maximum + * size. * </ul> - * <p>Note: it is possible for the size of the columns to exceed the declared page width. In this case the table - * will extend beyond the desired page width.</p> + * <p> + * Note: it is possible for the size of the columns to exceed the declared page width. In this case the table will extend beyond the desired page width. + * </p> + * * @param table the table to adjust. * @return a new TableDefinition with adjusted values. */ protected TableDefinition adjustTableFormat(final TableDefinition table) { final List<TextStyle.Builder> styleBuilders = new ArrayList<>(); - for (int i = 0; i < table.columnStyle().size(); i++) { - final TextStyle style = table.columnStyle().get(i); - final TextStyle.Builder builder = new TextStyle.Builder(style); + for (int i = 0; i < table.columnTextStyles().size(); i++) { + final TextStyle style = table.columnTextStyles().get(i); + final TextStyle.Builder builder = TextStyle.builder(style); styleBuilders.add(builder); final String header = table.headers().get(i); @@ -164,10 +160,9 @@ public class TextHelpAppendable extends FilterHelpAppendable { } } } - // calculate the total width. int calcWidth = 0; - int adjustedMaxWidth = styleBuilder.getMaxWidth(); + int adjustedMaxWidth = textStyleBuilder.getMaxWidth(); for (final TextStyle.Builder builder : styleBuilders) { adjustedMaxWidth -= builder.getLeftPad(); if (builder.isScalable()) { @@ -176,7 +171,6 @@ public class TextHelpAppendable extends FilterHelpAppendable { adjustedMaxWidth -= builder.getMaxWidth(); } } - // rescale if necessary if (calcWidth > adjustedMaxWidth) { final double fraction = adjustedMaxWidth * 1.0 / calcWidth; @@ -194,7 +188,6 @@ public class TextHelpAppendable extends FilterHelpAppendable { // adjust by removing the padding as it was not accounted for above. styles.add(builder.get()); } - return TableDefinition.from(table.caption(), styles, table.headers(), table.rows()); } @@ -204,9 +197,9 @@ public class TextHelpAppendable extends FilterHelpAppendable { if (level < 1) { throw new IllegalArgumentException("level must be at least 1"); } - final char[] fillChars = {'=', '%', '+', '_'}; + final char[] fillChars = { '=', '%', '+', '_' }; final int idx = Math.min(level, fillChars.length) - 1; - final TextStyle style = styleBuilder.get(); + final TextStyle style = textStyleBuilder.get(); final Queue<String> queue = makeColumnQueue(text, style); queue.add(Util.repeatSpace(style.getLeftPad()) + Util.repeat(Math.min(text.length(), style.getMaxWidth()), fillChars[idx])); queue.add(BLANK_LINE); @@ -217,12 +210,12 @@ public class TextHelpAppendable extends FilterHelpAppendable { @Override public void appendList(final boolean ordered, final Collection<CharSequence> list) throws IOException { if (list != null && !list.isEmpty()) { - final TextStyle.Builder builder = new TextStyle.Builder().setLeftPad(styleBuilder.getLeftPad()).setIndent(DEFAULT_LIST_INDENT); + final TextStyle.Builder builder = TextStyle.builder().setLeftPad(textStyleBuilder.getLeftPad()).setIndent(DEFAULT_LIST_INDENT); int i = 1; for (final CharSequence line : list) { - final String entry = ordered ? format(" %s. %s", i++, Util.defaultValue(line, BLANK_LINE)) : - format(" * %s", Util.defaultValue(line, BLANK_LINE)); - builder.setMaxWidth(Math.min(styleBuilder.getMaxWidth(), entry.length())); + final String entry = ordered ? format(" %s. %s", i++, Util.defaultValue(line, BLANK_LINE)) + : format(" * %s", Util.defaultValue(line, BLANK_LINE)); + builder.setMaxWidth(Math.min(textStyleBuilder.getMaxWidth(), entry.length())); printQueue(makeColumnQueue(entry, builder.get())); } output.append(System.lineSeparator()); @@ -232,7 +225,7 @@ public class TextHelpAppendable extends FilterHelpAppendable { @Override public void appendParagraph(final CharSequence paragraph) throws IOException { if (!Util.isEmpty(paragraph)) { - final Queue<String> queue = makeColumnQueue(paragraph, styleBuilder.get()); + final Queue<String> queue = makeColumnQueue(paragraph, textStyleBuilder.get()); queue.add(BLANK_LINE); printQueue(queue); } @@ -243,23 +236,21 @@ public class TextHelpAppendable extends FilterHelpAppendable { final TableDefinition table = adjustTableFormat(rawTable); // write the table appendParagraph(table.caption()); - final List<TextStyle> headerStyles = new ArrayList<>(); - for (final TextStyle style : table.columnStyle()) { - headerStyles.add(new TextStyle.Builder(style).setAlignment(TextStyle.Alignment.CENTER).get()); + for (final TextStyle style : table.columnTextStyles()) { + headerStyles.add(TextStyle.builder(style).setAlignment(TextStyle.Alignment.CENTER).get()); } writeColumnQueues(makeColumnQueues(table.headers(), headerStyles), headerStyles); for (final List<String> row : table.rows()) { - writeColumnQueues(makeColumnQueues(row, table.columnStyle()), table.columnStyle()); + writeColumnQueues(makeColumnQueues(row, table.columnTextStyles()), table.columnTextStyles()); } - output.append(System.lineSeparator()); } @Override public void appendTitle(final CharSequence title) throws IOException { if (!Util.isEmpty(title)) { - final TextStyle style = styleBuilder.get(); + final TextStyle style = textStyleBuilder.get(); final Queue<String> queue = makeColumnQueue(title, style); queue.add(Util.repeatSpace(style.getLeftPad()) + Util.repeat(Math.min(title.length(), style.getMaxWidth()), '#')); queue.add(BLANK_LINE); @@ -269,41 +260,45 @@ public class TextHelpAppendable extends FilterHelpAppendable { /** * Gets the indent for the output. + * * @return the indent ofr the page. */ public int getIndent() { - return styleBuilder.getIndent(); + return textStyleBuilder.getIndent(); } /** * Returns the left padding for the output. + * * @return The left padding for the output. */ public int getLeftPad() { - return styleBuilder.getLeftPad(); + return textStyleBuilder.getLeftPad(); } /** * Gets the maximum width for the output + * * @return the maximum width for the output. */ public int getMaxWidth() { - return styleBuilder.getMaxWidth(); + return textStyleBuilder.getMaxWidth(); } /** * Gets the style builder used to format text that is not otherwise formatted. + * * @return The style builder used to format text that is not otherwise formatted. */ - public TextStyle.Builder getStyleBuilder() { - return styleBuilder; + public TextStyle.Builder getTextStyleBuilder() { + return textStyleBuilder; } /** - * Creates a queue comprising strings extracted from columnData where the alignment and length are determined - * by the style. + * Creates a queue comprising strings extracted from columnData where the alignment and length are determined by the style. + * * @param columnData The string to wrap - * @param style The TextStyle to guide the wrapping. + * @param style The TextStyle to guide the wrapping. * @return A queue of the string wrapped. */ protected Queue<String> makeColumnQueue(final CharSequence columnData, final TextStyle style) { @@ -315,7 +310,7 @@ public class TextHelpAppendable extends FilterHelpAppendable { final int wrappedMaxWidth = style.getMaxWidth() - indent.length(); while (wrapPos < columnData.length()) { final int workingWidth = wrapPos == 0 ? style.getMaxWidth() : wrappedMaxWidth; - nextPos = findWrapPos(columnData, workingWidth, wrapPos); + nextPos = indexOfWrap(columnData, workingWidth, wrapPos); final CharSequence working = columnData.subSequence(wrapPos, nextPos); result.add(lpad + style.pad(wrapPos > 0, working)); wrapPos = Util.indexOfNonWhitespace(columnData, nextPos); @@ -325,10 +320,11 @@ public class TextHelpAppendable extends FilterHelpAppendable { } /** - * For each column in the {@code columnData} apply the associated {@link TextStyle} and generated a queue of strings - * that are the maximum size of the column + the left pad. + * For each column in the {@code columnData} apply the associated {@link TextStyle} and generated a queue of strings that are the maximum size of the column + * + the left pad. + * * @param columnData The column data to output. - * @param styles the styles to apply. + * @param styles the styles to apply. * @return A list of queues of strings that represent each column in the table. */ protected List<Queue<String>> makeColumnQueues(final List<String> columnData, final List<TextStyle> styles) { @@ -341,6 +337,7 @@ public class TextHelpAppendable extends FilterHelpAppendable { /** * Print a queue of text. + * * @param queue the queue of text to print. * @throws IOException on output error. */ @@ -352,16 +349,18 @@ public class TextHelpAppendable extends FilterHelpAppendable { /** * Print wrapped text using the TextHelpAppendable output style. + * * @param text the text to wrap * @throws IOException on output error. */ public void printWrapped(final String text) throws IOException { - printQueue(makeColumnQueue(text, this.styleBuilder.get())); + printQueue(makeColumnQueue(text, this.textStyleBuilder.get())); } /** * Print wrapped text. - * @param text the text to wrap + * + * @param text the text to wrap * @param style the style for the wrapped text. * @throws IOException on output error. */ @@ -371,7 +370,8 @@ public class TextHelpAppendable extends FilterHelpAppendable { /** * Resizes an original width based on the fractional size it should be. - * @param orig the original size. + * + * @param orig the original size. * @param fraction the fractional adjustment. * @return the resized value. */ @@ -381,7 +381,8 @@ public class TextHelpAppendable extends FilterHelpAppendable { /** * Resize a TextBuilder based on the fractional size. - * @param builder the builder to adjust. + * + * @param builder the builder to adjust. * @param fraction the fractional size (e.g. percentage of the current size) that the builder should be. * @return the builder with the maximum width and indent values resized. */ @@ -399,39 +400,42 @@ public class TextHelpAppendable extends FilterHelpAppendable { /** * Sets the indent for the output. + * * @param indent the indent used for paragraphs. */ public void setIndent(final int indent) { - styleBuilder.setIndent(indent); + textStyleBuilder.setIndent(indent); } /** * Sets the left padding: the number of characters from the left edge to start output. + * * @param leftPad the left padding. */ public void setLeftPad(final int leftPad) { - styleBuilder.setLeftPad(leftPad); + textStyleBuilder.setLeftPad(leftPad); } /** * Sets the maximum width for the output. + * * @param maxWidth the maximum width for the output. */ public void setMaxWidth(final int maxWidth) { - styleBuilder.setMaxWidth(maxWidth); + textStyleBuilder.setMaxWidth(maxWidth); } /** - * Write one line from each of the {@code columnQueues} until all the queues are exhausted. - * If an exhausted queue is encountered while other queues continue to have content the exhausted queue will - * produce empty text for the output width of the column (maximum width + left pad). + * Write one line from each of the {@code columnQueues} until all the queues are exhausted. If an exhausted queue is encountered while other queues continue + * to have content the exhausted queue will produce empty text for the output width of the column (maximum width + left pad). + * * @param columnQueues the List of queues that represent the columns of data. - * @param styles the TextStyle for each column. + * @param styles the TextStyle for each column. * @throws IOException on output error. */ protected void writeColumnQueues(final List<Queue<String>> columnQueues, final List<TextStyle> styles) throws IOException { boolean moreData = true; - final String lPad = Util.repeatSpace(styleBuilder.get().getLeftPad()); + final String lPad = Util.repeatSpace(textStyleBuilder.get().getLeftPad()); while (moreData) { output.append(lPad); moreData = false; diff --git a/src/main/java/org/apache/commons/cli/help/TextStyle.java b/src/main/java/org/apache/commons/cli/help/TextStyle.java index 28a51aa1..de8d7dff 100644 --- a/src/main/java/org/apache/commons/cli/help/TextStyle.java +++ b/src/main/java/org/apache/commons/cli/help/TextStyle.java @@ -41,12 +41,19 @@ public final class TextStyle { } /** - * The builder for the TextStyle + * The builder for the TextStyle. The default values are: + * <ul> + * <li>alignment = LEFT</li> + * <li>leftPad = 0</li> + * <li>scaling = VARIABLE</li> + * <li>minWidth = 0</li> + * <li>maxWidth = UNSET_MAX_WIDTH</li> + * </ul> */ public static final class Builder implements Supplier<TextStyle> { /** The alignment. */ - private Alignment alignment; + private Alignment alignment = Alignment.LEFT; /** The left padding. */ private int leftPad; @@ -55,13 +62,13 @@ public final class TextStyle { private int indent; /** The scalable flag. Identifies text blocks that can be made narrower or wider as needed by the HelpAppendable. */ - private boolean scalable; + private boolean scalable = true; /** The minimum width. */ private int minWidth; /** The maximum width. */ - private int maxWidth; + private int maxWidth = UNSET_MAX_WIDTH; /** * Constructs a new instance. The default values are: @@ -73,18 +80,23 @@ public final class TextStyle { * <li>maxWidth = UNSET_MAX_WIDTH</li> * </ul> */ - public Builder() { - alignment = Alignment.LEFT; - scalable = true; - maxWidth = UNSET_MAX_WIDTH; + private Builder() { } /** - * Constructs a builder from an existing TextStyle + * Constructs a builder from an existing TextStyle. The default values are: + * <ul> + * <li>alignment = LEFT</li> + * <li>leftPad = 0</li> + * <li>scaling = VARIABLE</li> + * <li>minWidth = 0</li> + * <li>maxWidth = UNSET_MAX_WIDTH</li> + * </ul> + * * * * @param style the TextStyle to set all values from. */ - public Builder(final TextStyle style) { + private Builder(final TextStyle style) { this.alignment = style.alignment; this.leftPad = style.leftPad; this.indent = style.indent; @@ -216,7 +228,26 @@ public final class TextStyle { /** * The default style as generated by the default Builder. */ - public static final TextStyle DEFAULT = new Builder().get(); + public static final TextStyle DEFAULT = builder().get(); + + /** + * Creates a new builder. + * + * @return a new builder. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Creates a new builder. + * + * @param textStyle The new builder values are copied from the given TextStyle. + * @return a new builder. + */ + public static Builder builder(final TextStyle textStyle) { + return new Builder(textStyle); + } /** The alignment. */ private final Alignment alignment; diff --git a/src/main/java/org/apache/commons/cli/help/Util.java b/src/main/java/org/apache/commons/cli/help/Util.java index 4a2d1415..ea947179 100644 --- a/src/main/java/org/apache/commons/cli/help/Util.java +++ b/src/main/java/org/apache/commons/cli/help/Util.java @@ -24,6 +24,11 @@ import java.util.Arrays; */ final class Util { + /** + * A special value for index not found. + */ + private static final int NOT_FOUND = -1; + /** * Returns the {@code defaultValue} if {@code str} is empty. * @@ -45,14 +50,14 @@ final class Util { */ static int indexOfNonWhitespace(final CharSequence text, final int startPos) { if (isEmpty(text)) { - return -1; + return NOT_FOUND; } // the line ends before the max wrap pos or a new line char found int idx = startPos; while (idx < text.length() && isWhitespace(text.charAt(idx))) { idx++; } - return idx < text.length() ? idx : -1; + return idx < text.length() ? idx : NOT_FOUND; } /** @@ -68,7 +73,7 @@ final class Util { /** * Works around https://bugs.java.com/bugdatabase/view_bug?bug_id=8341522 * - * Affected Version: 8,11,17,21,24 + * Affected Version: 8, 11, 17, 21, 24. */ static boolean isWhitespace(final char c) { return Character.isWhitespace(c) || Character.PARAGRAPH_SEPARATOR == c; @@ -78,11 +83,11 @@ final class Util { * Removes the leading whitespace from the specified String. * * @param s The String to remove the leading padding from. - * @return The String of without the leading padding + * @return The String of without the leading padding. */ static String ltrim(final String s) { final int pos = indexOfNonWhitespace(s, 0); - return pos == -1 ? "" : s.substring(pos); + return pos == NOT_FOUND ? "" : s.substring(pos); } /** @@ -103,7 +108,7 @@ final class Util { * * @param len The length of the String of padding to create. * - * @return The String of padding + * @return The String of padding. */ static String repeatSpace(final int len) { return repeat(len, ' '); @@ -113,7 +118,7 @@ final class Util { * Removes the trailing whitespace from the specified String. * * @param s The String to remove the trailing padding from. - * @return The String of without the trailing padding + * @return The String of without the trailing padding. */ static String rtrim(final String s) { if (isEmpty(s)) { diff --git a/src/main/java/org/apache/commons/cli/help/package-info.java b/src/main/java/org/apache/commons/cli/help/package-info.java index 5631db11..80d32c20 100644 --- a/src/main/java/org/apache/commons/cli/help/package-info.java +++ b/src/main/java/org/apache/commons/cli/help/package-info.java @@ -16,18 +16,19 @@ */ /** - * Commons client help production system. + * The help production system. * <p> - * This package contains the classes used by commons-cli to produce the help output. - * In general there are 4 classes that users/developers may be interested in. + * This package contains the classes to produce help output. In general,, there are 4 classes that may interest users. * </p> * <ul> - * <li>HelpFormatter - the class used to produce the help output for most users.</li> - * <li>Scribe - Writes the output in a specific output serialization format (e.g. text, XHTML, Markdown, etc.)</li> - * <li>OptionFormatter - Determines how to format the various data elements in an Option</li> - * <li>TableDefinition - Useful for developers who want to build custom option displays or use the help system to produce - * additional information in the help system</li> + * <li>{@link org.apache.commons.cli.help.HelpFormatter HelpFormatter} - The class used to produce the help output for most users.</li> + * <li>{@link org.apache.commons.cli.help.HelpAppendable HelpAppendable} - Writes the output in a specific output format. For example + * {@link org.apache.commons.cli.help.TextHelpAppendable TextHelpAppendable} for text, other classes for XHTML, Markdown, and so on.</li> + * <li>{@link org.apache.commons.cli.help.OptionFormatter OptionFormatter} - Determines how to format the various data elements in an Option</li> + * <li>{@link org.apache.commons.cli.help.TableDefinition TableDefinition} - Useful for developers who want to build custom option displays or use the help + * system to produce additional information in the help system.</li> * </ul> + * * @since 1.10.0 */ package org.apache.commons.cli.help; diff --git a/src/test/java/org/apache/commons/example/cli/AptHelpAppendable.java b/src/test/java/org/apache/commons/cli/example/AptHelpAppendable.java similarity index 88% rename from src/test/java/org/apache/commons/example/cli/AptHelpAppendable.java rename to src/test/java/org/apache/commons/cli/example/AptHelpAppendable.java index ae155c09..9aff41d9 100644 --- a/src/test/java/org/apache/commons/example/cli/AptHelpAppendable.java +++ b/src/test/java/org/apache/commons/cli/example/AptHelpAppendable.java @@ -14,12 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -package org.apache.commons.example.cli; +package org.apache.commons.cli.example; import static java.lang.String.format; import java.io.IOException; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -51,20 +50,6 @@ public class AptHelpAppendable extends FilterHelpAppendable { ESCAPE_APT = new LookupTranslator(escapeAptMap); } - /** - * Constructs a string of specified length filled with the specified char. - * - * @param len the length of the final string. - * @param fillChar the character to file it will. - * @return A string of specified length filled with the specified char. - * @since 1.10.0 - */ - static String filledString(final int len, final char fillChar) { - final char[] padding = new char[len]; - Arrays.fill(padding, fillChar); - return new String(padding); - } - /** * Constructs an appendable filter built on top of the specified underlying appendable. * @@ -119,8 +104,8 @@ public class AptHelpAppendable extends FilterHelpAppendable { final StringBuilder sb = new StringBuilder("*"); for (int i = 0; i < table.headers().size(); i++) { final String header = table.headers().get(i); - final TextStyle style = table.columnStyle().get(i); - sb.append(filledString(header.length() + 2, '-')); + final TextStyle style = table.columnTextStyles().get(i); + sb.append(StringUtils.repeat('-', header.length() + 2)); switch (style.getAlignment()) { case LEFT: sb.append("+"); @@ -134,7 +119,6 @@ public class AptHelpAppendable extends FilterHelpAppendable { } } final String rowSeparator = System.lineSeparator() + sb.append(System.lineSeparator()); - // output the header line. output.append(sb.toString()); output.append("|"); @@ -142,7 +126,6 @@ public class AptHelpAppendable extends FilterHelpAppendable { output.append(format(" %s |", ESCAPE_APT.translate(header))); } output.append(rowSeparator); - // write the table entries for (final Collection<String> row : table.rows()) { output.append("|"); @@ -151,12 +134,10 @@ public class AptHelpAppendable extends FilterHelpAppendable { } output.append(rowSeparator); } - // write the caption if (StringUtils.isNotEmpty(table.caption())) { output.append(format("%s%n", ESCAPE_APT.translate(table.caption()))); } - output.append(System.lineSeparator()); } } diff --git a/src/test/java/org/apache/commons/example/cli/AptHelpAppendableTest.java b/src/test/java/org/apache/commons/cli/example/AptHelpAppendableTest.java similarity index 96% rename from src/test/java/org/apache/commons/example/cli/AptHelpAppendableTest.java rename to src/test/java/org/apache/commons/cli/example/AptHelpAppendableTest.java index 1f87a35c..6b56af8f 100644 --- a/src/test/java/org/apache/commons/example/cli/AptHelpAppendableTest.java +++ b/src/test/java/org/apache/commons/cli/example/AptHelpAppendableTest.java @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package org.apache.commons.example.cli; +package org.apache.commons.cli.example; import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -55,7 +55,6 @@ public class AptHelpAppendableTest { sb.setLength(0); underTest.appendList(true, Arrays.asList(entries)); assertEquals(format(" [[1]] one%n [[2]] two%n [[3]] three%n%n"), sb.toString()); - sb.setLength(0); underTest.appendList(false, Arrays.asList(entries)); assertEquals(format(" * one%n * two%n * three%n%n"), sb.toString()); @@ -73,13 +72,12 @@ public class AptHelpAppendableTest { final List<TextStyle> styles = Arrays.asList(TextStyle.DEFAULT, TextStyle.DEFAULT, TextStyle.DEFAULT); final String[] headers = { "one", "two", "three" }; // @formatter:off - final List[] rows = { + final List<List<String>> rows = Arrays.asList( Arrays.asList(new String[]{"uno", "dos", "tres"}), Arrays.asList(new String[]{"aon", "dhá", "trí"}), Arrays.asList(new String[]{"واحد", "اثنين", "ثلاثة"}) - }; + ); // @formatter:on - List<String> expected = new ArrayList<>(); expected.add("*-----+-----+-------+"); expected.add("| one | two | three |"); @@ -92,27 +90,23 @@ public class AptHelpAppendableTest { expected.add("*-----+-----+-------+"); expected.add("The caption"); expected.add(""); - - TableDefinition table = TableDefinition.from("The caption", styles, Arrays.asList(headers), Arrays.asList(rows)); + TableDefinition table = TableDefinition.from("The caption", styles, Arrays.asList(headers), rows); sb.setLength(0); underTest.appendTable(table); List<String> actual = IOUtils.readLines(new StringReader(sb.toString())); assertEquals(expected, actual, "full table failed"); - - table = TableDefinition.from(null, styles, Arrays.asList(headers), Arrays.asList(rows)); + table = TableDefinition.from(null, styles, Arrays.asList(headers), rows); expected.remove(9); sb.setLength(0); underTest.appendTable(table); actual = IOUtils.readLines(new StringReader(sb.toString())); assertEquals(expected, actual); - table = TableDefinition.from(null, styles, Arrays.asList(headers), Collections.emptyList()); expected = new ArrayList<>(); expected.add("*-----+-----+-------+"); expected.add("| one | two | three |"); expected.add("*-----+-----+-------+"); expected.add(""); - sb.setLength(0); underTest.appendTable(table); actual = IOUtils.readLines(new StringReader(sb.toString())); diff --git a/src/test/java/org/apache/commons/example/cli/WeirdOptionFormat.java b/src/test/java/org/apache/commons/cli/example/WeirdOptionFormat.java similarity index 95% rename from src/test/java/org/apache/commons/example/cli/WeirdOptionFormat.java rename to src/test/java/org/apache/commons/cli/example/WeirdOptionFormat.java index bb6478ef..7e4ac32f 100644 --- a/src/test/java/org/apache/commons/example/cli/WeirdOptionFormat.java +++ b/src/test/java/org/apache/commons/cli/example/WeirdOptionFormat.java @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package org.apache.commons.example.cli; +package org.apache.commons.cli.example; import java.util.ArrayList; import java.util.Arrays; @@ -33,7 +33,7 @@ public class WeirdOptionFormat implements Function<Iterable<Option>, TableDefini public WeirdOptionFormat() { styles = new ArrayList<>(); - final TextStyle.Builder builder = new TextStyle.Builder(); + final TextStyle.Builder builder = TextStyle.builder(); styles.add(builder.setLeftPad(1).setIndent(3).get()); styles.add(builder.setLeftPad(5).get()); styles.add(builder.get()); @@ -59,7 +59,6 @@ public class WeirdOptionFormat implements Function<Iterable<Option>, TableDefini row.add(option.getDescription()); rows.add(row); } - return TableDefinition.from("", styles, Arrays.asList(headers), rows); } } diff --git a/src/test/java/org/apache/commons/example/cli/XhtmlHelpAppendable.java b/src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendable.java similarity index 98% rename from src/test/java/org/apache/commons/example/cli/XhtmlHelpAppendable.java rename to src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendable.java index 62e85f15..91adca1c 100644 --- a/src/test/java/org/apache/commons/example/cli/XhtmlHelpAppendable.java +++ b/src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendable.java @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package org.apache.commons.example.cli; +package org.apache.commons.cli.example; import static java.lang.String.format; @@ -71,11 +71,9 @@ public class XhtmlHelpAppendable extends FilterHelpAppendable { @Override public void appendTable(final TableDefinition table) throws IOException { output.append(format("<table class='commons_cli_table'>%n")); - if (StringUtils.isNotEmpty(table.caption())) { output.append(format(" <caption>%s</caption>%n", StringEscapeUtils.escapeHtml4(table.caption()))); } - // write the headers if (!table.headers().isEmpty()) { output.append(format(" <tr>%n")); @@ -84,7 +82,6 @@ public class XhtmlHelpAppendable extends FilterHelpAppendable { } output.append(format(" </tr>%n")); } - // write the data for (final List<String> row : table.rows()) { output.append(format(" <tr>%n")); diff --git a/src/test/java/org/apache/commons/example/cli/XhtmlHelpAppendableTest.java b/src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendableTest.java similarity index 96% rename from src/test/java/org/apache/commons/example/cli/XhtmlHelpAppendableTest.java rename to src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendableTest.java index 0a8e5060..11fe840e 100644 --- a/src/test/java/org/apache/commons/example/cli/XhtmlHelpAppendableTest.java +++ b/src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendableTest.java @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package org.apache.commons.example.cli; +package org.apache.commons.cli.example; import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -55,7 +55,6 @@ public class XhtmlHelpAppendableTest { sb.setLength(0); underTest.appendList(true, Arrays.asList(entries)); assertEquals(format("<ol>%n <li>one</li>%n <li>two</li>%n <li>three</li>%n</ol>%n"), sb.toString()); - sb.setLength(0); underTest.appendList(false, Arrays.asList(entries)); assertEquals(format("<ul>%n <li>one</li>%n <li>two</li>%n <li>three</li>%n</ul>%n"), sb.toString()); @@ -73,13 +72,12 @@ public class XhtmlHelpAppendableTest { final List<TextStyle> styles = Arrays.asList(TextStyle.DEFAULT, TextStyle.DEFAULT, TextStyle.DEFAULT); final String[] headers = { "one", "two", "three" }; // @formatter:off - final List[] rows = { + final List<List<String>> rows = Arrays.asList( Arrays.asList(new String[]{"uno", "dos", "tres"}), Arrays.asList(new String[]{"aon", "dhá", "trí"}), Arrays.asList(new String[]{"واحد", "اثنين", "ثلاثة"}) - }; + ); // @formatter:on - List<String> expected = new ArrayList<>(); expected.add("<table class='commons_cli_table'>"); expected.add(" <caption>The caption</caption>"); @@ -104,20 +102,17 @@ public class XhtmlHelpAppendableTest { expected.add(" <td>ثلاثة</td>"); expected.add(" </tr>"); expected.add("</table>"); - - TableDefinition table = TableDefinition.from("The caption", styles, Arrays.asList(headers), Arrays.asList(rows)); + TableDefinition table = TableDefinition.from("The caption", styles, Arrays.asList(headers), rows); sb.setLength(0); underTest.appendTable(table); List<String> actual = IOUtils.readLines(new StringReader(sb.toString())); assertEquals(expected, actual, "full table failed"); - - table = TableDefinition.from(null, styles, Arrays.asList(headers), Arrays.asList(rows)); + table = TableDefinition.from(null, styles, Arrays.asList(headers), rows); expected.remove(1); sb.setLength(0); underTest.appendTable(table); actual = IOUtils.readLines(new StringReader(sb.toString())); assertEquals(expected, actual); - table = TableDefinition.from(null, styles, Arrays.asList(headers), Collections.emptyList()); expected = new ArrayList<>(); expected.add("<table class='commons_cli_table'>"); @@ -127,7 +122,6 @@ public class XhtmlHelpAppendableTest { expected.add(" <th>three</th>"); expected.add(" </tr>"); expected.add("</table>"); - sb.setLength(0); underTest.appendTable(table); actual = IOUtils.readLines(new StringReader(sb.toString())); diff --git a/src/test/java/org/apache/commons/cli/help/HelpFormatterTest.java b/src/test/java/org/apache/commons/cli/help/HelpFormatterTest.java index 3e44f183..df0df3b3 100644 --- a/src/test/java/org/apache/commons/cli/help/HelpFormatterTest.java +++ b/src/test/java/org/apache/commons/cli/help/HelpFormatterTest.java @@ -29,7 +29,7 @@ import java.util.List; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionGroup; import org.apache.commons.cli.Options; -import org.apache.commons.example.cli.XhtmlHelpAppendable; +import org.apache.commons.cli.example.XhtmlHelpAppendable; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; @@ -60,7 +60,7 @@ public class HelpFormatterTest { public void testDefault() { final StringBuilder sb = new StringBuilder(); final TextHelpAppendable serializer = new TextHelpAppendable(sb); - final HelpFormatter formatter = new HelpFormatter(serializer); + final HelpFormatter formatter = HelpFormatter.builder().setHelpAppendable(serializer).get(); assertEquals(serializer, formatter.getSerializer(), "Unexpected helpAppendable tests may fail unexpectedly"); assertEquals(AbstractHelpFormatter.DEFAULT_COMPARATOR, formatter.getComparator(), "Unexpected comparator tests may fail unexpectedly"); assertEquals(AbstractHelpFormatter.DEFAULT_SYNTAX_PREFIX, formatter.getSyntaxPrefix(), "Unexpected syntax prefix tests may fail unexpectedly"); @@ -70,7 +70,7 @@ public class HelpFormatterTest { public void testPrintHelp() throws IOException { final StringBuilder sb = new StringBuilder(); final TextHelpAppendable serializer = new TextHelpAppendable(sb); - HelpFormatter formatter = new HelpFormatter(serializer); + HelpFormatter formatter = HelpFormatter.builder().setHelpAppendable(serializer).get(); final Options options = new Options().addOption(Option.builder("a").since("1853").hasArg().desc("aaaa aaaa aaaa aaaa aaaa").build()); @@ -89,7 +89,7 @@ public class HelpFormatterTest { List<String> actual = IOUtils.readLines(new StringReader(sb.toString())); assertEquals(expected, actual); - formatter = new HelpFormatter.Builder().setShowSince(false).setSerializer(serializer).build(); + formatter = new HelpFormatter.Builder().setShowSince(false).setHelpAppendable(serializer).get(); expected = new ArrayList<>(); expected.add(" usage: commandSyntax [-a <arg>]"); expected.add(""); @@ -148,7 +148,7 @@ public class HelpFormatterTest { public void testPrintHelpXML() throws IOException { final StringBuilder sb = new StringBuilder(); final XhtmlHelpAppendable serializer = new XhtmlHelpAppendable(sb); - final HelpFormatter formatter = new HelpFormatter(serializer); + final HelpFormatter formatter = HelpFormatter.builder().setHelpAppendable(serializer).get(); final Options options = new Options().addOption("a", false, "aaaa aaaa aaaa aaaa aaaa"); @@ -179,7 +179,7 @@ public class HelpFormatterTest { public void testPrintOptions() throws IOException { final StringBuilder sb = new StringBuilder(); final TextHelpAppendable serializer = new TextHelpAppendable(sb); - final HelpFormatter formatter = new HelpFormatter.Builder().setSerializer(serializer).setShowSince(false).build(); + final HelpFormatter formatter = new HelpFormatter.Builder().setHelpAppendable(serializer).setShowSince(false).get(); // help format default column styles // col options description helpAppendable @@ -230,7 +230,7 @@ public class HelpFormatterTest { final HelpFormatter.Builder underTest = new HelpFormatter.Builder(); final OptionFormatter.Builder ofBuilder = new OptionFormatter.Builder().setOptPrefix("Just Another "); underTest.setOptionFormatBuilder(ofBuilder); - final HelpFormatter formatter = underTest.build(); + final HelpFormatter formatter = underTest.get(); final OptionFormatter oFormatter = formatter.getOptionFormatter(Option.builder("thing").build()); assertEquals("Just Another thing", oFormatter.getOpt()); @@ -238,8 +238,8 @@ public class HelpFormatterTest { @Test public void testSetOptionGroupSeparatorTest() { - final HelpFormatter.Builder underTest = new HelpFormatter.Builder().setOptionGroupSeparator(" and "); - final HelpFormatter formatter = underTest.build(); + final HelpFormatter.Builder underTest = HelpFormatter.builder().setOptionGroupSeparator(" and "); + final HelpFormatter formatter = underTest.get(); final String result = formatter.toSyntaxOptions(new OptionGroup().addOption(Option.builder("this").build()).addOption(Option.builder("that").build())); assertTrue(result.contains("-that and -this")); } @@ -248,7 +248,7 @@ public class HelpFormatterTest { public void testSortOptionGroupsTest() { final Options options = getTestGroups(); final List<Option> optList = new ArrayList<>(options.getOptions()); - final HelpFormatter underTest = new HelpFormatter(); + final HelpFormatter underTest = HelpFormatter.builder().get(); final List<Option> expected = new ArrayList<>(); expected.add(optList.get(0)); // because 1 sorts before all long values expected.add(optList.get(1)); @@ -271,7 +271,7 @@ public class HelpFormatterTest { .addOption(Option.builder().longOpt("COpt").hasArg().desc("A COpt description").build()); // @formatter:on - HelpFormatter underTest = new HelpFormatter(); + HelpFormatter underTest = HelpFormatter.builder().get(); final List<Option> expected = new ArrayList<>(); expected.add(options.getOption("a")); expected.add(options.getOption("b")); @@ -281,7 +281,7 @@ public class HelpFormatterTest { expected.set(0, expected.get(2)); expected.set(2, options.getOption("a")); - underTest = new HelpFormatter.Builder().setComparator(AbstractHelpFormatter.DEFAULT_COMPARATOR.reversed()).build(); + underTest = new HelpFormatter.Builder().setComparator(AbstractHelpFormatter.DEFAULT_COMPARATOR.reversed()).get(); assertEquals(expected, underTest.sort(options)); assertEquals(0, underTest.sort(Collections.emptyList()).size(), "empty colleciton should return empty list"); @@ -293,7 +293,7 @@ public class HelpFormatterTest { public void testSyntaxPrefix() { final StringBuilder sb = new StringBuilder(); final TextHelpAppendable serializer = new TextHelpAppendable(sb); - final HelpFormatter formatter = new HelpFormatter(serializer); + final HelpFormatter formatter = HelpFormatter.builder().setHelpAppendable(serializer).get(); formatter.setSyntaxPrefix("Something new"); assertEquals("Something new", formatter.getSyntaxPrefix()); assertEquals(0, sb.length(), "Should not write to output"); @@ -303,7 +303,7 @@ public class HelpFormatterTest { public void testToArgNameTest() { final StringBuilder sb = new StringBuilder(); final TextHelpAppendable serializer = new TextHelpAppendable(sb); - final HelpFormatter formatter = new HelpFormatter(serializer); + final HelpFormatter formatter = HelpFormatter.builder().setHelpAppendable(serializer).get(); assertEquals("<some Arg>", formatter.toArgName("some Arg")); assertEquals("<>", formatter.toArgName("")); @@ -312,7 +312,7 @@ public class HelpFormatterTest { @Test public void testToSyntaxOptionGroupTest() { - final HelpFormatter underTest = new HelpFormatter(); + final HelpFormatter underTest = HelpFormatter.builder().get(); // @formatter:off final OptionGroup group = new OptionGroup() .addOption(Option.builder().option("o").longOpt("one").hasArg().build()) @@ -333,7 +333,7 @@ public class HelpFormatterTest { @Test public void testToSyntaxOptionIterableTest() { - final HelpFormatter underTest = new HelpFormatter(); + final HelpFormatter underTest = HelpFormatter.builder().get(); final List<Option> options = new ArrayList<>(); options.add(Option.builder().option("o").longOpt("one").hasArg().build()); @@ -349,7 +349,7 @@ public class HelpFormatterTest { @Test public void testToSyntaxOptionOptionsTest() { - final HelpFormatter underTest = new HelpFormatter(); + final HelpFormatter underTest = HelpFormatter.builder().get(); Options options = getTestGroups(); assertEquals("[-1 <arg> | --aon <arg> | --uno <arg>] [--dos <arg> | --dó <arg> | --two <arg>] " + "[--three <arg> | --tres <arg> | --trí <arg>]", underTest.toSyntaxOptions(options), "getTestGroup options failed"); diff --git a/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java b/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java index eea7d9d6..d489fff8 100644 --- a/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java +++ b/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java @@ -18,7 +18,6 @@ package org.apache.commons.cli.help; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.BiFunction; @@ -94,7 +93,7 @@ public class OptionFormatterTest { } @Test - public void testAsSyntaxOption() throws IOException { + public void testAsSyntaxOption() { OptionFormatter underTest; Option option = Option.builder().option("o").longOpt("opt").hasArg().build(); diff --git a/src/test/java/org/apache/commons/cli/help/TextHelpAppendableTest.java b/src/test/java/org/apache/commons/cli/help/TextHelpAppendableTest.java index 0bd43f4e..8d32c6d8 100644 --- a/src/test/java/org/apache/commons/cli/help/TextHelpAppendableTest.java +++ b/src/test/java/org/apache/commons/cli/help/TextHelpAppendableTest.java @@ -49,7 +49,7 @@ public final class TextHelpAppendableTest { @Test public void tesstMakeColumnQueue() { final String text = "The quick brown fox jumps over the lazy dog"; - final TextStyle.Builder styleBuilder = new TextStyle.Builder().setMaxWidth(10).setIndent(0).setLeftPad(0); + final TextStyle.Builder styleBuilder = TextStyle.builder().setMaxWidth(10).setIndent(0).setLeftPad(0); Queue<String> expected = new LinkedList<>(); expected.add("The quick "); @@ -101,15 +101,15 @@ public final class TextHelpAppendableTest { // test width smaller than header // @formatter:off final TableDefinition tableDefinition = TableDefinition.from("Testing", - Collections.singletonList(new TextStyle.Builder().setMaxWidth(3).get()), + Collections.singletonList(TextStyle.builder().setMaxWidth(3).get()), Collections.singletonList("header"), // "data" shorter than "header" Collections.singletonList(Collections.singletonList("data")) ); // @formatter:on final TableDefinition actual = underTest.adjustTableFormat(tableDefinition); - assertEquals("header".length(), actual.columnStyle().get(0).getMaxWidth()); - assertEquals("header".length(), actual.columnStyle().get(0).getMinWidth()); + assertEquals("header".length(), actual.columnTextStyles().get(0).getMaxWidth()); + assertEquals("header".length(), actual.columnTextStyles().get(0).getMinWidth()); } @Test @@ -225,20 +225,18 @@ public final class TextHelpAppendableTest { @Test public void testAppendTable() throws IOException { - final TextStyle.Builder styleBuilder = new TextStyle.Builder(); + final TextStyle.Builder styleBuilder = TextStyle.builder(); final List<TextStyle> styles = new ArrayList<>(); styles.add(styleBuilder.setIndent(2).get()); styles.add(styleBuilder.setIndent(0).setLeftPad(5).setAlignment(TextStyle.Alignment.RIGHT).get()); - final String[] headers = { "fox", "time" }; - // @formatter:off - final List[] rows = { + final List<List<String>> rows = Arrays.asList( Arrays.asList("The quick brown fox jumps over the lazy dog", "Now is the time for all good people to come to the aid of their country"), Arrays.asList("Léimeann an sionnach donn gasta thar an madra leisciúil", - "Anois an t-am do na daoine maithe go léir teacht i gcabhair ar a dtír"), - }; + "Anois an t-am do na daoine maithe go léir teacht i gcabhair ar a dtír") + ); // @formatter:on List<String> expected = new ArrayList<>(); @@ -251,14 +249,14 @@ public final class TextHelpAppendableTest { expected.add(" thar an madra leisciúil teacht i gcabhair ar a dtír"); expected.add(""); - TableDefinition table = TableDefinition.from("Common Phrases", styles, Arrays.asList(headers), Arrays.asList(rows)); + TableDefinition table = TableDefinition.from("Common Phrases", styles, Arrays.asList(headers), rows); sb.setLength(0); underTest.setMaxWidth(80); underTest.appendTable(table); List<String> actual = IOUtils.readLines(new StringReader(sb.toString())); assertEquals(expected, actual, "full table failed"); - table = TableDefinition.from(null, styles, Arrays.asList(headers), Arrays.asList(rows)); + table = TableDefinition.from(null, styles, Arrays.asList(headers), rows); expected.remove(1); expected.remove(0); sb.setLength(0); @@ -296,30 +294,30 @@ public final class TextHelpAppendableTest { } @Test - public void testFindWrapPos() { + public void testindexOfWrapPos() { final String testString = "The quick brown fox jumps over\tthe lazy dog"; - assertEquals(9, TextHelpAppendable.findWrapPos(testString, 10, 0), "did not find end of word"); - assertEquals(9, TextHelpAppendable.findWrapPos(testString, 14, 0), "did not backup to end of word"); - assertEquals(15, TextHelpAppendable.findWrapPos(testString, 15, 0), "did not find word at 15"); - assertEquals(15, TextHelpAppendable.findWrapPos(testString, 16, 0)); - assertEquals(30, TextHelpAppendable.findWrapPos(testString, 15, 20), "did not find break character"); - assertEquals(30, TextHelpAppendable.findWrapPos(testString, 150, 0), "did not handle text shorter than width"); + assertEquals(9, TextHelpAppendable.indexOfWrap(testString, 10, 0), "did not find end of word"); + assertEquals(9, TextHelpAppendable.indexOfWrap(testString, 14, 0), "did not backup to end of word"); + assertEquals(15, TextHelpAppendable.indexOfWrap(testString, 15, 0), "did not find word at 15"); + assertEquals(15, TextHelpAppendable.indexOfWrap(testString, 16, 0)); + assertEquals(30, TextHelpAppendable.indexOfWrap(testString, 15, 20), "did not find break character"); + assertEquals(30, TextHelpAppendable.indexOfWrap(testString, 150, 0), "did not handle text shorter than width"); - assertThrows(IllegalArgumentException.class, () -> TextHelpAppendable.findWrapPos("", 0, 0)); - assertEquals(3, TextHelpAppendable.findWrapPos("Hello", 4, 0)); + assertThrows(IllegalArgumentException.class, () -> TextHelpAppendable.indexOfWrap("", 0, 0)); + assertEquals(3, TextHelpAppendable.indexOfWrap("Hello", 4, 0)); } @ParameterizedTest @MethodSource("org.apache.commons.cli.help.UtilTest#charArgs") - public void testFindWrapPosWithWhitespace(final Character c, final boolean isWhitespace) { + public void testindexOfWrapPosWithWhitespace(final Character c, final boolean isWhitespace) { final String text = format("Hello%cWorld", c); - assertEquals(isWhitespace ? 5 : 6, TextHelpAppendable.findWrapPos(text, 7, 0)); + assertEquals(isWhitespace ? 5 : 6, TextHelpAppendable.indexOfWrap(text, 7, 0)); } @Test public void testGetStyleBuilder() { - final TextStyle.Builder builder = underTest.getStyleBuilder(); + final TextStyle.Builder builder = underTest.getTextStyleBuilder(); assertEquals(TextHelpAppendable.DEFAULT_INDENT, builder.getIndent(), "Default indent value was changed, some tests may fail"); assertEquals(TextHelpAppendable.DEFAULT_LEFT_PAD, builder.getLeftPad(), "Default left pad value was changed, some tests may fail"); assertEquals(TextHelpAppendable.DEFAULT_WIDTH, builder.getMaxWidth(), "Default width value was changed, some tests may fail"); @@ -328,7 +326,7 @@ public final class TextHelpAppendableTest { @Test public void testPrintWrapped() throws IOException { String text = "The quick brown fox jumps over the lazy dog"; - final TextStyle.Builder styleBuilder = new TextStyle.Builder().setMaxWidth(10).setIndent(0).setLeftPad(0); + final TextStyle.Builder styleBuilder = TextStyle.builder().setMaxWidth(10).setIndent(0).setLeftPad(0); final List<String> expected = new ArrayList<>(); expected.add("The quick"); @@ -390,11 +388,11 @@ public final class TextHelpAppendableTest { @Test public void testResize() { - TextStyle.Builder tsBuilder = new TextStyle.Builder().setIndent(2).setMaxWidth(3); + TextStyle.Builder tsBuilder = TextStyle.builder().setIndent(2).setMaxWidth(3); underTest.resize(tsBuilder, 0.5); assertEquals(0, tsBuilder.getIndent()); - tsBuilder = new TextStyle.Builder().setIndent(4).setMaxWidth(6); + tsBuilder = TextStyle.builder().setIndent(4).setMaxWidth(6); underTest.resize(tsBuilder, 0.5); assertEquals(1, tsBuilder.getIndent()); } @@ -403,11 +401,11 @@ public final class TextHelpAppendableTest { public void testResizeTableFormat() { underTest.setMaxWidth(150); final TableDefinition tableDefinition = TableDefinition.from("Caption", - Collections.singletonList(new TextStyle.Builder().setMinWidth(20).setMaxWidth(100).get()), Collections.singletonList("header"), + Collections.singletonList(TextStyle.builder().setMinWidth(20).setMaxWidth(100).get()), Collections.singletonList("header"), Collections.singletonList(Collections.singletonList("one"))); final TableDefinition result = underTest.adjustTableFormat(tableDefinition); - assertEquals(20, result.columnStyle().get(0).getMinWidth(), "Minimum width should not be reset"); - assertEquals(100, result.columnStyle().get(0).getMaxWidth(), "Maximum width should not be reset"); + assertEquals(20, result.columnTextStyles().get(0).getMinWidth(), "Minimum width should not be reset"); + assertEquals(100, result.columnTextStyles().get(0).getMaxWidth(), "Maximum width should not be reset"); } @Test @@ -442,7 +440,7 @@ public final class TextHelpAppendableTest { queues.add(queue); - final TextStyle.Builder styleBuilder = new TextStyle.Builder().setMaxWidth(10).setIndent(0).setLeftPad(0); + final TextStyle.Builder styleBuilder = TextStyle.builder().setMaxWidth(10).setIndent(0).setLeftPad(0); final List<TextStyle> columns = new ArrayList<>(); columns.add(styleBuilder.get()); diff --git a/src/test/java/org/apache/commons/cli/help/TextStyleTests.java b/src/test/java/org/apache/commons/cli/help/TextStyleTests.java index f81b13b2..67a6382a 100644 --- a/src/test/java/org/apache/commons/cli/help/TextStyleTests.java +++ b/src/test/java/org/apache/commons/cli/help/TextStyleTests.java @@ -32,7 +32,7 @@ public class TextStyleTests { public static Stream<Arguments> padTestData() { final List<Arguments> lst = new ArrayList<>(); - final TextStyle.Builder builder = new TextStyle.Builder(); + final TextStyle.Builder builder = TextStyle.builder(); builder.setIndent(5); builder.setLeftPad(5); builder.setMinWidth(4);