Skip to content

Commit 2c484de

Browse files
authored
[cli] Make all short names upper cases + Enable pipe mode and file mode (#203)
This PR updates the Decimo CLI to avoid short-flag collisions with negative expressions by uppercasing short options, and adds new stdin (pipe) + file-based input modes for evaluating multiple expressions. **Changes:** - Uppercase short flags for formatting/computation options (`-P/-S/-E/-D/-R`) and remove the `--pad` short flag to prevent collisions with expressions like `-e`, `-pi`, `-sin(1)`. - Add pipe mode (read/evaluate expressions from stdin, one per non-empty non-comment line) and file mode (`-F/--file`). - Extend integration/unit tests and update docs/changelog/plans for the new CLI UX.
1 parent 7f51854 commit 2c484de

File tree

8 files changed

+1069
-132
lines changed

8 files changed

+1069
-132
lines changed

docs/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
This is a list of changes for the Decimo package (formerly DeciMojo).
44

5+
## Unreleased - under development
6+
7+
### ⭐️ New in v0.10.0
8+
9+
**CLI Calculator:**
10+
11+
1. Add **pipe/stdin mode**: read expressions from standard input, one per line, when no positional argument is given and stdin is piped (e.g. `echo "1+2" | decimo`, `printf "pi\nsqrt(2)" | decimo -P 100`). Blank lines and comment lines (starting with `#`) are automatically skipped.
12+
1. Add **file mode**: use `--file` / `-F` flag to evaluate expressions from a file, one per line (e.g. `decimo -F expressions.dm -P 50`). Comments (`#`), inline comments, and blank lines are skipped. All CLI flags (precision, formatting, rounding) apply to every expression.
13+
14+
### 🦋 Changed in v0.10.0
15+
516
## 20260323 (v0.9.0)
617

718
Decimo v0.9.0 updates the codebase to **Mojo v0.26.2** and marks the **"make it useful"** phase. This release introduces three major additions:

docs/plans/cli_calculator.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ cat expressions.txt | decimo
9595
decimo < expressions.txt
9696

9797
# Evaluate a script file (.dm)
98-
decimo file.dm
98+
decimo -F file.dm
9999
```
100100

101101
Example `expressions.dm`:
@@ -266,17 +266,17 @@ Format the final `BigDecimal` result based on CLI flags:
266266
6. Handle unary minus.
267267
7. Test with basic expressions.
268268

269-
| # | Task | Status | Notes |
270-
| --- | ------------------------------------------------ | :----: | ----------------------------- |
271-
| 1.1 | Project structure (src/cli/, calculator module) || |
272-
| 1.2 | Tokenizer (numbers, `+ - * /`, parens) || |
273-
| 1.3 | Shunting-yard parser (infix → RPN) || |
274-
| 1.4 | RPN evaluator using `BigDecimal` || |
275-
| 1.5 | ArgMojo wiring (`expr`, `--precision`, `--help`) || |
276-
| 1.6 | Unary minus || |
277-
| 1.7 | Basic expression tests || 4 test files, 118 tests total |
278-
| 1.8 | Pipeline / stdin input (`echo "1+2" \| decimo`) | | Not yet implemented |
279-
| 1.9 | File input (`decimo file.dm`) | | Not yet implemented |
269+
| # | Task | Status | Notes |
270+
| --- | ------------------------------------------------ | :----: | -------------------------------------------------------------------------------------------- |
271+
| 1.1 | Project structure (src/cli/, calculator module) || |
272+
| 1.2 | Tokenizer (numbers, `+ - * /`, parens) || |
273+
| 1.3 | Shunting-yard parser (infix → RPN) || |
274+
| 1.4 | RPN evaluator using `BigDecimal` || |
275+
| 1.5 | ArgMojo wiring (`expr`, `--precision`, `--help`) || |
276+
| 1.6 | Unary minus || |
277+
| 1.7 | Basic expression tests || 4 test files |
278+
| 1.8 | Pipeline / stdin input (`echo "1+2" \| decimo`) | | Pipe mode: reads stdin when no positional arg and stdin is not a TTY |
279+
| 1.9 | File input (`decimo -F file.dm`) | | File mode via `-F/--file` flag: reads files line by line, skips comments (#) and blank lines |
280280

281281
### Phase 2: Power and Functions
282282

@@ -328,7 +328,7 @@ Format the final `BigDecimal` result based on CLI flags:
328328
| 3.13 | Documentation (user manual for CLI) || `docs/user_manual_cli.md`; include shell completion setup |
329329
| 3.14 | Build and distribute as single binary || |
330330
| 3.15 | Allow negative expressions || `allow_hyphen=True` on `Positional`; `decimo "-3*pi*(sin(1))"` works |
331-
| 3.16 | Make short names upper cases to avoid expression collisions | | `-sin(1)` clashes with `-s` (scientific), `-e` clashes with `--engineering` |
331+
| 3.16 | Make short names upper cases to avoid expression collisions | | `-P`, `-S`, `-E`, `-D`, `-R`; `--pad` has no short name; `-e`, `-pi`, `-sin(1)` all work |
332332
| 3.17 | Define `allow_hyphen_values` in declarative API || When argmojo supports it |
333333

334334
### Phase 4: Interactive REPL & Subcommands
@@ -408,7 +408,7 @@ This is the natural choice for a calculator: users expect `7 / 2` to be `3.5`, n
408408
| ------------------------------------- | ------------------------------------- |
409409
| `decimo "expr"` | One-shot: evaluate and exit |
410410
| `echo "expr" \| decimo` | Pipe: read stdin line by line |
411-
| `decimo file.dm` | File: read and evaluate each line |
411+
| `decimo -F file.dm` | File: read and evaluate each line |
412412
| `decimo` (no args, terminal is a TTY) | REPL: interactive session |
413413
| `decimo -i` | REPL: force interactive even if piped |
414414

0 commit comments

Comments
 (0)