com.concurrentthought

cla

package cla

Package object that adds a mini-DSL allowing the user to construct an Args using using a multi-line string.

Note

Experimental!

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. cla
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class Args(programInvocation: String, leadingComments: String, trailingComments: String, opts: Seq[Opt[_]], defaults: Map[String, Any], values: Map[String, Any], allValues: Map[String, Seq[Any]], remaining: Seq[String], failures: Seq[(String, Any)]) extends Product with Serializable

    Contains the options defined, the current values, which are the defaults before parsing and afterwards are the defaults overridden by the actual invocation options, and contains any parsing errors that were found, which is empty before parse is called.

    Contains the options defined, the current values, which are the defaults before parsing and afterwards are the defaults overridden by the actual invocation options, and contains any parsing errors that were found, which is empty before parse is called. In order to properly construct the default values, this constructor is protected. Instead, use the companion Args.apply to construct initial instances correctly. Subsequent calls to Args.parse return new, updated instances.

  2. case class Opt[V](name: String, flags: Seq[String], default: Option[V] = None, help: String = "", requiredFlag: Boolean = false)(fromString: (String) ⇒ Try[V]) extends Product with Serializable

    A command-line option, which might actually be required, with a corresponding value.

    A command-line option, which might actually be required, with a corresponding value. It has the following fields:

    • name - serve as a lookup key for retrieving the value.
    • flags - the arguments that invoke the option, e.g., -h and --help.
    • help - a message displayed for command-line help.
    • default - an optional default value, for when the user doesn't specify the option.
    • required - the user must specify this option on the command line. This flag is effectively ignored if a default is provided.
    • parser - An implementation feature for parsing arguments.
    • fromString: String => V - convert the found value from a String to the correct type.
  3. case class ParseError(msg: String, cause: Throwable = null) extends RuntimeException with Product with Serializable

  4. implicit class ToArgs extends AnyRef

    Specify the command-line arguments using a single, multi-line string.

    Specify the command-line arguments using a single, multi-line string. Note the following example:

    import com.concurrentthought.cla._
    
    val args: Args = """
      |java -cp ... foo
      |Some description
      |and a second line.
      |  [-i | --in  | --input       string]             Path to input file.
      |  [-o | --out | --output      string=/dev/null]   Path to output file.
      |  [-l | --log | --log-level   int=3]              Log level to use.
      |   -p | --path                path                Path elements separated by ':' (*nix) or ';' (Windows).
      |  [-q | --quiet               flag]               Suppress some verbose output.
      |       [--things              seq([-|])]          String elements separated by '-' or '|'.
      |                              others              Other stuff.
      |Any additional help description lines,
      |which also have no leading whitespace.
      |""".stripMargin.toArgs

    The format, as illustrated in the example, has the following requirements:

    • Zero or more leading and trailing lines without opening whitespace are interpreted as the "program invocation" string in the help message, followed by zero or more description lines, which will be concatenated together (separated by whitespace) in the help message.
    • Each option appears on a line with leading whitespace.
    • Each option has one or more flags, separated by "|". As a special case, one option can have no flags. It is used to provide a help message for all other command-line tokens that aren't associated with flags (which will be stored in Args.remaining). Note that these tokens are handled whether or not you specify a line like this or not.
    • If the option is not required for the user to specify a value, the flags and name must be wrapped in "[...]". Specifying a default value is effectively the name as not required, but the main purpose is display the expected behavior to the user.
    • After the flags, the "middle column" describes the type of option and optionally a default value. The types correspond to several helper functions in Opt: string, byte, char, int, long, float, double, path, seqString, where the string "seq" is used, followed by a required (delim) suffix to specify the delimiter regex as shown in the example, and flag which indicates a boolean flag where no value is expected, but the flag's presence means true and absence means false. However, for a no-flag option, the value in this column is interpreted as a name for the option for the help message. This is the one case where the string isn't interpreted as a type specifier. The = indicates the default value to use, if present. Current limitations of the type specification include the following: (i) Opt.seq[V] isn't supported in this mechanism, (ii) default values can't be specified for the path or seq types, nor for the no-flag case (an implementation limitation).
    • The remaining text is interpreted as the help string.
    Note

    This is an experimental feature. There are several known limitations:

    • It provides no way to use the predefined flags like Args.quietFlag, although Args.helpFlag and Args.remainingOpt are automatically added if the list of options doesn't explicitly define help and no-flag constructs.
    • The general case of Opt.seq[V] isn't supported, only Opt.seqString.
    • It needs to be tested on a lot more examples.

Value Members

  1. object Args extends Serializable

  2. object CLASampleMain

    Demonstrates how to use the API.

    Demonstrates how to use the API. Try running with different arguments, including --help. Try running the following examples within SBT:

    run-main com.concurrentthought.cla.CLASampleMain -h
    run -h
    run --help
    run -i /in -o /out -l 4 -p a:b --things x-y|z foo bar baz
    run --in /in --out=/out -l=4 --path "a:b" --things=x-y|z -q foo bar baz

    The last example demonstrates that both argflag value and argflag=value syntax is supported. The "[...]" indicate optional arguments, so in this example, you must specify the input argument and at least one token for "others".

  3. object Elems

    A set of "Elements", used for convenient access from clients.

  4. object Help

    Format a help message for the command-line invocation of a program, based on the Args object passed to apply.

  5. object Opt extends Serializable

  6. object OptParser extends Parser

    Parse a line defining an option.

Inherited from AnyRef

Inherited from Any

Ungrouped