Package org.apache.commons.cli.help
Class HelpFormatter
- java.lang.Object
-
- org.apache.commons.cli.help.AbstractHelpFormatter
-
- org.apache.commons.cli.help.HelpFormatter
-
public class HelpFormatter extends AbstractHelpFormatter
A default formatter implementation for standard usage.Example:
Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file").withDescription("The file to be processed").hasArg().withArgName("FILE").isRequired().create('f')); options.addOption(OptionBuilder.withLongOpt("version").withDescription("Print the version of the application").create('v')); options.addOption(OptionBuilder.withLongOpt("help").create('h')); String header = "Do something useful with an input file"; String footer = "Please report issues at https://example.com/issues"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("myapp", header, options, footer, true);This produces the following output:
usage: myapp -f <FILE> [-h] [-v] Do something useful with an input file -f,--file <FILE> The file to be processed -h,--help -v,--version Print the version of the application Please report issues at https://example.com/issues- Since:
- 1.10.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHelpFormatter.BuilderA builder for the HelpFormatter.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_COLUMN_SPACINGThe default number of spaces between columns in the options table: 5.static intDEFAULT_LEFT_PADDefault padding to the left of each line: 1.static intDEFAULT_WIDTHDefault number of characters per line: 74.-
Fields inherited from class org.apache.commons.cli.help.AbstractHelpFormatter
DEFAULT_COMPARATOR, DEFAULT_OPTION_GROUP_SEPARATOR, DEFAULT_SYNTAX_PREFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHelpFormatter(HelpFormatter.Builder builder)Constructs the Help formatter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HelpFormatter.Builderbuilder()Constructs a new builder.TableDefinitiongetTableDefinition(java.lang.Iterable<Option> options)Gets the table definition for the options.-
Methods inherited from class org.apache.commons.cli.help.AbstractHelpFormatter
getComparator, getHelpAppendable, getOptionFormatBuilder, getOptionFormatter, getOptionGroupSeparator, getSerializer, getSyntaxPrefix, printHelp, printHelp, printOptions, printOptions, printOptions, setSyntaxPrefix, sort, sort, toArgName, toSyntaxOptions, toSyntaxOptions, toSyntaxOptions, toSyntaxOptions
-
-
-
-
Field Detail
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTH
Default number of characters per line: 74.- See Also:
- Constant Field Values
-
DEFAULT_LEFT_PAD
public static final int DEFAULT_LEFT_PAD
Default padding to the left of each line: 1.- See Also:
- Constant Field Values
-
DEFAULT_COLUMN_SPACING
public static final int DEFAULT_COLUMN_SPACING
The default number of spaces between columns in the options table: 5.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HelpFormatter
protected HelpFormatter(HelpFormatter.Builder builder)
Constructs the Help formatter.- Parameters:
builder- the Builder to build from.
-
-
Method Detail
-
builder
public static HelpFormatter.Builder builder()
Constructs a new builder.- Returns:
- a new builder.
-
getTableDefinition
public TableDefinition getTableDefinition(java.lang.Iterable<Option> options)
Gets the table definition for the options.- Specified by:
getTableDefinitionin classAbstractHelpFormatter- Parameters:
options- the collection ofOptioninstances to create the table from.- Returns:
- A
TableDefinitionto display the options.
-
-