Class ArgumentParsers
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default format width of text output.static final String
Default prefix characters. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns true iff CJK width hack is enabled.static int
Returns the width of formatted text.static boolean
Returns true iff terminal width detection is enabled.static boolean
Returns true iff a metavar is shown only after the last flag.static ArgumentParser
newArgumentParser
(String prog) CreatesArgumentParser
with given program name.static ArgumentParser
newArgumentParser
(String prog, boolean addHelp) CreatesArgumentParser
with given program name and addHelp.static ArgumentParser
newArgumentParser
(String prog, boolean addHelp, String prefixChars) CreatesArgumentParser
with given program name, addHelp and prefixChars.static ArgumentParser
newArgumentParser
(String prog, boolean addHelp, String prefixChars, String fromFilePrefix) CreatesArgumentParser
with given program name, addHelp and prefixChars.static void
setCJKWidthHack
(boolean flag) Settrue
to enable CJK width hack.static void
setSingleMetavar
(boolean singleMetavar) If singleMetavar istrue
, a metavar string in help message is only shown after the last flag instead of each flag.static void
setTerminalWidthDetection
(boolean flag) Settrue
to enable terminal width detection.
-
Field Details
-
DEFAULT_PREFIX_CHARS
Default prefix characters.- See Also:
-
DEFAULT_FORMAT_WIDTH
public static final int DEFAULT_FORMAT_WIDTHDefault format width of text output.- See Also:
-
-
Method Details
-
newArgumentParser
Creates
ArgumentParser
with given program name.This is equivalent with
newArgumentParser(prog, true, "-", null)
.- Parameters:
prog
- The program name- Returns:
- ArgumentParser object
-
newArgumentParser
Creates
ArgumentParser
with given program name and addHelp.This is equivalent with
ArgumentParser(prog, addHelp, "-", null)
.- Parameters:
prog
- The program nameaddHelp
- If true,-h/--help
are available. If false, they are not.- Returns:
- ArgumentParser object
-
newArgumentParser
Creates
ArgumentParser
with given program name, addHelp and prefixChars.This is equivalent with
ArgumentParser(prog, addHelp, prefixChars, null)
.- Parameters:
prog
- The program nameaddHelp
- If true,-h/--help
are available. If false, they are not.prefixChars
- The set of characters that prefix optional arguments.- Returns:
- ArgumentParser object.
-
newArgumentParser
public static ArgumentParser newArgumentParser(String prog, boolean addHelp, String prefixChars, String fromFilePrefix) Creates
ArgumentParser
with given program name, addHelp and prefixChars.- Parameters:
prog
- The program nameaddHelp
- If true,-h/--help
are available. If false, they are not.prefixChars
- The set of characters that prefix optional arguments.fromFilePrefix
- The set of characters that prefix file path from which additional arguments should be read. Specifynull
to disable reading arguments from file.- Returns:
- ArgumentParser object.
-
setCJKWidthHack
public static void setCJKWidthHack(boolean flag) Set
true
to 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
-true
orfalse
-
getCjkWidthHack
public static boolean getCjkWidthHack()Returns true iff CJK width hack is enabled.- Returns:
true
orfalse
-
setTerminalWidthDetection
public static void setTerminalWidthDetection(boolean flag) Set
true
to enable terminal width detection.If this feature is enabled, argparse4j will automatically detect the terminal width and use it to format help messages.
- Parameters:
flag
-true
orfalse
-
getTerminalWidthDetection
public static boolean getTerminalWidthDetection()Returns true iff terminal width detection is enabled.- Returns:
true
orfalse
-
getFormatWidth
public static int getFormatWidth()Returns the width of formatted text. If the terminal width detection is enabled, this method will detect the terminal width automatically and calculate the width based on it. If it is not enabled or auto-detection was failed, theDEFAULT_FORMAT_WIDTH
is returned.- Returns:
- the width of formatted text
-
setSingleMetavar
public static void setSingleMetavar(boolean 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
false
is given to this method, a metavar is shown after each flag:-f FOO, --foo FOO
If
true
is given to this method, a metavar string is shown only once:-f, --foo FOO
- Parameters:
singleMetavar
- Switch to display a metavar only after the last flag.
-
isSingleMetavar
public static boolean isSingleMetavar()Returns true iff a metavar is shown only after the last flag.- Returns:
true
orfalse
-