Skip to content

Commit a256448

Browse files
committed
[doc] Update documents
1 parent 96fd4e8 commit a256448

File tree

3 files changed

+85
-100
lines changed

3 files changed

+85
-100
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The following table summarizes the package versions and their corresponding Mojo
8686
| ----------------- | -------------- | --------------- |
8787
| 0.1.0 | ==0.26.1 | pixi |
8888
| 0.2.0 | ==0.26.1 | pixi |
89+
| 0.3.0 | ==0.26.1 | pixi |
8990

9091
## Quick Start
9192

docs/changelog.md

Lines changed: 83 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,79 @@ This document tracks all notable changes to ArgMojo, including new features, API
66
Comment out unreleased changes here. This file will be edited just before each release to reflect the final changelog for that version.
77
-->
88

9-
<!--
10-
## 20260303 (v0.3.0)
9+
## 20260305 (v0.3.0)
1110

12-
ArgMojo v0.3.0 enables shell completion script generation for Bash, Zsh, and Fish.
11+
ArgMojo v0.3.0 adds shell completion, typo suggestions, mutual implication, hidden subcommands, `NO_COLOR` support, and several builder-method improvements. Internally the code is decomposed into smaller helpers and a new `utils.mojo` module; several API names are refined for consistency. Two breaking changes affect call sites that use `nargs`, `max`, or `range` (now compile-time parameters) and the renamed methods listed below.
12+
13+
ArgMojo v0.3.0 is compatible with Mojo v0.26.1.
1314

