Class ArgumentParsers
- java.lang.Object
-
- net.sourceforge.argparse4j.ArgumentParsers
-
public final class ArgumentParsers extends java.lang.Object
Factory class to create new ArgumentParser.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_FORMAT_WIDTH
Default format width of text output.static java.lang.String
DEFAULT_PREFIX_CHARS
Default prefix characters.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
getCjkWidthHack()
Returns true iff CJK width hack is enabled.static int
getFormatWidth()
Returns the width of formatted text.static boolean
getTerminalWidthDetection()
Returns true iff terminal width detection is enabled.static boolean
isSingleMetavar()
Returns true iff a metavar is shown only after the last flag.static ArgumentParser
newArgumentParser(java.lang.String prog)
CreatesArgumentParser
with given program name.static ArgumentParser
newArgumentParser(java.lang.String prog, boolean addHelp)
CreatesArgumentParser
with given program name and addHelp.static ArgumentParser
newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars)
CreatesArgumentParser
with given program name, addHelp and prefixChars.static ArgumentParser
newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars, java.lang.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 Detail
-
DEFAULT_PREFIX_CHARS
public static final java.lang.String DEFAULT_PREFIX_CHARS
Default prefix characters.- See Also:
- Constant Field Values
-
DEFAULT_FORMAT_WIDTH
public static final int DEFAULT_FORMAT_WIDTH
Default format width of text output.- See Also:
- Constant Field Values
-
-
Method Detail
-
newArgumentParser
public static ArgumentParser newArgumentParser(java.lang.String prog)
Creates
ArgumentParser
with given program name.This is equivalent with
newArgumentParser(prog, true, "-", null)
.- Parameters:
prog
- The program name- Returns:
- ArgumentParser object
-
newArgumentParser
public static ArgumentParser newArgumentParser(java.lang.String prog, boolean addHelp)
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
public static ArgumentParser newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars)
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(java.lang.String prog, boolean addHelp, java.lang.String prefixChars, java.lang.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
-
-