ParsersApi

argparse.core.ParsersApi

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Api
object default.type
trait MacroApi
trait OutputApi
Self type

Members list

Concise view

Type members

Classlikes

class ArgumentParser(val description: String, val helpFlags: Seq[String], val bashCompletionFlags: Seq[String])

A simple command line argument parser.

A simple command line argument parser.

Usage:

  1. Define parameters with param, requiredParam and repeatedParam. Each of these methods gives back a handle to a future argument value.

  2. Call parseOrExit() with actual arguments.

  3. If parsing succeeds, the arguments will be available in the handles defined in step 1.

If parsing fails, error descriptions are printed and the program exits with 2.

Example:

val parser = argparse.default.ArgumentParser()

val p1 = parser.param[String]("--this-is-a-named-param", default = "default value")
val p2 = parser.param[Int]("positional-param", default = 2)

parser.parseOrExit(Seq("--this-is-a-named-param=other", 5))
println(p1.value)
println(p2.value)

Attributes

bashCompletionFlag

Use these flags to print a sourceable bash-completion script. Set to empty to disable.

description

A short description of this command. Used in help messages.

helpFlags

Use these flags to print the help message. Set to empty to disable.

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Value members

Concrete methods

The name of the flag to use for generating standalone bash-completion.

The name of the flag to use for generating standalone bash-completion.

Set this to empty to disable bash-completion entirely.

Note that individual argument parsers may override this.

Attributes

def defaultHelpFlags: Seq[String]

The name of the flag to use for printing help messages.

The name of the flag to use for printing help messages.

Set this to empty to disable help entirely.

Note that individual argument parsers may override this.

Attributes

def defaultHelpMessage(parser: ArgumentParser): String

Generate a help message from parameters.

Generate a help message from parameters.

This message will be used by ArgumentParsers. Overriding this allows you to customize the help message of all ArgumentParsers.

Attributes

protected def exit(code: Int): Nothing

Called by parseOrExit in case of error.

Called by parseOrExit in case of error.

Overriding this can be useful in situations where you do not want to exit, for example in tests.

Attributes