Class DefaultOptionParser

  • All Implemented Interfaces:
    OptionParser

    public class DefaultOptionParser
    extends java.lang.Object
    implements OptionParser
    The default command option parser.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultOptionParser()
      Creates a new DefaultParser instance with partial matching enabled.
      DefaultOptionParser​(boolean allowPartialMatching)
      Create a new DefaultParser instance with the specified partial matching policy.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ParsedOptions parse​(Options options, java.lang.String[] args)
      Parse the arguments according to the specified options.
      ParsedOptions parse​(Options options, java.lang.String[] args, boolean skipParsingAtNonOption)
      Parse the arguments according to the specified options.
      ParsedOptions parse​(Options options, java.lang.String[] args, java.util.Properties properties)
      Parse the arguments according to the specified options and properties.
      ParsedOptions parse​(Options options, java.lang.String[] args, java.util.Properties properties, boolean skipParsingAtNonOption)
      Parse the arguments according to the specified options and properties.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultOptionParser

        public DefaultOptionParser()
        Creates a new DefaultParser instance with partial matching enabled. By "partial matching" we mean that given the following code:
             
             Options options = new Options();
             options.addOption(new Option("d", "debug", false, "Turn on debug."));
             options.addOption(new Option("e", "extract", false, "Turn on extract."));
             options.addOption(new Option("o", "option", true, "Turn on option with argument."));
             
         
        with "partial matching" turned on, -de only matches the "debug" option. However, with "partial matching" disabled, -de would enable both debug as well as extract options.
      • DefaultOptionParser

        public DefaultOptionParser​(boolean allowPartialMatching)
        Create a new DefaultParser instance with the specified partial matching policy. By "partial matching" we mean that given the following code:
             
                  Options options = new Options();
              options.addOption(new Option("d", "debug", false, "Turn on debug."));
              options.addOption(new Option("e", "extract", false, "Turn on extract."));
              options.addOption(new Option("o", "option", true, "Turn on option with argument."));
              
         
        with "partial matching" turned on, -de only matches the "debug" option. However, with "partial matching" disabled, -de would enable both debug as well as extract options.
        Parameters:
        allowPartialMatching - if partial matching of long options shall be enabled
    • Method Detail

      • parse

        public ParsedOptions parse​(Options options,
                                   java.lang.String[] args)
                            throws OptionParserException
        Description copied from interface: OptionParser
        Parse the arguments according to the specified options.
        Specified by:
        parse in interface OptionParser
        Parameters:
        options - the specified Options
        args - the command line arguments
        Returns:
        the list of atomic option and value tokens
        Throws:
        OptionParserException - if there are any problems encountered while parsing the command line tokens
      • parse

        public ParsedOptions parse​(Options options,
                                   java.lang.String[] args,
                                   java.util.Properties properties)
                            throws OptionParserException
        Parse the arguments according to the specified options and properties.
        Specified by:
        parse in interface OptionParser
        Parameters:
        options - the specified Options
        args - the command line arguments
        properties - command line option name-value pairs
        Returns:
        the list of atomic option and value tokens
        Throws:
        OptionParserException - if there are any problems encountered while parsing the command line tokens
      • parse

        public ParsedOptions parse​(Options options,
                                   java.lang.String[] args,
                                   boolean skipParsingAtNonOption)
                            throws OptionParserException
        Description copied from interface: OptionParser
        Parse the arguments according to the specified options.
        Specified by:
        parse in interface OptionParser
        Parameters:
        options - the specified Options
        args - the command line arguments
        skipParsingAtNonOption - if true an unrecognized argument stops the parsing and the remaining arguments are added to the ParsedOptionss args list. If false an unrecognized argument triggers a ParseException.
        Returns:
        the list of atomic option and value tokens
        Throws:
        OptionParserException - if there are any problems encountered while parsing the command line tokens
      • parse

        public ParsedOptions parse​(Options options,
                                   java.lang.String[] args,
                                   java.util.Properties properties,
                                   boolean skipParsingAtNonOption)
                            throws OptionParserException
        Parse the arguments according to the specified options and properties.
        Specified by:
        parse in interface OptionParser
        Parameters:
        options - the specified Options
        args - the command line arguments
        properties - command line option name-value pairs
        skipParsingAtNonOption - if true an unrecognized argument stops the parsing and the remaining arguments are added to the ParsedOptionss args list. If false an unrecognized argument triggers a ParseException.
        Returns:
        the list of atomic option and value tokens
        Throws:
        OptionParserException - if there are any problems encountered while parsing the command line tokens