glint
Types
Input type for Runner
.
pub type CommandInput {
CommandInput(args: List(String), flags: FlagMap)
}
Constructors
-
CommandInput(args: List(String), flags: FlagMap)
CommandNode tree representation.
pub opaque type CommandNode(a)
Config for glint
pub type Config(a) {
Config(pretty_help: Option(PrettyHelp))
}
Constructors
-
Config(pretty_help: Option(PrettyHelp))
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
PrettyHelp defines the header colours to be used when styling help text
pub type PrettyHelp {
PrettyHelp(usage: Colour, flags: Colour, subcommands: Colour)
}
Constructors
-
PrettyHelp(usage: Colour, flags: Colour, subcommands: Colour)
DEPRECATED: use glint.cmd
and related builder functions instead to create a Command
Create command stubs to be used in add_command_from_stub
pub type Stub(a) {
Stub(
path: List(String),
run: Runner(a),
flags: List(#(String, Flag)),
description: String,
)
}
Constructors
-
Stub( path: List(String), run: Runner(a), flags: List(#(String, Flag)), description: String, )
Constants
Functions
pub fn add(to glint: Glint(a), at path: List(String), do contents: Command(
a,
)) -> 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)
DEPRECATED: use glint.cmd
and related builder functions instead to create a Command
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 description(cmd: Command(a), description: String) -> Command(
a,
)
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.
This function does not print its output and is mainly intended for use within glint
itself.
If you would like to print or handle the output of a command please see the run_and_handle
function.
pub fn help_flag() -> String
Function to create the help flag string Exported for testing purposes only
pub fn run(from glint: Glint(a), for args: List(String)) -> Nil
A wrapper for execute
that prints any errors enountered or the help text if requested.
This function ignores any value returned by the command that was run.
If you would like to do something with the command output please see the run_and_handle function.
pub fn run_and_handle(from glint: Glint(a), for args: List(String), with handle: fn(
a,
) -> b) -> Nil
A wrapper for execute
that prints any errors enountered or the help text if requested.
This function calls the provided handler with the value returned by the command that was run.
pub fn with_config(glint: Glint(a), config: Config(a)) -> Glint(a)
Add the provided config to the existing command tree
pub fn with_global_flag(glint: Glint(a), at key: String, of flag: Flag) -> Glint(
a,
)
Add global flags to the existing command tree
pub fn with_global_flags(glint: Glint(a), flags: List(
#(String, Flag),
)) -> 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