Class ArgumentParsers
- java.lang.Object
-
- net.sourceforge.argparse4j.ArgumentParsers
-
public final class ArgumentParsers extends java.lang.ObjectFactory class to create new ArgumentParser.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_FORMAT_WIDTHDefault format width of text output.static java.lang.StringDEFAULT_PREFIX_CHARSDefault prefix characters.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleangetCjkWidthHack()Returns true iff CJK width hack is enabled.static intgetFormatWidth()Returns the width of formatted text.static booleangetTerminalWidthDetection()Returns true iff terminal width detection is enabled.static booleanisSingleMetavar()Returns true iff a metavar is shown only after the last flag.static ArgumentParsernewArgumentParser(java.lang.String prog)CreatesArgumentParserwith given program name.static ArgumentParsernewArgumentParser(java.lang.String prog, boolean addHelp)CreatesArgumentParserwith given program name and addHelp.static ArgumentParsernewArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars)CreatesArgumentParserwith given program name, addHelp and prefixChars.static ArgumentParsernewArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars, java.lang.String fromFilePrefix)CreatesArgumentParserwith given program name, addHelp and prefixChars.static voidsetCJKWidthHack(boolean flag)Settrueto enable CJK width hack.static voidsetSingleMetavar(boolean singleMetavar)If singleMetavar istrue, a metavar string in help message is only shown after the last flag instead of each flag.static voidsetTerminalWidthDetection(boolean flag)Settrueto 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
ArgumentParserwith 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
ArgumentParserwith given program name and addHelp.This is equivalent with
ArgumentParser(prog, addHelp, "-", null).- Parameters:
prog- The program nameaddHelp- If true,-h/--helpare 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
ArgumentParserwith given program name, addHelp and prefixChars.This is equivalent with
ArgumentParser(prog, addHelp, prefixChars, null).- Parameters:
prog- The program nameaddHelp- If true,-h/--helpare 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
ArgumentParserwith given program name, addHelp and prefixChars.- Parameters:
prog- The program nameaddHelp- If true,-h/--helpare 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. Specifynullto disable reading arguments from file.- Returns:
- ArgumentParser object.
-
setCJKWidthHack
public static void setCJKWidthHack(boolean flag)
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
-
getCjkWidthHack
public static boolean getCjkWidthHack()
Returns true iff CJK width hack is enabled.- Returns:
trueorfalse
-
setTerminalWidthDetection
public static void setTerminalWidthDetection(boolean flag)
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.
- Parameters:
flag-trueorfalse
-
getTerminalWidthDetection
public static boolean getTerminalWidthDetection()
Returns true iff terminal width detection is enabled.- Returns:
trueorfalse
-
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_WIDTHis 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
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:
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:
trueorfalse
-
-