Class ArgumentParsers


  • public final class ArgumentParsers
    extends java.lang.Object
    Factory class to create new ArgumentParser.
    • 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 name
        addHelp - 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 name
        addHelp - 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 name
        addHelp - 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. Specify null 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 or false
      • getCjkWidthHack

        public static boolean getCjkWidthHack()
        Returns true iff CJK width hack is enabled.
        Returns:
        true or false
      • 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 or false
      • getTerminalWidthDetection

        public static boolean getTerminalWidthDetection()
        Returns true iff terminal width detection is enabled.
        Returns:
        true or false
      • 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, the DEFAULT_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 or false