You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[core] Implement response file (but temporarily not exposed to users due to issues when setting ASSERT=all) (#13)
This PR adds opt-in “response file” (`@args.txt`) expansion to ArgMojo
commands, plus documentation/examples/tests, and clarifies
`default_if_no_value` semantics.
However, this functionality is temporarily not exposed to users due to
issues when setting `ASSERT=all` (the issue is related to `with
open()`).
**Changes:**
- Add response-file parsing support to `Command` (prefix + recursion
depth), expanding `@file` tokens into per-line arguments.
- Add a dedicated response-file test suite and wire it into the test
runner.
- Update docs/examples/changelog and adjust `default_if_no_value`
wording + a related test rename.
Copy file name to clipboardExpand all lines: docs/changelog.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,10 +13,18 @@ Comment out unreleased changes here. This file will be edited just before each r
13
13
1. Add `.default_if_no_value("value")` builder method for default-if-no-value semantics. When an option has a default-if-no-value, it may appear without an explicit value: `--compress` uses the default-if-no-value, while `--compress=bzip2` uses the explicit value. For long options, `.default_if_no_value()` implies `.require_equals()`. For short options, `-c` uses the default-if-no-value while `-cbzip2` uses the attached value (PR #12).
14
14
2. Add `.require_equals()` builder method. When set, long options reject space-separated syntax (`--key value`) and require `--key=value`. Can be used standalone (the value is mandatory via `=`) or combined with `.default_if_no_value()` (the value is optional; omitting it uses default-if-no-value) (PR #12).
15
15
3. Help output adapts to the new modifiers: `--key=<value>` for require_equals, `--key[=<value>]` for default_if_no_value (PR #12).
16
+
4.~~Add `response_file_prefix()` builder method on `Command` for response-file support. When enabled, tokens starting with the prefix (default `@`) are expanded by reading the referenced file — each non-empty, non-comment line becomes a separate argument. Supports comments (`#`), escape (`@@literal`), recursive nesting (configurable depth), and custom prefix characters (PR #12).~~*(Temporarily disabled — triggers a Mojo compiler deadlock under `-D ASSERT=all`. The implementation is preserved as module-level functions and will be re-enabled when the Mojo compiler bug is fixed.)*
17
+
18
+
### 🔧 Fixes
19
+
20
+
- Clarify documentation and docstrings: `default_if_no_value` does not "reject" `--key value`; it simply does not consume the next token as a value (PR #12, review feedback).
21
+
- Fix cross-library comparison: click is described as "Python CLI framework" instead of incorrectly saying "built on top of argparse" (PR #12, review feedback).
22
+
- Reject `.require_equals()` / `.default_if_no_value()` combined with `.number_of_values[N]()` at `add_argument()` time with a clear error (PR #12, review feedback).
16
23
17
24
### 📚 Documentation and testing
18
25
19
26
- Add `tests/test_const_require_equals.mojo` with 30 tests covering default_if_no_value, require_equals, and their interactions with choices, append, prefix matching, merged short flags, persistent flags, and help formatting (PR #12).
-[Disabling the Built-in Flag](#disabling-the-built-in-flag)
@@ -2062,7 +2070,7 @@ Options:
2062
2070
2063
2071
Use `.default_if_no_value("value")` to make an option's value **optional**. When the option is present without an explicit value, the default-if-no-value is used. When an explicit value is provided (via `=` for long options, or attached for short options), that value is used instead.
2064
2072
2065
-
`.default_if_no_value()` automatically implies `.require_equals()` for long options, so `--keyvalue`(space-separated) is rejected — the user must write `--key=value`to supply an explicit value.
2073
+
`.default_if_no_value()` automatically implies `.require_equals()` for long options in the sense that `=` is required to attach an *explicit* value. A bare `--key` is still accepted and uses the default-if-no-value; `--key value`(space-separated) does *not* treat `value` as the argument to `--key` but leaves it to be parsed as a positional argument or another option. To supply an explicit value to the option itself, the user must write `--key=value`.
2066
2074
2067
2075
```mojo
2068
2076
command.add_argument(
@@ -2545,6 +2553,107 @@ myapp -- -10.18
2545
2553
2546
2554
> **Tip:** ArgMojo's [Auto-detect](#negative-number-passthrough) can handle most negative-number cases without `--`. Use `--` only when auto-detect is insufficient (e.g., a digit short option is registered without `allow_negative_numbers()`).
The implementation is preserved as module-level functions and will be re-enabled
2558
+
when the Mojo compiler bug is fixed.
2559
+
2560
+
## Response Files
2561
+
2562
+
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.
2563
+
2564
+
> Libraries with similar support: **argparse** (`fromfile_prefix_chars`), **javac** (`@argfile`), **MSBuild** (`@file`), **gcc** (`@file`).
2565
+
2566
+
### Enabling Response Files
2567
+
2568
+
Call `response_file_prefix()` on your command to enable the feature:
2569
+
2570
+
```mojo
2571
+
var command = Command("mytool", "My CLI tool")
2572
+
command.response_file_prefix() # default '@'
2573
+
```
2574
+
2575
+
Now `mytool @args.txt` reads arguments from `args.txt`, with each line becoming a separate argument.
2576
+
2577
+
### File Format
2578
+
2579
+
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.
2580
+
2581
+
```text
2582
+
# args.txt — common flags for the build
2583
+
--verbose
2584
+
--output=build/release
2585
+
--jobs=4
2586
+
2587
+
# source files
2588
+
src/main.mojo
2589
+
src/utils.mojo
2590
+
```
2591
+
2592
+
```bash
2593
+
mytool @args.txt
2594
+
# equivalent to: mytool --verbose --output=build/release --jobs=4 src/main.mojo src/utils.mojo
2595
+
```
2596
+
2597
+
Response file arguments can be mixed freely with direct CLI arguments:
2598
+
2599
+
```bash
2600
+
mytool --debug @args.txt --extra-flag
2601
+
```
2602
+
2603
+
### Escaping the Prefix
2604
+
2605
+
To pass a literal token that starts with `@` (e.g., an email address), double the prefix:
2606
+
2607
+
```bash
2608
+
mytool @@user@example.com
2609
+
# parsed as: @user@example.com
2610
+
```
2611
+
2612
+
The same escape works inside response files:
2613
+
2614
+
```text
2615
+
# users.txt
2616
+
@@admin
2617
+
@@guest
2618
+
```
2619
+
2620
+
### Recursive Response Files
2621
+
2622
+
Response files may reference other response files:
2623
+
2624
+
```text
2625
+
# base-args.txt
2626
+
--verbose
2627
+
2628
+
# build-args.txt
2629
+
@base-args.txt
2630
+
--output=build/release
2631
+
```
2632
+
2633
+
```bash
2634
+
mytool @build-args.txt
2635
+
# expands to: mytool --verbose --output=build/release
2636
+
```
2637
+
2638
+
Recursion depth is limited to 10 by default. Adjust with `response_file_max_depth()`:
2639
+
2640
+
```mojo
2641
+
command.response_file_max_depth(5)
2642
+
```
2643
+
2644
+
A self-referencing or circular response file triggers an error once the depth limit is reached.
2645
+
2646
+
### Custom Prefix
2647
+
2648
+
Use a different prefix character if `@` conflicts with your argument values:
2649
+
2650
+
```mojo
2651
+
command.response_file_prefix("+")
2652
+
# Now: mytool +args.txt
2653
+
```
2654
+
2655
+
end of Response Files section -->
2656
+
2548
2657
## Shell Completion
2549
2658
2550
2659
ArgMojo can generate **shell completion scripts** for Bash, Zsh, and Fish. These scripts enable tab-completion for your CLI's options, flags, subcommands, and choice values — with zero runtime overhead.
@@ -2701,7 +2810,7 @@ The generated scripts cover the full command tree:
2701
2810
2702
2811
The table below maps every ArgMojo builder method / command-level method to its equivalent in four popular CLI libraries. **An empty cell means the name is identical (or near-identical) to ArgMojo's.** A filled cell shows the other library's name or approach. **—** means the library has no built-in equivalent.
2703
2812
2704
-
> Libraries compared: **argparse** (Python stdlib), **click** (Python, built on top of argparse), **clap** (Rust, derive & builder API), **cobra / pflag** (Go).
0 commit comments