outil

Types

A positional command line argument.

pub type Argument {
  BoolArgument(name: String)
  FloatArgument(name: String)
  IntArgument(name: String)
  StringArgument(name: String)
}

Constructors

  • BoolArgument(name: String)
  • FloatArgument(name: String)
  • IntArgument(name: String)
  • StringArgument(name: String)

A command line interface to a run function.

pub type Command {
  Command(
    name: String,
    description: String,
    arguments: List(Argument),
    options: List(Opt),
    argv: List(String),
  )
}

Constructors

  • Command(
      name: String,
      description: String,
      arguments: List(Argument),
      options: List(Opt),
      argv: List(String),
    )

The result of executing a command.

pub type CommandResult(a, b) =
  Result(a, CommandReturn(b))

Non-normal return values from executing a command.

pub type CommandReturn(a) {
  CommandLineError(reason: Reason, usage: String)
  CommandError(a)
  Help(usage: String)
}

Constructors

  • CommandLineError(reason: Reason, usage: String)

    An error in parsing the command line.

  • CommandError(a)

    An error in executing the command, a is your error value.

  • Help(usage: String)

    The user asked for help.

A command line option/flag.

pub type Opt {
  Opt(
    long: String,
    short: Option(String),
    description: String,
    value: OptValue,
  )
}

Constructors

  • Opt(
      long: String,
      short: Option(String),
      description: String,
      value: OptValue,
    )

The type and default value of an option.

pub type OptValue {
  BoolOpt
  FloatOpt(default: Float)
  IntOpt(default: Int)
  StringOpt(default: String)
}

Constructors

  • BoolOpt
  • FloatOpt(default: Float)
  • IntOpt(default: Int)
  • StringOpt(default: String)

Functions

pub fn command(
  name: String,
  description: String,
  argv: List(String),
  continue: fn(Command) -> a,
) -> a

Create a command with the given name and description, and pass it to the given continuation function for further configuration.

The command gets a default implementation that returns an error.

pub fn parse_bool(arg: String) -> Result(Bool, Nil)

Parse a Bool from a string.

pub fn print_usage(return: CommandReturn(a)) -> Nil

Convenience function for handling the result of executing a command.

Print usage if there was a command line error or if the user asked for it.

Does nothing if the command returned an application error, assuming that the application will handle it.

pub fn print_usage_and_exit(return: CommandReturn(a)) -> Nil

Convenience function for handling the result of executing a command.

Print usage if there was a command line error or if the user asked for it.

Exit with 2 if there was a command line error, 1 if there was a command error, or 0 if the command was successful.

Search Document