- 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 private static boolean
cjkWidthHack_
(package private) static java.util.List<java.lang.String>
cjkWidthLangs_
private static java.lang.String[]
cjkWidthLangsSrc_
static int
DEFAULT_FORMAT_WIDTH
Default format width of text output.static java.lang.String
DEFAULT_PREFIX_CHARS
Default prefix characters.private static boolean
noDestConversionForPositionalArgs_
private static boolean
singleMetavar_
private static boolean
terminalWidthDetection_
-
Constructor Summary
Constructors Modifier Constructor Description private
ArgumentParsers()
Intentionally made private to avoid to get instantiated in application code.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static boolean
getCjkWidthHack()
Deprecated.This is not thread safe.static int
getFormatWidth()
Deprecated.This is not thread safe.static boolean
getNoDestConversionForPositionalArgs()
Deprecated.This is not thread safe.static boolean
getTerminalWidthDetection()
Deprecated.This is not thread safe.static boolean
isSingleMetavar()
Deprecated.This is not thread safe.static ArgumentParser
newArgumentParser(java.lang.String prog)
Deprecated.This is not thread safe.static ArgumentParser
newArgumentParser(java.lang.String prog, boolean addHelp)
Deprecated.This is not thread safe.static ArgumentParser
newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars)
Deprecated.This is not thread safe.static ArgumentParser
newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars, java.lang.String fromFilePrefix)
Deprecated.This is not thread safe.static ArgumentParserBuilder
newFor(java.lang.String prog)
CreatesArgumentParserBuilder
with given program name.static ArgumentParserBuilder
newFor(java.lang.String prog, DefaultSettings defaultSettings)
CreatesArgumentParserBuilder
with given program name and default settings.static void
setCJKWidthHack(boolean flag)
Deprecated.This is not thread safe.static void
setNoDestConversionForPositionalArgs(boolean flag)
Deprecated.This is not thread safe.static void
setSingleMetavar(boolean singleMetavar)
Deprecated.This is not thread safe.static void
setTerminalWidthDetection(boolean flag)
Deprecated.This is not thread safe.
-
-
-
Field Detail
-
DEFAULT_PREFIX_CHARS
public static final java.lang.String DEFAULT_PREFIX_CHARS
Default prefix characters.- See Also:
- Constant Field Values
-
cjkWidthLangsSrc_
private static final java.lang.String[] cjkWidthLangsSrc_
-
cjkWidthLangs_
static java.util.List<java.lang.String> cjkWidthLangs_
-
cjkWidthHack_
private static boolean cjkWidthHack_
-
terminalWidthDetection_
private static boolean terminalWidthDetection_
-
DEFAULT_FORMAT_WIDTH
public static final int DEFAULT_FORMAT_WIDTH
Default format width of text output.- See Also:
- Constant Field Values
-
singleMetavar_
private static boolean singleMetavar_
-
noDestConversionForPositionalArgs_
private static boolean noDestConversionForPositionalArgs_
-
-
Method Detail
-
newFor
public static ArgumentParserBuilder newFor(java.lang.String prog)
Creates
ArgumentParserBuilder
with given program name.- Parameters:
prog
- The program name- Returns:
- ArgumentParserBuilder object
- Since:
- 0.8.0
-
newFor
public static ArgumentParserBuilder newFor(java.lang.String prog, DefaultSettings defaultSettings)
Creates
ArgumentParserBuilder
with given program name and default settings.- Parameters:
prog
- The program namedefaultSettings
- The default settings to use.- Returns:
- ArgumentParserBuilder object
- Since:
- 0.9.0
-
newArgumentParser
@Deprecated public static ArgumentParser newArgumentParser(java.lang.String prog)
Deprecated.This is not thread safe. UsenewFor(String)
instead.Creates
ArgumentParser
with given program name.This is equivalent with
newArgumentParser(prog, true, "-", null)
.- Parameters:
prog
- The program name- Returns:
- ArgumentParser object
-
newArgumentParser
@Deprecated public static ArgumentParser newArgumentParser(java.lang.String prog, boolean addHelp)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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
@Deprecated public static ArgumentParser newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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 named arguments.- Returns:
- ArgumentParser object.
-
newArgumentParser
@Deprecated public static ArgumentParser newArgumentParser(java.lang.String prog, boolean addHelp, java.lang.String prefixChars, java.lang.String fromFilePrefix)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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 named 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
@Deprecated public static void setCJKWidthHack(boolean flag)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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
@Deprecated public static boolean getCjkWidthHack()
Deprecated.This is not thread safe. UsenewFor(String)
instead.Returns true iff CJK width hack is enabled.- Returns:
true
orfalse
-
setTerminalWidthDetection
@Deprecated public static void setTerminalWidthDetection(boolean flag)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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
@Deprecated public static boolean getTerminalWidthDetection()
Deprecated.This is not thread safe. UsenewFor(String)
instead.Returns true iff terminal width detection is enabled.- Returns:
true
orfalse
-
getFormatWidth
@Deprecated public static int getFormatWidth()
Deprecated.This is not thread safe. UsenewFor(String)
instead.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
@Deprecated public static void setSingleMetavar(boolean singleMetavar)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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
@Deprecated public static boolean isSingleMetavar()
Deprecated.This is not thread safe. UsenewFor(String)
instead.Returns true iff a metavar is shown only after the last flag.- Returns:
true
orfalse
-
setNoDestConversionForPositionalArgs
@Deprecated public static void setNoDestConversionForPositionalArgs(boolean flag)
Deprecated.This is not thread safe. UsenewFor(String)
instead.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 withtrue
to 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. Iftrue
is given, no conversion is made.
-
getNoDestConversionForPositionalArgs
@Deprecated public static boolean getNoDestConversionForPositionalArgs()
Deprecated.This is not thread safe. UsenewFor(String)
instead.Returnstrue
iff no destination value conversion for positional arguments is enabled.- Returns:
true
orfalse
-
-