std/cli/argument

std/cli/src/argument.trb

Argument: the types an option of a command can have. An option is declared with its type, option<Int>("jobs"), and the text after --jobs is checked against it while the command line is read, so a value that does not fit is an error of the command line and never of the program.

trait Argument

trait Argument with Show

A type that an option can be read as: it says what its name is in a message and how text becomes a value. Int, Float64, Bool and String have it; a type of the program gets it with an extend:

use Argument from "std/cli"

type Level {
  case Low
  case High
}

extend Level with Argument {
  static fn argumentName(): String {
    "level"
  }

  static fn fromArgument(text: String): Result<Self, String> {
    match text {
      "low" => Ok Level.Low
      "high" => Ok Level.High
      _ => Fail "neither low nor high"
    }
  }
}

Show is how a default is written in the help text.

fn argumentName

static fn argumentName(): String

What the type is called in the help text, as in --jobs <integer>.

fn fromArgument

static fn fromArgument(text: String): Result<Self, String>

The value that text stands for, or why it does not. The error reads 'text' is <reason>: "not an integer".

extend Int with Argument

extend Int with Argument

Whole numbers: an optional sign and digits.

fn argumentName

static fn argumentName(): String

fn fromArgument

static fn fromArgument(text: String): Result<Self, String>

extend Float64 with Argument

extend Float64 with Argument

Decimal numbers.

fn argumentName

static fn argumentName(): String

fn fromArgument

static fn fromArgument(text: String): Result<Self, String>

extend Bool with Argument

extend Bool with Argument

true or false, and nothing else.

fn argumentName

static fn argumentName(): String

fn fromArgument

static fn fromArgument(text: String): Result<Self, String>

extend String with Argument

extend String with Argument

Any text.

fn argumentName

static fn argumentName(): String

fn fromArgument

static fn fromArgument(text: String): Result<Self, String>