Packages

  • package root
    Definition Classes
    root
  • package de
    Definition Classes
    root
  • package h2b
    Definition Classes
    de
  • package scala
    Definition Classes
    h2b
  • package lib
    Definition Classes
    scala
  • package util

    This is a Scala library of programming utilities.

    This is a Scala library of programming utilities. It is not intended to comprise a systematic collection but contains some tools that may be useful for some applications.

    Some highlights are a number of probability distributions, a command-line interface, a configuration package, an RSS utility, a class to handle temporary directories, control structures, a logger trait and a timer.

    Definition Classes
    lib
  • package cli

    Define the parameters of your command line as instances of

    Define the parameters of your command line as instances of

    - FlagParameter: no specific value, just signals that it is there,

    - HelpParameter: signals that the user needs some help (if given as a command-line argument, other parameters are not computed and no parse exceptions are thrown),

    - ValueParameter[V]: has exactly one value of type V,

    - ListParameter[V]: has a number of values of type V and

    - MainParameter: has a number of String values.

    ValueParameter[V] and ListParameter[V] need a converter to convert a string to the value type V. You might want to import the object Converter that provides converters for standard data types implicitly by:

    import de.h2b.scala.lib.util.cli.Converter._

    Then create a new instance of CommandLine with a set of parameters. The resulting object then can parse a string sequence or an array of strings for parameters and their values. If something goes wrong, either a ParameterException (some argument does not obey to the format specified by its parameter) or a CommandLineException (something is wrong with the arguments as a whole) is thrown.

    Finally query the original parameter instances for its value or values field.

    The usage method of CommandLine constructs a string suitable for a usage message.

    Definition Classes
    util
    Example:
    1. import de.h2b.scala.lib.util.cli._
      import de.h2b.scala.lib.util.cli.Converter._
      val overwrite = FlagParameter(Set("-o", "--overwrite"), "overwrite target")
      val mode = ValueParameter(Set("-m"), "mode", default=Some(0))
      val main = MainParameter("source target", arity=2)
      CommandLine(Set(overwrite, mode, main)).parse("-o -m 1 from to".split(' '))
      println(overwrite.value) //> Some(true)
      println(mode.value) //> Some(1)
      println(main.values) //> Some(WrappedArray(from, to))
  • CommandLine
  • CommandLineException
  • Converter
  • FlagParameter
  • HelpParameter
  • ListParameter
  • MainParameter
  • MultipleValues
  • Parameter
  • ParameterException
  • SingleValue
  • ValueParameter
  • package config

    This package provides various configuration sources under a common trait Config, which is basically an immutable map.

    This package provides various configuration sources under a common trait Config, which is basically an immutable map. The following implementations are available:

    - ArgsConfig loads key/value pairs from an array of strings: array elements that contain a separator char (defined by ArgsConfig.SeparatorChar) are considered as key/value pairs, while elements not consumed by this rule can be retrieved by the remaining array (makes it suitable to scan a command line for such key/value pairs and parsing the rest with tools like described in [U1 Command-Line Interface](#u1-command-line-interface).

    - FileConfig loads key/value pairs from a specified resource file which must conform to the java.util.Properties#load(InputStream) method; there is also a factory method where the resource is looked up under the modified package name of a specified class.

    - BundleConfig loads key/value pairs from a resource bundle (according to the java.util.ResourceBundle class) of a specified base name using a locale option; there is also a factory method where the resource bundle is looked up under the modified package name of a specified class.

    * SystemPropertiesConfig is a Config object that represents the system properties of the JVM.

    * SystemEnvironmentConfig is a Config object that represents the system environment; note that the system may not support environment variables -- in this case, this object is empty.

    Multiple Configs can be combined using the standard map ++ operators, yielding an overall Config.

    Definition Classes
    util
    Example:
    1. import de.h2b.scala.lib.util.config._
      val argsConfig = ArgsConfig("-x key1=val1 /y key2=val2 abc".split(' '))
      val sysConfig = SystemPropertiesConfig
      val otherConfig = Config("one"->1, "two"->2, "three"->3)
      val config = argsConfig ++ sysConfig ++ otherConfig
      println(config.get("key1")) //> Some(val1)
      println(config.get("java.version")) //> Some(1.8.0_121)
      println(config.get("two")) //> Some(2)
      println(argsConfig.remaining.mkString(" ")) //> -x /y abc

package cli

Define the parameters of your command line as instances of

- FlagParameter: no specific value, just signals that it is there,

- HelpParameter: signals that the user needs some help (if given as a command-line argument, other parameters are not computed and no parse exceptions are thrown),

- ValueParameter[V]: has exactly one value of type V,

- ListParameter[V]: has a number of values of type V and

- MainParameter: has a number of String values.

ValueParameter[V] and ListParameter[V] need a converter to convert a string to the value type V. You might want to import the object Converter that provides converters for standard data types implicitly by:

import de.h2b.scala.lib.util.cli.Converter._

Then create a new instance of CommandLine with a set of parameters. The resulting object then can parse a string sequence or an array of strings for parameters and their values. If something goes wrong, either a ParameterException (some argument does not obey to the format specified by its parameter) or a CommandLineException (something is wrong with the arguments as a whole) is thrown.

Finally query the original parameter instances for its value or values field.

The usage method of CommandLine constructs a string suitable for a usage message.

Example:
  1. import de.h2b.scala.lib.util.cli._
    import de.h2b.scala.lib.util.cli.Converter._
    val overwrite = FlagParameter(Set("-o", "--overwrite"), "overwrite target")
    val mode = ValueParameter(Set("-m"), "mode", default=Some(0))
    val main = MainParameter("source target", arity=2)
    CommandLine(Set(overwrite, mode, main)).parse("-o -m 1 from to".split(' '))
    println(overwrite.value) //> Some(true)
    println(mode.value) //> Some(1)
    println(main.values) //> Some(WrappedArray(from, to))
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. cli
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. class CommandLine extends AnyRef
  2. case class CommandLineException(message: Option[String] = None, cause: Option[Throwable] = None) extends RuntimeException with Product with Serializable
  3. trait Converter[V] extends AnyRef
  4. case class FlagParameter(names: Set[String], description: String) extends Parameter[Boolean] with SingleValue[Boolean] with Product with Serializable

    A flag parameter has no specific value, it just signals that it is there.

    A flag parameter has no specific value, it just signals that it is there.

    If its value is defined, it is present in the command line, else it is not.

  5. case class HelpParameter(names: Set[String]) extends Parameter[Boolean] with SingleValue[Boolean] with Product with Serializable

    Signals that the user needs some help.

    Signals that the user needs some help.

    If a help-parameter name is given as a command-line argument, other parameters are not computed and no parse exceptions are thrown.

    If its value is defined, it is present in the command line, else it is not.

  6. case class ListParameter[V](names: Set[String], description: String, arity: Int, required: Boolean = false, defaults: Option[Seq[V]] = None)(implicit convert: (String) => Try[V]) extends Parameter[V] with MultipleValues[V] with Converter[V] with Product with Serializable

    A list parameter has a number of values specified by its arity.

    A list parameter has a number of values specified by its arity.

    The values can be retrieved as a sequence by the values option.

  7. case class MainParameter(description: String, arity: Int, required: Boolean = false, defaults: Option[Seq[String]] = None) extends Parameter[String] with MultipleValues[String] with Product with Serializable

    A main parameter has a number of values specified by its arity.

    A main parameter has a number of values specified by its arity.

    The values can be retrieved as a sequence by the values option.

    A main parameter is different from a list parameter by the absence of a name in the command line. There is, however, an internal name (MainParameter.internalName) that can be used in the command line to avoid ambiguities.

    Main-parameter values can be given at the beginning or at the end of the arguments sequence (or both mixed up, but that may be confusing). Beware, that values at the end might be consumed by a variable-arity parameter in a position right before.

  8. trait MultipleValues[V] extends AnyRef
  9. sealed trait Parameter[V] extends AnyRef
  10. case class ParameterException(parameter: Parameter[_], message: Option[String] = None, cause: Option[Throwable] = None) extends RuntimeException with Product with Serializable
  11. trait SingleValue[V] extends AnyRef
  12. case class ValueParameter[V](names: Set[String], description: String, required: Boolean = false, default: Option[V] = None)(implicit convert: (String) => Try[V]) extends Parameter[V] with SingleValue[V] with Converter[V] with Product with Serializable

    A value parameter has exactly one value.

    A value parameter has exactly one value.

    The value can be retrieved by the value option.

Value Members

  1. object CommandLine
  2. object Converter
  3. object MainParameter extends Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped