Positional inputs. Matched in declaration order.

Basic

command "greet" do
  argument :name, type: :string, required: true, help: "Who to greet"
end
greet 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   # default

Optional 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   # optional

Value 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"
end
exec 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"} end

See Validation for more.

Hidden arguments

argument :internal, type: :string, hide: true

Accepted by the parser; omitted from help output.

See also