Positional inputs. Matched in declaration order.
Basic
command "greet" do
argument :name, type: :string, required: true, help: "Who to greet"
endgreet world # args[:name] == "world"
greet # error: missing required argument(s): <name>Types and coercion
argument :port, type: :integer
argument :ratio, type: :float
argument :enabled, type: :boolean
argument :name, type: :string # defaultOptional arguments
Omit required: true to make an argument optional. Optional arguments must
follow all required ones in declaration order.
argument :source, type: :string, required: true
argument :dest, type: :string # optionalValue placeholders
Override the help-output name:
argument :input, type: :string, value_name: "FILE"
# Usage: convert <FILE>Trailing variadic args
Collect an arbitrary number of trailing tokens under a named key:
command "exec" do
argument :program, type: :string, required: true, help: "Program to run"
trailing_var_arg :args, help: "Arguments to pass through"
endexec ls -- -la /tmp
# args[:program] == "ls"
# args[:args] == ["-la", "/tmp"]If required: true is set on trailing_var_arg, at least one token must be
provided.
Without a declared trailing_var_arg, tokens after -- are available as
args[:rest].
Validation
argument :port, type: :integer,
validate: fn p -> if p in 1024..65_535, do: :ok, else: {:error, "bad port"} endSee Validation for more.
Hidden arguments
argument :internal, type: :string, hide: trueAccepted by the parser; omitted from help output.
See also
- Options -- non-positional flags.
- Help and output --
:display_orderfor arguments.