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
-[ ]**Long option prefix matching** — `--verb` auto-resolves to `--verbose` when unambiguous (argparse `allow_abbrev`)
220
+
-[ ]**Append / collect action** — `--tag x --tag y` → `["x", "y"]` collects repeated options into a list (argparse `append`, cobra `StringArrayVar`, clap `Append`)
221
+
-[ ]**One-required group** — `cmd.one_required(["json", "yaml"])` requires at least one from the group (cobra `MarkFlagsOneRequired`, clap `ArgGroup::required`)
213
222
-[ ]**Aliases** for long names — `.aliases(["colour"])` for `--color`
Copy file name to clipboardExpand all lines: docs/user_manual.md
+73-7Lines changed: 73 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ myapp "hello" ./src
45
45
# pattern path
46
46
```
47
47
48
-
Positional arguments are assigned in the order they are registered with `add_arg()`. If fewer values are provided than defined arguments, the remaining ones use their default values (if any). If more are provided, an error is raised (see [Positional Arg Count Validation](#16-positional-arg-count-validation)).
48
+
Positional arguments are assigned in the order they are registered with `add_arg()`. If fewer values are provided than defined arguments, the remaining ones use their default values (if any). If more are provided, an error is raised (see [Positional Arg Count Validation](#17-positional-arg-count-validation)).
49
49
50
50
**Retrieving:**
51
51
@@ -388,7 +388,73 @@ Each group is validated independently — using `--json` and `--no-color` togeth
388
388
389
389
> **Note:** Pass the `List[String]` with `^` (ownership transfer).
390
390
391
-
## 15. Required-Together Groups
391
+
## 15. Negatable Flags
392
+
393
+
A **negatable** flag automatically creates a `--no-X` counterpart. When the user passes `--X`, the flag is set to `True`; when they pass `--no-X`, it is explicitly set to `False`.
394
+
395
+
This replaces the manual pattern of defining two separate flags (`--color` and `--no-color`) and a mutually exclusive group.
396
+
397
+
### Defining a negatable flag
398
+
399
+
```mojo
400
+
cmd.add_arg(
401
+
Arg("color", help="Enable colored output")
402
+
.long("color").flag().negatable()
403
+
)
404
+
```
405
+
406
+
### Behaviour
407
+
408
+
```bash
409
+
myapp --color # color = True, has("color") = True
410
+
myapp --no-color # color = False, has("color") = True
411
+
myapp # color = False, has("color") = False (default)
412
+
```
413
+
414
+
Use `result.has("color")` to distinguish between "user explicitly disabled colour" (`--no-color`) and "user didn't mention colour at all".
myapp "hello" ./src /tmp # Error: Too many positional arguments: expected 2, got 3
485
551
```
486
552
487
-
## 17. The `--` Stop Marker
553
+
## 18. The `--` Stop Marker
488
554
489
555
A bare `--` tells the parser to **stop interpreting options**. Everything after `--` is treated as a positional argument, even if it looks like an option.
490
556
@@ -508,7 +574,7 @@ myapp --ling -- "-v is not a flag here" ./src
508
574
# path = "./src"
509
575
```
510
576
511
-
## 18. Auto-generated Help
577
+
## 19. Auto-generated Help
512
578
513
579
Every command automatically supports `--help` (or `-h`). The help text is generated from the registered argument definitions.
514
580
@@ -552,7 +618,7 @@ Options:
552
618
553
619
After printing help, the program exits cleanly with exit code 0.
554
620
555
-
## 19. Version Display
621
+
## 20. Version Display
556
622
557
623
Every command automatically supports `--version` (or `-V`).
558
624
@@ -575,7 +641,7 @@ var cmd = Command("myapp", "Description", version="1.0.0")
575
641
576
642
After printing the version, the program exits cleanly with exit code 0.
577
643
578
-
## 20. Reading Parsed Results
644
+
## 21. Reading Parsed Results
579
645
580
646
After calling `cmd.parse()` or `cmd.parse_args()`, you get a `ParseResult` with these typed accessors:
0 commit comments