22
33![ icon] ( image.jpeg )
44
5- A command-line argument parser library for [ Mojo] ( https://www.modular.com/mojo ) .
5+ A command-line argument parser library for [ Mojo] ( https://www.modular.com/mojo ) , inspired by Python's ` argparse ` , Rust's ` clap ` , Go's ` cobra ` , and other popular libraries .
66
7- > ** A** rguments
8- > ** R** esolved and
9- > ** G** rouped into
10- > ** M** eaningful
11- > ** O** ptions and
12- > ** J** oined
13- > ** O** bjects
7+ <!--
8+ > **A**rguments **R**esolved and **G**rouped into **M**eaningful **O**ptions and **J**oined **O**bjects
9+ -->
10+
11+ [ ![ Version] ( https://img.shields.io/github/v/tag/forfudan/argmojo?label=version&color=blue )] ( https://github.com/forfudan/argmojo/releases )
12+ [ ![ Mojo] ( https://img.shields.io/badge/mojo-0.26.1-orange )] ( https://docs.modular.com/mojo/manual/ )
13+ [ ![ pixi] ( https://img.shields.io/badge/pixi%20add-argmojo-brightgreen )] ( https://prefix.dev/channels/modular-community/packages/argmojo )
14+ [ ![ User manual] ( https://img.shields.io/badge/user-manual-purple )] ( https://github.com/forfudan/argmojo/wiki )
15+
16+ ![ Shell tab-completion powered by ArgMojo] ( https://raw.githubusercontent.com/forfudan/forfudan-github-data/main/argmojo/completions.gif )
17+ * Demo: Shell tab-completion powered by ArgMojo*
18+
19+ <!--
20+ [](https://github.com/forfudan/argmojo/actions/workflows/run_tests.yaml)
21+ [](LICENSE)
22+ [](https://github.com/forfudan/argmojo/stargazers)
23+ [](https://github.com/forfudan/argmojo/issues)
24+ [](https://github.com/forfudan/argmojo/commits/main)
25+ 
26+ -->
1427
1528## Overview
1629
@@ -41,6 +54,7 @@ ArgMojo provides a builder-pattern API for defining and parsing command-line arg
4154- ** One-required groups** : require at least one argument from a group (e.g., must provide ` --json ` or ` --yaml ` )
4255- ** Value delimiter** : ` --env dev,staging,prod ` splits by delimiter into a list with ` .delimiter(",") `
4356- ** Multi-value options (nargs)** : ` --point 10 20 ` consumes N consecutive values with ` .nargs(N) `
57+ - ** Shell completion script generation** : ` generate_completion("bash"|"zsh"|"fish") ` produces a complete tab-completion script for your CLI
4458
4559---
4660
@@ -63,7 +77,7 @@ Then, you can install ArgMojo using any of these methods:
63771 . In the ` mojoproject.toml ` file of your project, add the following dependency:
6478
6579 ``` toml
66- argmojo = " ==0.2 .0"
80+ argmojo = " ==0.3 .0"
6781 ```
6882
6983 Then run `pixi install` to download and install the package.
@@ -73,18 +87,18 @@ The following table summarizes the package versions and their corresponding Mojo
7387| `argmojo` version | `mojo` version | package manager |
7488| ----------------- | -------------- | --------------- |
7589| 0.1.0 | ==0.26.1 | pixi |
76- | 0.2 .0 | ==0.26.1 | pixi |
90+ | 0.3 .0 | ==0.26.1 | pixi |
7791
7892# # Quick Start
7993
80- Here is a simple example of how to use ArgMojo in a Mojo program. See `examples/grep .mojo` for the full version.
94+ Here is a simple example of how to use ArgMojo in a Mojo program. See `examples/mgrep .mojo` for the full version.
8195
8296```mojo
8397from argmojo import Argument, Command
8498
8599
86100fn main() raises:
87- var app = Command("grep ", "Search for PATTERN in each FILE.", version =" 1.0.0" )
101+ var app = Command("mgrep ", "Search for PATTERN in each FILE.", version =" 1.0.0" )
88102
89103 # Positional arguments
90104 app.add_argument(Argument("pattern", help =" Search pattern" ).positional().required())
@@ -129,66 +143,75 @@ fn main() raises:
129143
130144## Usage Examples
131145
132- For detailed explanations and more examples of every feature, see the User Manual.
146+ For detailed explanations and more examples of every feature, see the ** [ User Manual] ( https://github.com/forfudan/argmojo/wiki ) ** .
133147
134148ArgMojo ships with two complete example CLIs:
135149
136- | Example | File | Features |
137- | ----------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
138- | ` grep ` — simulated grep | ` examples/grep .mojo ` | Positional args, flags, count flags, negatable flags, choices, metavar, append/collect, value delimiter, nargs, mutually exclusive groups, required-together groups, conditional requirements, numeric range, key-value map, aliases, deprecated args, hidden args, negative-number passthrough, ` -- ` stop marker, custom tips |
139- | ` git ` — simulated git | ` examples/git .mojo ` | Subcommands (clone/init/add/commit/push/pull/log/remote/branch/diff/tag/stash), nested subcommands (remote add/remove/rename/show), persistent (global) flags, per-command args, mutually exclusive groups, choices, aliases, deprecated args, custom tips |
150+ | Example | File | Features |
151+ | ------------------------ | - -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
152+ | ` mgrep ` — simulated grep | ` examples/mgrep .mojo ` | Positional args, flags, count flags, negatable flags, choices, metavar, append/collect, value delimiter, nargs, mutually exclusive groups, required-together groups, conditional requirements, numeric range, key-value map, aliases, deprecated args, hidden args, negative-number passthrough, ` -- ` stop marker, custom tips |
153+ | ` mgit ` — simulated git | ` examples/mgit .mojo ` | Subcommands (clone/init/add/commit/push/pull/log/remote/branch/diff/tag/stash), nested subcommands (remote add/remove/rename/show), persistent (global) flags, per-command args, mutually exclusive groups, choices, aliases, deprecated args, custom tips, shell completion script generation |
140154
141155Build both example binaries:
142156
143157``` bash
144158pixi run build
145159```
146160
147- ### ` grep ` (no subcommands)
161+ ### ` mgrep ` (no subcommands)
162+
163+ ![ mgrep CLI demo] ( https://raw.githubusercontent.com/forfudan/forfudan-github-data/main/argmojo/mgrep.png )
148164
149165``` bash
150166# Help and version
151- ./grep --help
152- ./grep --version
167+ ./mgrep --help
168+ ./mgrep --version
153169
154170# Basic search
155- ./grep " fn main" ./src
171+ ./mgrep " fn main" ./src
156172
157173# Combined short flags + options
158- ./grep -rnic " TODO" ./src --max-depth 5
174+ ./mgrep -rnic " TODO" ./src --max-depth 5
159175
160176# Choices, append, negatable
161- ./grep " pattern" --format json --tag fixme --tag urgent --color
177+ ./mgrep " pattern" --format json --tag fixme --tag urgent --color
162178
163179# -- stops option parsing
164- ./grep -- " -pattern-with-dashes" ./src
180+ ./mgrep -- " -pattern-with-dashes" ./src
165181
166182# Prefix matching (--exc matches --exclude-dir)
167- ./grep " fn" --exc .git,node_modules
183+ ./mgrep " fn" --exc .git,node_modules
168184```
169185
170- ### ` git ` (with subcommands)
186+ ### ` mgit ` (with subcommands)
187+
188+ ![ mgit clone subcommand] ( https://raw.githubusercontent.com/forfudan/forfudan-github-data/main/argmojo/mgit-clone.png )
171189
172190``` bash
173191# Root help — shows Commands section + Global Options
174- ./git --help
192+ ./mgit --help
175193
176194# Child help — shows full command path
177- ./git clone --help
195+ ./mgit clone --help
178196
179197# Subcommand dispatch
180- ./git clone https://example.com/repo.git my-project --depth 1
181- ./git commit -am " initial commit"
182- ./git log --oneline -n 20 --author " Alice"
183- ./git -v push origin main --force --tags
198+ ./mgit clone https://example.com/repo.git my-project --depth 1
199+ ./mgit commit -am " initial commit"
200+ ./mgit log --oneline -n 20 --author " Alice"
201+ ./mgit -v push origin main --force --tags
184202
185203# Nested subcommands (remote → add/remove/rename/show)
186- ./git remote add origin https://example.com/repo.git
187- ./git remote show origin
204+ ./mgit remote add origin https://example.com/repo.git
205+ ./mgit remote show origin
188206
189207# Unknown subcommand → clear error
190- ./git foo
191- # error: git: Unknown command 'foo'. Available commands: clone, init, ...
208+ ./mgit foo
209+ # error: mgit: Unknown command 'foo'. Available commands: clone, init, ...
210+
211+ # Shell completion script generation
212+ ./mgit --completions bash # bash completion script
213+ ./mgit --completions zsh # zsh completion script
214+ ./mgit --completions fish # fish completion script
192215```
193216
194217## Development
@@ -214,14 +237,15 @@ argmojo/
214237├── docs/ # Documentation
215238│ └── user_manual.md # User manual with detailed examples
216239├── examples/
217- │ ├── grep .mojo # grep-like CLI (no subcommands)
218- │ └── git .mojo # git-like CLI (with subcommands)
240+ │ ├── mgrep .mojo # grep-like CLI (no subcommands)
241+ │ └── mgit .mojo # git-like CLI (with subcommands)
219242├── src/
220243│ └── argmojo/ # Main package
221244│ ├── __init__.mojo # Package exports
222245│ ├── argument.mojo # Argument struct (argument definition)
223246│ ├── command.mojo # Command struct (parsing logic)
224- │ └── parse_result.mojo # ParseResult struct (parsed values)
247+ │ ├── parse_result.mojo # ParseResult struct (parsed values)
248+ │ └── utils.mojo # ANSI colour constants and utility functions
225249├── tests/ # Test suites (241 tests)
226250│ ├── test_parse.mojo
227251│ ├── test_groups.mojo
0 commit comments