Appearance
Arguments
Arguments define the input schema of a generator.
All parsed inputs are available through the params object inside the generator’s call method. Inputs are normalized and validated before execution begins.
Arguments are divided into two categories: positional arguments and options.
Positional Arguments
Positional arguments are matched by order.
Single Argument
A single positional argument consumes exactly one CLI value.
ruby
arg :namebash
loci g example Johnruby
params.name
# => "John"Variadic Arguments
Variadic arguments capture all remaining positional values.
ruby
arg :name
args :filesbash
loci g example John a.txt b.txt c.txtruby
params.files
# => ["a.txt", "b.txt", "c.txt"]- Only one variadic argument is allowed per generator
- It may be defined in any place, but it always process the tail of argument list.
Options
Options are named inputs passed via flags. They are order-independent.
Boolean Flags
CLI options provided without an explicit value are treated as true. Set the option's default value to false to enable toggle-style flag behavior.
ruby
option :verbose, default: falsebash
loci g example --verboseruby
params.verbose
# => trueIf the flag is not provided:
ruby
params.verbose
# => falseSingle-Value Option
ruby
option :namebash
loci g example --name "Jane Doe"ruby
params.name
# => "Jane Doe"Array Option
Array options accept repeated values.
ruby
option :tags, array: truebash
loci g example --tags ruby --tags git
# or
loci g example --tags=ruby,gitruby
params.tags
# => ["ruby", "git"]Each value is processed independently.
Hash / Map Option
Options with a hash default accept key–value pairs.
ruby
option :meta, default: {}bash
loci g example --meta author:alice version:1.0ruby
params.meta
# => { "author" => "alice", "version" => "1.0" }They can also process nested keys using dot notation, which automatically builds nested structures within the resulting hash.
ruby
option :meta, default: {}bash
loci g example --meta author:alice user.name:bob user.address.city:londonruby
params.meta
# => {
# "author" => "alice",
# "user" => {
# "name" => "bob",
# "address" => {
# "city" => "london"
# }
# }
# }If a key is provided with comma-separated values, it is automatically converted into an array.
bash
loci g example --meta author:alice tags:tag1,tag2,tag3ruby
params.meta
# => {
# "author" => "alice",
# "tags" => ["tag1", "tag2", "tag3"]
# }You can also use array: true with map options. This allows you to pass the same option multiple times to generate a list of nested objects.
ruby
option :users, array: true, default: {}bash
loci g example --users name:alice city:london --users name:bob city:parisruby
params.users
# => [
# { "name" => "alice", "city" => "london" },
# { "name" => "bob", "city" => "paris" }
# ]Input Parameters
Both positional arguments and options support the following parameters.
required
Marks the argument as mandatory.
ruby
option :address, required: trueIf omitted at the CLI, validation fails and execution does not start.
default
Provides a fallback value when no input is given.
ruby
option :environment, default: "dev"bash
loci g exampleruby
params.environment
# => "dev"array
Enables repeated input values.
ruby
option :ids, array: trueruby
params.ids
# => ["1", "2", "3"]Variadic positional arguments behave the same way by default.
type
Casts values after parsing.
ruby
arg :start_date, type: Datebash
loci g example 2025-01-01ruby
params.start_date
# => #<Date: 2025-01-01>
params.start_date.class
# => DateCasting happens automatically before execution.
description
ruby
option :force, description: "Overwrite existing files"Descriptions appear in:
- CLI help output
- AI agent metadata
Transformation Block
A transformation block allows you to normalize values immediately after parsing.
ruby
option :shout do |value|
value.to_s.upcase
endbash
loci g example --shout helloruby
params.shout
# => "HELLO"If type is also specified, the transformation runs before type casting.
For array inputs, the block runs once per element.