Arguments v0.1.0 Arguments View Source
Arguments provides a module with argument parsing through YourArguments.parse(incoming)
use Arguments
There are two styles of arguments allowed
command-$ cmd new projectflag-$ cmd --dir /etc
These two styles can be mixed, but the flags will always take priority
Full Example:
module MyArguments do
use Arguments
command "new", do: [
arguments: [:name, :dir]
]
flag "name", do: [
type: :string,
alias: :n,
defaults: fn (n) -> [
dir: "./#{n}"
] end
]
flag "more", do: %{
type: :boolean,
alias: :m
}
flag "dir", do: [
type: :string
]
end
iex> MyArguments.parse(["--name", "myname"])
%{name: "myname", dir: "./myname"}
iex> MyArguments.parse(["new", "myname", "dirhere"])
%{new: true, name: "myname", dir: "dirhere"}
iex> MyArguments.parse(["--more"])
%{more: true}
iex> MyArguments.parse(["-m"])
%{more: true}
Link to this section Summary
Link to this section Functions
Defines a command style argument
A command is an ordered set of flags with a boolean flag for itself
Required Options:
arguments:(list of atoms) [:arg0, arg1] e.g. [:name, :dir]Example
command "new", do [arguments: [:name, :dir]]$ cmd new MyName YourDir%{new: true, name: "MyName", dir: "YourDir"}
Optional Uncommon Options:
name:(atom) Double dash name, e.g.:dir->--dir(defaults to command [name])
Defines a flag style argument
Required Options:
type:(atom) Argument type fromOptionParser.parse/1:stringparses the value as a string:booleansets the value to true when given:countcounts the number of times the switch is given:integerparses the value as an integer:floatparses the value as a float
Optional Common Options:
alias:(atom) Single dash name, e.g.:d->-ddefaults:(fn(value) | list) If the flag is set, the defaults will be applied- The end result must be a keyword list. The function form may NOT use anything from outside, but will be passed in the value of the flag.
Example:
defaults: fn(name) -> [dir: "./#{name}"] end$ cmd --name myname%{name: "myname", dir: "./myname"}
Optional Uncommon Options:
name:(atom) Double dash name, e.g.:dir->--dir(defaults to flag [name])