Object

com.github.scli

ParameterParser

Related Doc: package scli

Permalink

object ParameterParser

A module for parsing command line arguments into options and input values.

This module provides a function that expects a sequence of command line arguments as input and tries to generate a map with parameters from it. This function groups the single strings on the command line into option names, option values, and other input parameters. The resulting representation of parameters can then serve as input for the further processing of the command line, e.g. to extract configuration objects out of it.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ParameterParser
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type AliasResolverFunc = (ParameterKey) ⇒ Option[ParameterKey]

    Permalink

    Definition of a function that can resolve aliases.

    Definition of a function that can resolve aliases.

    The idea is that the function gets passed in a parameter key. If this key is known to be an alias, the function should return a defined Option with the key the alias is for; this key is then used as replacement for the alias. If the key cannot be resolved as an alias, the function should return None; the key is then used as is.

  2. type CliClassifierFunc = (Seq[String], Int) ⇒ CliElement

    Permalink

    Definition of a function to classify parameters on the command line.

    Definition of a function to classify parameters on the command line.

    The function is passed the sequence with parameters and the index of the current one to be inspected. It returns the result of the classification as a CliElement object.

  3. sealed trait CliElement extends AnyRef

    Permalink

    A trait describing an item encountered on the command line.

    A trait describing an item encountered on the command line.

    During parameter parsing the single items on the command line need to be classified into options, switches, or input parameters. For this purpose, a classification function is used which returns sub classes of this trait. The parser needs to handle the sub classes differently.

    This trait also plays a role for error handling: It stores the original key and the raw value of the represented parameter. This information is useful when generating meaningful error messages.

    In addition, the position of the corresponding element on the command line can be queried. This is needed by some use cases that override the values of options with values appearing later on the command line.

  4. type ExtractedKeyClassifierFunc = (ParameterKey, Seq[String], Int) ⇒ Option[CliElement]

    Permalink

    Definition of a function to classify specific parameters whose key has already been extracted.

    Definition of a function to classify specific parameters whose key has already been extracted.

    This function type is similar to CliClassifierFunc, but there are a couple of differences: First, it is invoked with a parameter key in addition to the sequence of parameters and the current index; so it will be called only for options or switches. Second, this function can fail to classify a parameter. The idea here is that multiple functions of this type can be combined, each of which is specialized for a specific parameter type. If none of those are able to detect the parameter type, an input parameter can be assumed as fallback.

  5. type FileOptionFunc = (CliElement) ⇒ Option[(ParameterKey, String)]

    Permalink

    Definition of a function that detects options referencing a parameters file.

    Definition of a function that detects options referencing a parameters file.

    The library supports externalizing complex parameter lists in files. These files can be specified on the command line using specific options. This function type is used by the processFileOptions() function to determine the parameter files to be loaded. The function is passed a CliElement; if this element references a parameters file, it returns a defined Option with the key of the file option (to be used in error messages) and the file name.

  6. case class InputParameterElement(value: String, index: Int = 0) extends CliElement with Product with Serializable

    Permalink

    A concrete CliElement class representing an input parameter.

    A concrete CliElement class representing an input parameter.

    value

    the value to be added to the input parameters

    index

    the index of this element on the command line

  7. type KeyExtractorFunc = (String) ⇒ Option[ParameterKey]

    Permalink

    Definition of a function that can extract the key of an option or switch parameter from a command line element.

    Definition of a function that can extract the key of an option or switch parameter from a command line element.

    The function is passed the string encountered on the command line. A concrete implementation probably checks whether this string starts with a prefix indicating an option or switch. If so, the key is returned (with the prefix removed); otherwise, result is an empty Option.

  8. case class OptionElement(key: ParameterKey, optValue: Option[String], index: Int = 0) extends CliElement with Product with Serializable

    Permalink

    A concrete CliElement class representing an option.

    A concrete CliElement class representing an option.

    The option is identified by its key. If possible, its value is extracted; but this may noe be possible, for instance if the option key was the last parameter on the command line.

    key

    the key of the option

    optValue

    an Option with the value

    index

    the index of this element on the command line

  9. case class OptionPrefixes extends Product with Serializable

    Permalink

    A data class that stores a list with supported prefixes for options.

    A data class that stores a list with supported prefixes for options.

    When parsing the command line each item is checked whether it starts with one of the prefixes defined by this class. If so, the item is considered an option or a switch.

    Command line applications often distinguish between full parameter names and short alias names. The alias has the same meaning as the regular parameter name, but it is shorter to type on the command line. Typically, a different prefix is used distinguish between the long and short parameter names, such as --target-directory for the full name and -d for the short alias. When constructing an instance the prefixes to be managed are specified as ParameterKey objects; hence, it can be stated whether a prefix is used for long or short parameter names.

  10. class ParameterFileException extends Exception

    Permalink

    A specialized exception class to report problems during the processing of parameter files.

    A specialized exception class to report problems during the processing of parameter files.

    During parameter file processing, I/O exceptions can occur. Such exceptions are converted to exceptions of this type. They transport some more information which is useful when handling errors, e.g. printing help or error information.

  11. type ParametersMap = Map[ParameterKey, Iterable[CliElement]]

    Permalink

    Type definition for the map with resolved parameter values.

    Type definition for the map with resolved parameter values. The array with command line options is transformed in such a map which allows direct access to the value(s) assigned to parameters. The map stores CliElement objects, so that the original information from the command line is still available.

  12. case class SwitchesElement(switches: List[(ParameterKey, String)], index: Int = 0) extends CliElement with Product with Serializable

    Permalink

    A concrete CliElement class representing a set of switches.

    A concrete CliElement class representing a set of switches.

    A single parameter on the command line can contain multiple switches, e.g. if multiple short keys are composed, as in tar xvzf. Therefore, this class holds a list with switches that have been extracted. For each switch its key and its value (which is derived from the default value defined in the parameter model) is stored.

    Note: The properties for key and value are dummies; during parameter parsing, for each switch in the result, a new element is created.

    switches

    a list with switches and their values that have been extracted

    index

    the index of this element on the command line

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final val DefaultOptionPrefixes: OptionPrefixes

    Permalink

    An OptionPrefixes object with the default prefix for options.

    An OptionPrefixes object with the default prefix for options. This is used if for a parse operation no explicit functions to recognize options and extract their keys are specified.

  5. final val InputParameter: ParameterKey

    Permalink

    Reserved key of a parameter that collects the input strings that are no values of options or switches.

  6. object OptionPrefixes extends Serializable

    Permalink
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def classifierOf(keyClassifiers: List[ExtractedKeyClassifierFunc])(keyExtractor: KeyExtractorFunc): CliClassifierFunc

    Permalink

    Generates a CliClassifierFunc from the given sequence extracted key classifier functions.

    Generates a CliClassifierFunc from the given sequence extracted key classifier functions. The resulting classifier function tries to extract an option or switch key from the current command line parameter using the extractor function provided. If this succeeds, the key is passed to the key classifier functions one by one until one returns a defined result. This result is returned. If extraction of the key fails or none of the classifier functions returns a result, an InputParameterElement is returned.

    keyClassifiers

    a list of ExtractedKeyClassifierFunc functions

    keyExtractor

    the key extractor function

    returns

    a CliClassifierFunc constructed from these parameters

  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @throws( ... )
  10. def combinedSwitchKeyClassifierFunc(modelContext: ⇒ ModelContext)(resolverFunc: AliasResolverFunc): ExtractedKeyClassifierFunc

    Permalink

    Returns a key classifier function for switches that can extract multiple short alias keys.

    Returns a key classifier function for switches that can extract multiple short alias keys. For long keys, the classifier function behaves in the same way as the one returned by switchKeyClassifierFunc(). For short aliases, however, the function assumes that the key passed in consists of multiple single letter key aliases and returns corresponding keys in the resulting SwitchesElement. Note that here no checks for the parameter type are done. So to work correctly, the function should be executed after a check for option elements.

    modelContext

    the model context

    resolverFunc

    function to resolve alias keys

    returns

    the key classifier function for multiple switches

  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def fileOptionFuncForOptions(options: Iterable[ParameterKey]): FileOptionFunc

    Permalink

    Returns a FileOptionFunc that detects the given parameter keys as file options.

    Returns a FileOptionFunc that detects the given parameter keys as file options. During file option processing, the command line elements are classified. If an element is an option with a key in the given list, the value of this option is returned as name of a parameter file.

    options

    a sequence with options referencing parameter files

    returns

    the FileOptionFunc detecting these keys

  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  15. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  20. def optionKeyClassifierFunc(modelContext: ⇒ ModelContext)(resolverFunc: AliasResolverFunc): ExtractedKeyClassifierFunc

    Permalink

    Returns a key classifier func for options.

    Returns a key classifier func for options. The function checks whether the passed in key references an option in the model context. If so, a corresponding result is returned.

    modelContext

    the model context

    resolverFunc

    function to resolve alias keys

    returns

    the key classifier function for options

  21. def parseParameters(args: Seq[String])(classifierFunc: CliClassifierFunc)(aliasResolverFunc: AliasResolverFunc): ParametersMap

    Permalink

    Parses the command line arguments and converts them into a map keyed by options.

    Parses the command line arguments and converts them into a map keyed by options. The parsing operation can be customized by specifying some properties, especially a CliClassifierFunc. This function is invoked for each argument, and - based on its result - the parameter is added to the result produced by this function. Note that the parsing operation always succeeds, even if invalid parameters are passed in; this is detected and handled later in the extraction phase.

    args

    the sequence with command line arguments

    classifierFunc

    a function to classify parameters

    aliasResolverFunc

    a function to resolve aliases

    returns

    a Try with the parsed map of arguments

  22. def processParameterFiles(args: Seq[String])(classifierFunc: CliClassifierFunc)(fileOptionFunc: FileOptionFunc): Try[Seq[String]]

    Permalink

    Processes the passed in sequence of parameters and resolves all parameter files detected by the given FileOptionFunc.

    Processes the passed in sequence of parameters and resolves all parameter files detected by the given FileOptionFunc. The files are read, and their content is added to the command line, replacing the original file options. If successful, result is the full sequence of command line parameters with all parameter files included.

    As I/O operations may fail, this function returns a Try. In case of a failure, the exception is of type ParameterFileException and contains further information about the failed read operation.

    args

    the sequence with command line arguments

    classifierFunc

    a function to classify parameters

    fileOptionFunc

    a function to detect file options

    returns

    the final sequence of parameters including all parameter files

  23. def switchKeyClassifierFunc(modelContext: ⇒ ModelContext)(resolverFunc: AliasResolverFunc): ExtractedKeyClassifierFunc

    Permalink

    Returns a key classifier function for switches.

    Returns a key classifier function for switches. The function checks whether the passed in key references a switch in the model context. If so, a corresponding result is returned.

    modelContext

    the model context

    resolverFunc

    function to resolve alias keys

    returns

    the key classifier function for switches

  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  25. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  26. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @Deprecated @deprecated @throws( classOf[java.lang.Throwable] )
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

Ungrouped