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
[x]**Positional arg count validation**: reject extra positional args
33
-
[x]**Negatable flags**: `--color` / `--no-color` paired flags with `.negatable()`
34
-
[x]**Mutually exclusive groups**: prevent conflicting flags (e.g., `--json` vs `--yaml`)
35
-
[x]**Required-together groups**: enforce that related flags are provided together (e.g., `--username` + `--password`)
36
-
[x]**Long option prefix matching**: allow abbreviated options (e.g., `--verb` → `--verbose`). If the prefix is ambiguous (e.g., `--ver` could match both `--verbose` and `--version`), an error is raised.
15
+
ArgMojo provides a builder-pattern API for defining and parsing command-line arguments in Mojo. It currently supports:
-**Positional arg count validation**: reject extra positional args
33
+
-**Negatable flags**: `--color` / `--no-color` paired flags with `.negatable()`
34
+
-**Mutually exclusive groups**: prevent conflicting flags (e.g., `--json` vs `--yaml`)
35
+
-**Required-together groups**: enforce that related flags are provided together (e.g., `--username` + `--password`)
36
+
-**Long option prefix matching**: allow abbreviated options (e.g., `--verb` → `--verbose`). If the prefix is ambiguous (e.g., `--ver` could match both `--verbose` and `--version`), an error is raised.
37
37
38
38
---
39
39
40
40
I created this project to support my experiments with a CLI-based Chinese character search engine in Mojo, as well as a CLI-based calculator for [DeciMojo](https://github.com/forfudan/decimojo). It is inspired by Python's `argparse`, Rust's `clap`, Go's `cobra`, and other popular argument parsing libraries, but designed to fit Mojo's unique features and constraints.
41
41
42
+
My goal is to provide a Mojo-idiomatic argument parsing library that can be easily adopted by the growing Mojo community for their CLI applications. **Before Mojo v1.0** (which means it gets stable), my focus is on building core features and ensuring correctness. "Core features" refer to those who appear in `argparse`/`clap`/`cobra` and are commonly used in CLI apps. "Correctness" means that the library should handle edge cases properly, provide clear error messages, and have good test coverage. Some fancy features will depend on my time and interest.
43
+
42
44
## Installation
43
45
44
-
ArgMojo requires Mojo >= 0.26.1 and uses [pixi](https://pixi.sh) for environment management.
46
+
ArgMojo requires Mojo == 0.26.1 and uses [pixi](https://pixi.sh) for environment management.
45
47
46
48
```bash
47
49
git clone https://github.com/forfudan/argmojo.git
48
50
cd argmojo
49
51
pixi install
50
52
```
51
53
54
+
I make the Mojo version strictly 0.26.1 because that's the version I developed and tested on, and Mojo is rapidly evolving. Based on my experience, the library will not work every time there's a new Mojo release.
55
+
52
56
## Quick Start
53
57
54
58
Here is a simple example of how to use ArgMojo in a Mojo program. The full example can be found in `examples/demo.mojo`.
@@ -58,7 +62,7 @@ from argmojo import Arg, Command
58
62
59
63
60
64
fn main() raises:
61
-
var cmd = Command("sou", "A CJK-aware text search tool", version="0.1.0")
65
+
var cmd = Command("demo", "A CJK-aware text search tool that supports Pinyin and Yuhao Input Methods (宇浩系列輸入法).", version="0.1.0")
0 commit comments