Command

clam.dispatch.Command
See theCommand companion object
class Command(val name: String, val description: String, val pdefs: ArrayBuffer[ParamDef], var parse: (Command, Context, Result) => Result[Any], var action: Option[Any => Result[Any]], val builtins: Map[String, Command], var listExternalCommands: () => Iterable[String], var callExternalCommand: Option[(Context, Iterator[String]) => String => Result[Any]], var makeHelp: (Command, Context) => String) extends (Context, Iterator[String]) => Result[Any]

An entrypoint to the application

When a command is called, it goes through two phases:

  1. argument parsing (this may alter the available subcommands)
  2. running an action or subcommand

A command can be in a tree, but it is designed to be callable as a top-level entrypoint. As such, parent args must be stored in a global context, usually the environment.

When a command is called, it will first parse arguments depending on its parameter definitions. Then, depending on the remainder, a subcommand may be called.

Attributes

action

A function to call with the extracted result

builtins

Subcommand candidates to call

extract

A function that is called with the command's arguments, and whose result may be passed to an action if one is defined. The arguments are: (context, result, next), where:

  • context: the global (mutable) context. Values may be passed to subcommands by putting them in this context
  • result: the getopt parameter result from the pdefs
  • next: whether or not a subcommand will be called
pdefs

The parameter definitions

Companion:
object
Graph
Supertypes
trait (Context, Iterator[String]) => Result[Any]
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def apply(ctx: Context, args: Iterator[String]): Result[Any]
def parse(args: Iterable[String], stdout: PrintStream, stderr: PrintStream, env: Map[String, String], terminal: Terminal, exit: Int => Nothing): Result[Any]
def parseOrExit(args: Iterable[String], stdout: PrintStream, stderr: PrintStream, env: Map[String, String], terminal: Terminal, exit: Int => Nothing): Any
def printHelp(ctx: Context): Unit

Inherited methods

def curried: T1 => T2 => R

Attributes

Inherited from:
Function2
override def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns:

a string representation of the object.

Definition Classes
Function2 -> Any
Inherited from:
Function2
def tupled: ((T1, T2)) => R

Attributes

Inherited from:
Function2

Concrete fields

var action: Option[Any => Result[Any]]
val builtins: Map[String, Command]
var callExternalCommand: Option[(Context, Iterator[String]) => String => Result[Any]]
val description: String
var listExternalCommands: () => Iterable[String]
var makeHelp: (Command, Context) => String
val name: String
var parse: (Command, Context, Result) => Result[Any]
val pdefs: ArrayBuffer[ParamDef]