- Since:
- 0.8.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddHelp(boolean flag) If true,-h/--helpare available.build()cjkWidthHack(boolean flag) Settrueto enable CJK width hack.private ArgumentParserConfigurationImplconfig()private TextWidthCounterdefaultFormatWidth(int defaultFormatWidth) Set the default format width.fromFilePrefix(String fromFilePrefix) The set of characters that prefix file path from which additional arguments should be read.private intincludeArgumentNamesAsKeysInResult(boolean flag) Include the name (see below) of the argument as a key in the parse result in addition to the key indestof the argument.The locale to use for messages.mustHelpTextIncludeMutualExclusivity(boolean flag) Add a text to the help of mutually-exclusive groups explaining that at most 1 arguments of the group may be given.noDestConversionForPositionalArgs(boolean flag) Do not perform any conversion to produce "dest" value (SeeArgument.getDest()) from positional argument name.prefixChars(String prefixChars) The set of characters that prefix named arguments.singleMetavar(boolean flag) If singleMetavar istrue, a metavar string in help message is only shown after the last flag instead of each flag.terminalWidthDetection(boolean flag) Settrueto enable terminal width detection.
-
Field Details
-
prog_
-
addHelp_
private boolean addHelp_ -
prefixChars_
-
fromFilePrefix_
-
locale_
-
cjkWidthHack_
private boolean cjkWidthHack_ -
defaultFormatWidth_
private int defaultFormatWidth_ -
terminalWidthDetection_
private boolean terminalWidthDetection_ -
singleMetavar_
private boolean singleMetavar_ -
noDestConversionForPositionalArgs_
private boolean noDestConversionForPositionalArgs_ -
includeArgumentNamesAsKeysInResult_
private boolean includeArgumentNamesAsKeysInResult_ -
mustHelpTextIncludeMutualExclusivity_
boolean mustHelpTextIncludeMutualExclusivity_
-
-
Constructor Details
-
ArgumentParserBuilder
ArgumentParserBuilder(String prog, DefaultSettings defaultSettings)
-
-
Method Details
-
addHelp
If true,
-h/--helpare available. If false, they are not. Default value:true.- Parameters:
flag-trueorfalse- Returns:
- This builder.
-
prefixChars
The set of characters that prefix named arguments. Default value:
"-".- Parameters:
prefixChars- The named argument prefixes.- Returns:
- This builder.
-
fromFilePrefix
The set of characters that prefix file path from which additional arguments should be read. Specify
nullto disable reading arguments from file. Default value:null.- Parameters:
fromFilePrefix- The from file path prefixes.- Returns:
- This builder.
-
locale
The locale to use for messages. Default value:
Locale.getDefault().- Parameters:
locale- The locale for messages.- Returns:
- This builder.
-
cjkWidthHack
Set
trueto enable CJK width hack.The CJK width hack is treat Unicode characters having East Asian Width property Wide/Full/Ambiguous to have twice a width of ascii characters when formatting help message if locale is "ja", "zh" or "ko". This feature is enabled by default.
- Parameters:
flag-trueorfalse- Returns:
- This builder.
-
defaultFormatWidth
Set the default format width. This width is used when terminal width detection is disabled or when terminal width detection cannot detect the actual number of columns. Default value:
ArgumentParsers.DEFAULT_FORMAT_WIDTH.- Parameters:
defaultFormatWidth- The default format width.- Returns:
- This builder.
-
terminalWidthDetection
Set
trueto enable terminal width detection.If this feature is enabled, argparse4j will automatically detect the terminal width and use it to format help messages. This feature is enabled by default.
- Parameters:
flag-trueorfalse- Returns:
- This builder.
-
singleMetavar
If singleMetavar is
true, a metavar string in help message is only shown after the last flag instead of each flag.By default and
falseis given to this method, a metavar is shown after each flag:-f FOO, --foo FOO
If
trueis given to this method, a metavar string is shown only once:-f, --foo FOO
- Parameters:
flag- Switch to display a metavar only after the last flag.- Returns:
- This builder.
-
noDestConversionForPositionalArgs
Do not perform any conversion to produce "dest" value (See
Argument.getDest()) from positional argument name.Prior 0.5.0, no conversion is made to produce "dest" value from positional argument name. Since 0.5.0, "dest" value is generated by replacing "-" with "_" in positional argument name. This is the same conversion rule for named arguments.
By default, this is set to
false(which means, conversion will be done). Application is advised to update its implementation to cope with this change. But if it is not feasible, call this method withtrueto turn off the conversion and retain the same behaviour with pre-0.5.0 version.- Parameters:
flag- Switch not to perform conversion to produce dest for positional arguments. Iftrueis given, no conversion is made.- Returns:
- This builder.
-
includeArgumentNamesAsKeysInResult
Include the name (see below) of the argument as a key in the parse result in addition to the key in
destof the argument.The argument name is determined as follows:
- Positional arguments: the name of the argument
- Named arguments: the first long flag, or if no long flag is present, the first flag, without the prefix
- Parameters:
flag- Iftrueis given, the argument name (as defined above) will also be in included as a key in the result. Otherwise onlydestof the argument will be a key in the result.- Returns:
- This builder.
-
mustHelpTextIncludeMutualExclusivity
Add a text to the help of mutually-exclusive groups explaining that at most 1 arguments of the group may be given.
- Parameters:
flag- Iftrueis given, the help text of mutually-exclusive groups will be extended to indicate at most 1 argument of the group can be given. Otherwise the mutual exclusivity of a group is only visible in the usage.- Returns:
- This builder.
-
build
-
config
-
createTextWidthCounter
-
getFormatWidth
private int getFormatWidth()
-