ArgMojo v0.2.0
20260228 (v0.2.0)
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 (old name kept as alias). Two complete example CLIs (grep and git) replace the previous demo.
ArgMojo v0.2.0 is compatible with Mojo v0.26.1.
⭐️ New in v0.2.0
Subcommands:
- Implement full subcommand support with
add_subcommand()API, hierarchical dispatch, and nested subcommands (e.g.,git remote add). - Auto-register a
helpsubcommand so thatapp help <command>works out of the box; opt out withdisable_help_subcommand(). - Add
allow_positional_with_subcommands()guard — prevents accidental mixing of positional args and subcommands on the sameCommand, following the cobra/clap convention. Requires explicit opt-in. - Add
subcommandandsubcommand_resultfields onParseResultwithhas_subcommand_result()/get_subcommand_result()accessors.
Persistent flags:
- Add
.persistent()builder method onArgumentto mark a flag as global. - 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.
- Detect conflicting long/short names between parent persistent args and child local args at registration time (
add_subcommand()raises an error).
Negative number passthrough:
- Recognize negative numeric tokens like
-3.14or-42as positional values instead of unknown short options. - Add
allow_negative_numbers()opt-in onCommandfor explicit control.
Custom tips:
- Add
add_tip()API onCommandto attach user-defined tips that render as a dedicated section at the bottom of help output.
Error handling:
- Colored error and warning messages — ANSI-styled stderr output for all parse errors.
- Unknown subcommand error now lists all available commands.
- Errors inside child parse are prefixed with the full command path (e.g.,
git remote add: ...).
🦋 Changed in v0.2.0
API rename:
- Rename
Argstruct toArgument. The old name is kept as alias for convenience. - Rename source files:
arg.mojo→argument.mojo,result.mojo→parse_result.mojo.
Help & UX improvements:
- Add a "Commands" section to help output listing available subcommands with aligned descriptions.
- Show
<COMMAND>placeholder in the usage line for commands that have subcommands. - Display persistent flags under a "Global Options" heading in child help.
- Show the full command path in child help and error messages (e.g.,
Usage: git remote add [OPTIONS] NAME URL).
Internal refactoring:
- Extract
_apply_defaults()and_validate()into private helper methods onCommand, enabling clean reuse for both root and child parsing.
📚 Documentation and testing in v0.2.0
- Add two complete example CLIs:
examples/grep.mojo(single-command, demonstrating all argument features) andexamples/git.mojo(subcommand-based, with nested subcommands and persistent flags). - Add
tests/test_subcommands.mojocovering data model, dispatch, help subcommand, persistent flags, allow-positional guard, and error handling. - Add
tests/test_negative_numbers.mojo. - Add
tests/test_persistent.mojo. - Update user manual (
docs/user_manual.md) to cover all new features.