glint/flag

Types

Flag descriptions

pub type Description =
  String

Flag data and descriptions

pub type Flag {
  Flag(value: Value, description: Description)
}

Constructors

  • Flag(value: Value, description: Description)

A type that facilitates the usage of new functions for creating Flags

pub type FlagBuilder(a) =
  fn(Internal(a)) -> Flag

An internal representation of flag contents

pub opaque type Internal(a)

Associate flag names to their current values.

pub type Map =
  map.Map(String, Flag)

Supported flag types. The constructors of this Value type can also be used as ValueBuilders

pub type Value {
  B(Internal(Bool))
  I(Internal(Int))
  LI(Internal(List(Int)))
  F(Internal(Float))
  LF(Internal(List(Float)))
  S(Internal(String))
  LS(Internal(List(String)))
}

Constructors

  • B(Internal(Bool))

    Boolean flags, to be passed in as --flag=true or --flag=false. Can be toggled by omitting the desired value like --flag. Toggling will negate the existing value.

  • I(Internal(Int))

    Int flags, to be passed in as --flag=1

  • LI(Internal(List(Int)))

    List(Int) flags, to be passed in as --flag=1,2,3

  • F(Internal(Float))

    Float flags, to be passed in as --flag=1.0

  • LF(Internal(List(Float)))

    List(Float) flags, to be passed in as --flag=1.0,2.0

  • S(Internal(String))

    String flags, to be passed in as --flag=hello

  • LS(Internal(List(String)))

    List(String) flags, to be passed in as --flag=hello,world

ValueBuilder is a conveniency type to describe the constructors of the Value type.

pub type ValueBuilder(a) =
  fn(Internal(a)) -> Value

Constants

pub const prefix: String = "--"

Flag inputs must start with this prefix

Functions

pub fn build(of new: fn(Internal(a)) -> Flag) -> Flag

create a new Flag from a FlagBuilder(a)

pub fn build_map(flags: List(#(String, Flag))) -> Map(
  String,
  Flag,
)

Convert a list of flags to a Map.

pub fn constraint(for flag: fn(Internal(a)) -> Flag, of constraint: fn(
    a,
  ) -> Result(Nil, Snag)) -> fn(Internal(a)) -> Flag

attach a constraint to a Flag

pub fn default(for val: fn(Internal(a)) -> Flag, of default: a) -> fn(
  Internal(a),
) -> Flag

Set the default value for a flag Value

pub fn description(for flag: fn(Internal(a)) -> Flag, of description: String) -> fn(
  Internal(a),
) -> Flag

attach a description to a Flag

pub fn flag_type_help(flag: #(String, Flag)) -> String

Generate the help message contents for a single flag

pub fn flags_help(flags: Map(String, Flag)) -> List(String)

Generate help messages for all flags

pub fn get_bool(from flags: Map(String, Flag), for name: String) -> Result(
  Bool,
  Snag,
)

Gets the current value for the associated bool flag

pub fn get_bool_value(from flag: #(String, Flag)) -> Result(
  Bool,
  Snag,
)

Gets the current value for the provided bool flag

pub fn get_float(from flags: Map(String, Flag), for name: String) -> Result(
  Float,
  Snag,
)

Gets the current value for the associated float flag

pub fn get_float_value(from flag: #(String, Flag)) -> Result(
  Float,
  Snag,
)

Gets the current value for the provided float flag

pub fn get_floats(from flags: Map(String, Flag), for name: String) -> Result(
  List(Float),
  Snag,
)

Gets the current value for the associated floats flag

pub fn get_floats_value(from flag: #(String, Flag)) -> Result(
  List(Float),
  Snag,
)

Gets the current value for the provided floats flag

pub fn get_int(from flags: Map(String, Flag), for name: String) -> Result(
  Int,
  Snag,
)

Gets the current value for the associated int flag

pub fn get_int_value(from flag: #(String, Flag)) -> Result(
  Int,
  Snag,
)

Gets the current value for the provided int flag

pub fn get_ints(from flags: Map(String, Flag), for name: String) -> Result(
  List(Int),
  Snag,
)

Gets the current value for the associated ints flag

pub fn get_ints_value(from flag: #(String, Flag)) -> Result(
  List(Int),
  Snag,
)

Gets the current value for the provided ints flag

pub fn get_string(from flags: Map(String, Flag), for name: String) -> Result(
  String,
  Snag,
)

Gets the current value for the associated string flag

pub fn get_string_value(from flag: #(String, Flag)) -> Result(
  String,
  Snag,
)

Gets the current value for the provided string flag

pub fn get_strings(from flags: Map(String, Flag), for name: String) -> Result(
  List(String),
  Snag,
)

Gets the current value for the associated strings flag

pub fn get_strings_value(from flag: #(String, Flag)) -> Result(
  List(String),
  Snag,
)

Gets the current value for the provided strings flag

pub fn new(of new: fn(Internal(a)) -> Value) -> fn(Internal(a)) ->
  Flag

create a new FlagBuilder from the provided ValueBuilder

pub fn update_flags(in flags: Map(String, Flag), with flag_input: String) -> Result(
  Map(String, Flag),
  Snag,
)

Updates a flag value, ensuring that the new value can satisfy the required type. Assumes that all flag inputs passed in start with – This function is only intended to be used from glint.execute_root

Search Document