clip/arg
Functions for building Args. An Arg is a positional option.
Types
Values
pub fn default(arg: Arg(a), default: a) -> Arg(a)
Provide a default value for an Arg when it is not provided by the user.
pub fn float(arg: Arg(String)) -> Arg(Float)
Modify an Arg(String) to produce a Float.
arg.new("height")
|> arg.float
Note: float changes the type of an Arg and therefore clears any
previously set default value.
pub fn int(arg: Arg(String)) -> Arg(Int)
Modify an Arg(String) to produce an Int.
arg.new("age")
|> arg.int
Note: int changes the type of an Arg and therefore clears any
previously set default value.
pub fn map(arg: Arg(a), f: fn(a) -> b) -> Arg(b)
Modify the value produced by an Arg in a way that cannot fail.
arg.new("name")
|> arg.map(fn(name) { string.uppercase(name) })
Note: map can change the type of an Arg and therefore clears any
previously set default value.
pub fn new(name: String) -> Arg(String)
Create a new Arg with the provided name. New Args always initially
produce a String, which is the unmodified value given by the user on the
command line.
pub fn optional(arg: Arg(a)) -> Arg(Result(a, Nil))
Transform an Arg(a) to an Arg(Result(a, Nil), making it optional.
pub fn try_map(
arg: Arg(a),
f: fn(a) -> Result(b, String),
) -> Arg(b)
Modify the value produced by an Arg in a way that may fail.
arg.new("age")
|> arg.try_map(fn(age_str) {
case int.parse(age_str) {
Ok(age) -> Ok(age)
Error(Nil) -> Error("Unable to parse integer")
}
})
Note: try_map can change the type of an Arg and therefore clears any
previously set default value.