1415
### ⭐️ New in v0.3.0
15-
1. completion (PR #4)
16-
1. typo suggestions (PR #3)
17-
1. Command aliases (PR #5)
18-
1. Range clamping with warning message if users pass out-of-range values (#6)
19-
1. Compile-time parameter APIs: `.max[ceiling]()`, `.range[min, max]()`, `.number_of_values[N]()` replace the former runtime methods (PR #8). **Breaking change**: callers must update call sites.
20-
1. Hidden subcommands — `Command.hidden()` excludes a subcommand from help output, shell completions, available-commands error messages, and typo suggestions while keeping it dispatchable by exact name or alias (PR #9)
21-
1. `NO_COLOR` environment variable support — when `NO_COLOR` is set (any value, including empty), all ANSI colour output from `_generate_help()`, `_warn()`, `_error()`, and `_error_with_usage()` is suppressed, following the [no-color.org](https://no-color.org/) standard (PR #9)
22-
1. Mutual implication — `Command.implies(trigger, implied)` automatically sets one argument when another is present. Supports chained implications (A → B → C) with cycle detection at registration time. Works with flags, count arguments, and integrates with existing constraints (`required_if`, `mutually_exclusive`) (PR #10)
2316

24-
### 🦋 Changed in v0.2.0
25-
-->
17+
1. Implement shell completion script generation for Bash, Zsh, and Fish, with a built-in `--completions <shell>` flag that emits a ready-to-source script (PR #4).
18+
2. Allow disabling the built-in flag (`disable_default_completions()`), customising the trigger name (`completions_name()`), or exposing completions as a subcommand (`completions_as_subcommand()`) (PR #4).
19+
3. Add Levenshtein-distance based "did you mean ...?" suggestions for misspelled long options and subcommand names (PR #3).
20+
4. Implement `command_aliases()` on `Command` to register alternative names for subcommands. Aliases are shown in help, accepted during dispatch, and included in shell completions and typo suggestions (PR #5).
21+
5. Add `.clamp()` modifier for `.range[min, max]()` -- out-of-range values are adjusted to the nearest boundary with a warning instead of a hard error (PR #6).
22+
6. Move count-ceiling enforcement (`.max[N]()`) and range validation into the `_validate()` phase so all post-parse checks run in a single pass (PR #6).
23+
7. Parameterise `.max[ceiling]()`, `.range[min, max]()`, and `.number_of_values[N]()` as compile-time parameters, enabling build-time validation of invalid values (PR #8).
24+
8. Add `Command.hidden()` builder method. Hidden subcommands are excluded from help output, shell completions, "Available commands" error messages, and typo suggestions, while remaining dispatchable by exact name or alias (PR #9).
25+
9. Honour the `NO_COLOR` environment variable (any value, including empty). When set, all ANSI colour output from help, warning, and error messages is suppressed, following the no-color.org standard (PR #9).
26+
10. Add `Command.implies(trigger, implied)` to automatically set one argument when another is present. Supports chained implications (A -> B -> C) with cycle detection at registration time. Works with flags and count arguments, and integrates with existing constraints (`required_if`, `mutually_exclusive`) (PR #10).
27+
28+
### 🦋 Changed in v0.3.0
29+
30+
1. `parse_args()` renamed to `parse_arguments()` (PR #5).
31+
2. `help_on_no_args()` renamed to `help_on_no_arguments()` (PR #5).
32+
3. `.nargs()` renamed to `.number_of_values()` and `nargs_count` field renamed to `_number_of_values` (PR #5).
33+
4. Several `Argument` and `ParseResult` attributes are now underscore-prefixed (private). Public builder methods are unchanged (PR #7).
34+
5. Decompose `parse_args()` into four sub-methods: `_parse_long_option()`, `_parse_short_single()`, `_parse_short_merged()`, `_dispatch_subcommand()` (PR #2).
35+
6. Decompose `_generate_help()` into five sub-methods: `_help_usage_line()`, `_help_positionals_section()`, `_help_options_section()`, `_help_commands_section()`, `_help_tips_section()` (PR #2).
36+
7. Extract ANSI colour constants and utility functions into a new internal module `utils.mojo` (PR #2).
37+
8. Rename example files to avoid confusion: `git.mojo` -> `mgit.mojo`, `grep.mojo` -> `mgrep.mojo`.
38+
9. Add `examples/demo.mojo` -- a comprehensive showcase of all ArgMojo features in a single CLI (PR #7).
39+
40+
### 📚 Documentation and testing in v0.3.0
41+
42+
- Add `tests/test_typo_suggestions.mojo` covering Levenshtein-based suggestions (PR #3).
43+
- Add `tests/test_completion.mojo` with comprehensive tests for Bash, Zsh, and Fish script generation (PR #4).
44+
- Add `tests/test_implies.mojo` covering basic, chained, and multi-target implications, cycle detection, and constraint integration (PR #10).
45+
- Add builder method compatibility section to the user manual with an ASCII tree, Mermaid diagram, and compatibility table (PR #11).
46+
- Set up GitHub Actions workflow for automatic wiki synchronisation from `docs/user_manual.md`.
47+
- Update user manual to cover all new features.
48+
49+
---
2650

2751
## 20260228 (v0.2.0)
2852

29-
ArgMojo v0.2.0 is a major release that transforms the library from a single-command parser into a full **subcommand-capable CLI framework**. It introduces hierarchical subcommands with automatic dispatch, persistent (global) flags with bidirectional sync, negative number passthrough, colored error messages, custom tips, and significant help/UX improvements. The public API is also refined: `Arg` `Argument`, `Result` `ParseResult` (old names kept as aliases). Two complete example CLIs (`mgrep` and `mgit`) replace the previous demo.
53+
ArgMojo v0.2.0 is a major release that transforms the library from a single-command parser into a full subcommand-capable CLI framework. It introduces hierarchical subcommands with automatic dispatch, persistent (global) flags with bidirectional sync, negative number passthrough, colored error messages, custom tips, and significant help/UX improvements. The public API is also refined: `Arg` -> `Argument`, `Result` -> `ParseResult` (old names kept as aliases). Two complete example CLIs (`mgrep` and `mgit`) replace the previous demo.
3054

3155
ArgMojo v0.2.0 is compatible with Mojo v0.26.1.
3256

3357
### ⭐️ New in v0.2.0
3458

35-
**Subcommands:**
36-
3759
1. Implement full subcommand support with `add_subcommand()` API, hierarchical dispatch, and nested subcommands (e.g., `git remote add`).
38-
1. Auto-register a `help` subcommand so that `app help <command>` works out of the box; opt out with `disable_help_subcommand()`.
39-
1. Add `allow_positional_with_subcommands()` guard — prevents accidental mixing of positional args and subcommands on the same `Command`, following the cobra/clap convention. Requires explicit opt-in.
40-
1. Add `subcommand` and `subcommand_result` fields on `ParseResult` with `has_subcommand_result()` / `get_subcommand_result()` accessors.
41-
1. Add `command_aliases()` builder method for subcommand short names (e.g., `clone``cl`). Aliases dispatch to the canonical subcommand, appear in help output, shell completions, and typo suggestions.
42-
43-
**Persistent flags:**
44-
45-
1. Add `.persistent()` builder method on `Argument` to mark a flag as global.
46-
1. Persistent args are automatically injected into child commands and support bidirectional sync: flags set before the subcommand push down to the child, and flags set after the subcommand bubble up to the root.
47-
1. Detect conflicting long/short names between parent persistent args and child local args at registration time (`add_subcommand()` raises an error).
48-
49-
**Negative number passthrough:**
50-
51-
1. Recognize negative numeric tokens like `-3.14` or `-42` as positional values instead of unknown short options.
52-
1. Add `allow_negative_numbers()` opt-in on `Command` for explicit control.
53-
54-
**Custom tips:**
55-
56-
1. Add `add_tip()` API on `Command` to attach user-defined tips that render as a dedicated section at the bottom of help output.
57-
58-
**Error handling:**
59-
60-
1. Colored error and warning messages — ANSI-styled stderr output for all parse errors.
61-
1. Unknown subcommand error now lists all available commands.
62-
1. Errors inside child parse are prefixed with the full command path (e.g., `git remote add: ...`).
60+
2. Auto-register a `help` subcommand so that `app help <command>` works out of the box; opt out with `disable_help_subcommand()`.
61+
3. Add `allow_positional_with_subcommands()` guard -- prevents accidental mixing of positional args and subcommands on the same `Command`, following the cobra/clap convention. Requires explicit opt-in.
62+
4. Add `subcommand` and `subcommand_result` fields on `ParseResult` with `has_subcommand_result()` / `get_subcommand_result()` accessors.
63+
5. Add `command_aliases()` builder method for subcommand short names (e.g., `clone` -> `cl`). Aliases dispatch to the canonical subcommand, appear in help output, shell completions, and typo suggestions.
64+
6. Add `.persistent()` builder method on `Argument` to mark a flag as global.
65+
7. Persistent args are automatically injected into child commands and support bidirectional sync: flags set before the subcommand push down to the child, and flags set after the subcommand bubble up to the root.
66+
8. Detect conflicting long/short names between parent persistent args and child local args at registration time (`add_subcommand()` raises an error).
67+
9. Recognize negative numeric tokens like `-3.14` or `-42` as positional values instead of unknown short options. Add `allow_negative_numbers()` opt-in on `Command` for explicit control.
68+
10. Add `add_tip()` API on `Command` to attach user-defined tips that render as a dedicated section at the bottom of help output.
69+
11. Colored error and warning messages -- ANSI-styled stderr output for all parse errors.
70+
12. Unknown subcommand error now lists all available commands.
71+
13. Errors inside child parse are prefixed with the full command path (e.g., `git remote add: ...`).
6372

6473
### 🦋 Changed in v0.2.0
6574

66-
**API rename:**
67-
6875
1. Rename `Arg` struct to `Argument` and `Result` struct to `ParseResult`. The old names are kept as aliases for backward compatibility.
69-
1. Rename source files: `arg.mojo``argument.mojo`, `result.mojo``parse_result.mojo`.
70-
71-
**Help & UX improvements:**
72-
73-
1. Add a "Commands" section to help output listing available subcommands with aligned descriptions.
74-
1. Show `<COMMAND>` placeholder in the usage line for commands that have subcommands.
75-
1. Display persistent flags under a "Global Options" heading in child help.
76-
1. Show the full command path in child help and error messages (e.g., `Usage: git remote add [OPTIONS] NAME URL`).
77-
78-
**Internal refactoring:**
79-
80-
1. Extract `_apply_defaults()` and `_validate()` into private helper methods on `Command`, enabling clean reuse for both root and child parsing.
76+
2. Rename source files: `arg.mojo` -> `argument.mojo`, `result.mojo` -> `parse_result.mojo`.
77+
3. Add a "Commands" section to help output listing available subcommands with aligned descriptions.
78+
4. Show `<COMMAND>` placeholder in the usage line for commands that have subcommands.
79+
5. Display persistent flags under a "Global Options" heading in child help.
80+
6. Show the full command path in child help and error messages (e.g., `Usage: git remote add [OPTIONS] NAME URL`).
81+
7. Extract `_apply_defaults()` and `_validate()` into private helper methods on `Command`, enabling clean reuse for both root and child parsing.
8182

8283
### 📚 Documentation and testing in v0.2.0
8384

@@ -97,48 +98,31 @@ ArgMojo v0.1.0 is compatible with Mojo v0.26.1.
9798

9899
### ⭐️ New in v0.1.0
99100

100-
**Core parsing:**
101-
102101
1. Long options (`--verbose`, `--output file.txt`, `--output=file.txt`) and short options (`-v`, `-o file.txt`).
103-
1. Boolean flags that take no value.
104-
1. Positional arguments matched by position, with optional default values.
105-
1. Required argument validation.
106-
1. `--` stop marker — everything after `--` is treated as positional.
107-
1. Short flag merging — `-abc` expands to `-a -b -c`.
108-
1. Attached short values — `-ofile.txt` means `-o file.txt`.
109-
1. Count flags — `-vvv``get_count("verbose") == 3`.
110-
1. Positional argument count validation — reject extra positional args.
111-
112-
**Choices & validation:**
113-
114-
1. Choices validation — restrict values to a set (e.g., `json`, `csv`, `table`).
115-
1. Negatable flags — `--color` / `--no-color` paired flags with `.negatable()`.
116-
1. Long option prefix matching — `--verb` auto-resolves to `--verbose` when unambiguous.
117-
1. Conditional requirements — `--output` required only when `--save` is present.
118-
1. Numeric range validation — `.range[1, 65535]()` validates value is within bounds.
119-
120-
**Groups:**
121-
122-
1. Mutually exclusive groups — prevent conflicting flags (e.g., `--json` vs `--yaml`).
123-
1. Required-together groups — enforce that related flags are provided together (e.g., `--username` + `--password`).
124-
1. One-required groups — require at least one argument from a group.
125-
126-
**Collection:**
127-
128-
1. Append / collect action — `--tag x --tag y` collects repeated options into a list with `.append()`.
129-
1. Value delimiter — `--env dev,staging,prod` splits by delimiter into a list with `.delimiter(",")`.
130-
1. Multi-value options (nargs) — `--point 10 20` consumes N consecutive values with `.number_of_values[N]()` (breaking change from v0.1.0: replaces the old `.number_of_values(N)` runtime form, which no longer works).
131-
1. Key-value map option — `--define key=value` builds a `Dict` with `.key_value()`.
132-
133-
**Help & display:**
134-
135-
1. Auto-generated help with `--help` / `-h` / `-?`, dynamic column alignment, pixi-style ANSI colours, and customisable header/arg colours.
136-
1. Help on no args — optionally show help when invoked with no arguments.
137-
1. Version display with `--version` / `-V`.
138-
1. Metavar — custom display name for values in help text.
139-
1. Hidden arguments — exclude internal args from help output.
140-
141-
**Other:**
142-
143-
1. Aliases for long names — `.aliases(["color"])` for `--colour` / `--color`.
144-
1. Deprecated arguments — `.deprecated("Use --format instead")` prints warning to stderr.
102+
2. Boolean flags that take no value.
103+
3. Positional arguments matched by position, with optional default values.
104+
4. Required argument validation.
105+
5. `--` stop marker -- everything after `--` is treated as positional.
106+
6. Short flag merging -- `-abc` expands to `-a -b -c`.
107+
7. Attached short values -- `-ofile.txt` means `-o file.txt`.
108+
8. Count flags -- `-vvv` -> `get_count("verbose") == 3`.
109+
9. Positional argument count validation -- reject extra positional args.
110+
10. Choices validation -- restrict values to a set (e.g., `json`, `csv`, `table`).
111+
11. Negatable flags -- `--color` / `--no-color` paired flags with `.negatable()`.
112+
12. Long option prefix matching -- `--verb` auto-resolves to `--verbose` when unambiguous.
113+
13. Conditional requirements -- `--output` required only when `--save` is present.
114+
14. Numeric range validation -- `.range[1, 65535]()` validates value is within bounds.
115+
15. Mutually exclusive groups -- prevent conflicting flags (e.g., `--json` vs `--yaml`).
116+
16. Required-together groups -- enforce that related flags are provided together (e.g., `--username` + `--password`).
117+
17. One-required groups -- require at least one argument from a group.
118+
18. Append / collect action -- `--tag x --tag y` collects repeated options into a list with `.append()`.
119+
19. Value delimiter -- `--env dev,staging,prod` splits by delimiter into a list with `.delimiter(",")`.
120+
20. Multi-value options (nargs) -- `--point 10 20` consumes N consecutive values with `.number_of_values[N]()`.
121+
21. Key-value map option -- `--define key=value` builds a `Dict` with `.map_option()`.
122+
22. Auto-generated help with `--help` / `-h` / `-?`, dynamic column alignment, pixi-style ANSI colours, and customisable header/arg colours.
123+
23. Help on no args -- optionally show help when invoked with no arguments.
124+
24. Version display with `--version` / `-V`.
125+
25. Metavar -- custom display name for values in help text.
126+
26. Hidden arguments -- exclude internal args from help output.
127+
27. Aliases for long names -- `.aliases(["color"])` for `--colour` / `--color`.
128+
28. Deprecated arguments -- `.deprecated("Use --format instead")` prints warning to stderr.

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "Apache-2.0"
1010
name = "argmojo"
1111
platforms = ["osx-arm64", "linux-64"]
1212
readme = "README.md"
13-
version = "0.2.0"
13+
version = "0.3.0"
1414

1515
[dependencies]
1616
mojo = "==0.26.1"

0 commit comments

Comments
 (0)