glint

Types

Result type for command execution

pub type CmdResult(a) =
  Result(Out(a))

Command tree representation.

pub opaque type Command(a)

Input type for Runner.

pub type CommandInput {
  CommandInput(args: List(String), flags: FlagMap)
}

Constructors

  • CommandInput(args: List(String), flags: FlagMap)

Config for glint

pub type Config {
  Config(pretty_help: Option(PrettyHelp))
}

Constructors

  • Config(pretty_help: Option(PrettyHelp))

Command contents

pub opaque type Contents(a)

Glint container type for config and commands

pub opaque type Glint(a)

Ok type for command execution

pub type Out(a) {
  Out(a)
  Help(String)
}

Constructors

  • Out(a)

    Container for the command return value

  • Help(String)

    Container for the generated help string

pub type PrettyHelp {
  PrettyHelp(usage: Colour, flags: Colour, subcommands: Colour)
}

Constructors

  • PrettyHelp(usage: Colour, flags: Colour, subcommands: Colour)
pub type RGB =
  #(Int, Int, Int)

Function type to be run by glint.

pub type Runner(a) =
  fn(CommandInput) -> a

Create command stubs to be used in add_command_from_stub

pub type Stub(a) {
  Stub(
    path: List(String),
    run: Runner(a),
    flags: List(Flag),
    description: String,
  )
}

Constructors

  • Stub(
      path: List(String),
      run: Runner(a),
      flags: List(Flag),
      description: String,
    )

Constants

pub const default_config: Config = Config(pretty_help: None)

Default config

Functions

pub fn add_command(to glint: Glint(a), at path: List(String), do f: fn(
    CommandInput,
  ) -> a, with flags: List(#(String, Contents)), described description: String) -> Glint(
  a,
)

Adds a new command to be run at the specified path.

If the path is [], the root command is set with the provided function and flags.

Note: all command paths are sanitized by stripping whitespace and removing any empty string elements.

pub fn add_command_from_stub(to glint: Glint(a), with stub: Stub(
    a,
  )) -> Glint(a)

Add a command to the root given a stub

pub fn default_pretty_help() -> PrettyHelp

Default pretty help heading colouring mint (r: 182, g: 255, b: 234) colour for usage pink (r: 255, g: 175, b: 243) colour for flags buttercup (r: 252, g: 226, b: 174) colour for subcommands

pub fn execute(glint: Glint(a), args: List(String)) -> Result(
  Out(a),
  Snag,
)

Determines which command to run and executes it.

Sets any provided flags if necessary.

Each value prefixed with -- is parsed as a flag.

pub fn help_flag() -> String

Function to create the help flag string Exported for testing purposes only

pub fn new() -> Glint(a)

Creates a new command tree.

pub fn run(glint: Glint(a), args: List(String)) -> Nil

A wrapper for execute that discards output and prints any errors encountered.

pub fn with_config(glint: Glint(a), config: Config) -> Glint(a)

Add the provided config to the existing command tree

pub fn with_global_flags(glint: Glint(a), flags: List(
    #(String, Contents),
  )) -> Glint(a)

Add global flags to the existing command tree

pub fn with_pretty_help(glint: Glint(a), pretty: PrettyHelp) -> Glint(
  a,
)

Enable custom colours for help text headers For a pre-made colouring use default_pretty_help()

pub fn without_pretty_help(glint: Glint(a)) -> Glint(a)

Disable custom colours for help text headers

Search Document