Class SimpleJSAP


  • public class SimpleJSAP
    extends JSAP
    A simple interface to JSAP that handles directly help, explanation and an array of parameters.

    More precisely, instances of this class behave exactly like those of JSAP, but additionally require a command name, an explanation (a wordy description) and an array of parameters (which will be registered automatically). A switch activated by --help is always registered under the ID help.

    A message will be automatically printed upon invocation of the parse() methods if an error occurs, or if the help switch is detected. In this case, messagePrinted() will return true, and the caller may check this condition to stop its actions.

    The screen width used to format the help text may be set using setScreenWidth(int). The formatter will preserve newlines. Note: as of 2.0a non-breaking spaces are temporarily disabled until some console encoding issues have been worked out. - ML

    Author:
    Sebastiano Vigna
    • Constructor Detail

      • SimpleJSAP

        public SimpleJSAP​(java.lang.String name,
                          java.lang.String explanation,
                          Parameter[] parameter)
                   throws JSAPException
        Creates a new simple JSAP with default screen width.
        Parameters:
        name - the name of the command for which help will be printed.
        explanation - a wordy explanation of the command, or null for no explanation.
        parameter - an array of parameters, which will be registered for you, or null.
        Throws:
        JSAPException
      • SimpleJSAP

        public SimpleJSAP​(java.lang.String name,
                          java.lang.String explanation)
                   throws JSAPException
        Creates a new simple JSAP with default screen width.
        Parameters:
        name - the name of the command for which help will be printed.
        explanation - a wordy explanation of the command, or null for no explanation.
        Throws:
        JSAPException
      • SimpleJSAP

        public SimpleJSAP​(java.lang.String name)
                   throws JSAPException
        Creates a new simple JSAP with a help switch, no explanation and default screen width.
        Parameters:
        name - the name of the command for which help will be printed.
        Throws:
        JSAPException
    • Method Detail

      • parse

        public JSAPResult parse​(java.lang.String arg)
        Description copied from class: JSAP
        Parses the specified command line. The specified command line is first parsed into an array, much like the operating system does for the JVM prior to calling your application's main class' main() method. If no Exception is thrown, the entire command line has been parsed successfully, and its results have been successfully instantiated.
        Overrides:
        parse in class JSAP
        Parameters:
        arg - An array of command line arguments to parse. This array is typically provided in the application's main class' main() method.
        Returns:
        a JSAPResult containing the resulting Objects.
      • parse

        public JSAPResult parse​(java.lang.String[] arg)
        Description copied from class: JSAP
        Parses the specified command line array. If no Exception is thrown, the entire command line has been parsed successfully, and its results have been successfully instantiated.
        Overrides:
        parse in class JSAP
        Parameters:
        arg - An array of command line arguments to parse. This array is typically provided in the application's main class' main() method.
        Returns:
        a JSAPResult containing the resulting Objects.
      • getScreenWidth

        public int getScreenWidth()
        Returns the current screen width.

        This value will be passed to JSAP.getHelp(int), and used to format the explanation.

        Returns:
        the current screen width.
      • setScreenWidth

        public SimpleJSAP setScreenWidth​(int screenWidth)
        Sets the screen width.
        Parameters:
        screenWidth - the new screen width.
        Returns:
        this simple JSAP.
      • messagePrinted

        public boolean messagePrinted()
        Returns true if the last parsing caused the a message to be printed.
        Returns:
        true if the last parsing caused a message to be printed.