Response Files
A response file (also called an args file) lets users store arguments
in a text file and reference it on the command line with a prefix character
(default @). This is useful when the argument list is very long or when the
same set of arguments is reused frequently.
Libraries with similar support: argparse (
fromfile_prefix_chars), javac (@argfile), MSBuild (@file), gcc (@file).
Enabling Response Files
Call response_file_prefix() on your command to enable the feature:
var command = Command("mytool", "My CLI tool")
command.response_file_prefix() # default '@'
Now mytool @args.txt reads arguments from args.txt, with each line
becoming a separate argument.
File Format
Each non-empty line in the response file becomes one argument. Lines starting
with # are comments and are ignored. Leading and trailing whitespace per line
is stripped.
# args.txt — common flags for the build
--verbose
--output=build/release
--jobs=4
# source files
src/main.mojo
src/utils.mojo
mytool @args.txt
# equivalent to: mytool --verbose --output=build/release --jobs=4 src/main.mojo src/utils.mojo
Response file arguments can be mixed freely with direct CLI arguments:
mytool --debug @args.txt --extra-flag
Escaping the Prefix
To pass a literal token that starts with @ (e.g., an email address), double
the prefix:
mytool @@user@example.com
# parsed as: @user@example.com
The same escape works inside response files:
# users.txt
@@admin
@@guest
Recursive Response Files
Response files may reference other response files:
# base-args.txt
--verbose
# build-args.txt
@base-args.txt
--output=build/release
mytool @build-args.txt
# expands to: mytool --verbose --output=build/release
Recursion depth is limited to 10 by default. Adjust with
response_file_max_depth[depth]():
command.response_file_max_depth[5]()
A self-referencing or circular response file triggers an error once the depth limit is reached.
Custom Prefix
Use a different prefix character if @ conflicts with your argument values:
command.response_file_prefix("+")
# Now: mytool +args.txt