clip/arg
Functions for building Args. An Arg is a positional option.
Types
Functions
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 run(
arg: Arg(a),
args: List(String),
) -> Result(#(a, List(String)), String)
Run an Arg(a) against a list of arguments. Used internally by clip, not
intended for direct usage.
pub fn run_many(
arg: Arg(a),
args: List(String),
) -> Result(#(List(a), List(String)), String)
Run an Arg(a) against a list of arguments producing zero or more results.
Used internally by clip, not intended for direct usage.
pub fn run_many1(
arg: Arg(a),
args: List(String),
) -> Result(#(List(a), List(String)), String)
Run an Arg(a) against a list of arguments producing one or more results.
Used internally by clip, not intended for direct usage.
pub fn to_arg_info(arg: Arg(a)) -> ArgInfo
Used internally, not intended for direct usage.
pub fn to_arg_info_many(arg: Arg(a)) -> ArgInfo
Used internally, not intended for direct usage.
pub fn to_arg_info_many1(arg: Arg(a)) -> ArgInfo
Used internally, not intended for direct usage.
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.