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
[cli] Enable negative expressions as positional arguments (#202)
This PR updates the Decimo CLI argument parsing so expressions that
start with `-` (e.g., negative numbers / negative expressions) can be
passed as the positional `<EXPR>` more naturally, and documents/tests
the behavior.
**Changes:**
- Enable hyphen-prefixed values for the `expr` positional argument via
ArgMojo (`allow_hyphen=True`) and remove the older command-level
negative-number allowance.
- Expand CLI integration tests to cover negative expressions, mixed
option/positional ordering, and `--` separator cases.
- Add user-manual documentation for “Negative Expressions” and update
the CLI calculator plan checklist accordingly.
| 3.5 | Shell completion (`--completions bash\|zsh\|fish`) | ✓ | Built-in — zero code; needs documentation in user manual and README |
321
-
| 3.6 |`allow_negative_numbers()` to allow pure negative numbers | ✓ | Explicit opt-in in hybrid bridge; `decimo "-3"` works, expressions need quoting or `--`|
322
-
| 3.7 | Numeric range on `precision`| ✓ |`has_range=True, range_min=1, range_max=1000000000`; rejects `--precision 0` or `-5`|
323
-
| 3.8 | Value names for help readability | ✓ |`--precision <N>`, `--delimiter <CHAR>`, `--rounding-mode <MODE>`|
324
-
| 3.9 | Argument groups in help output | ✓ |`Computation` and `Formatting` groups in `--help`|
325
-
| 3.10 | Custom usage line | ✓ |`Usage: decimo [OPTIONS] <EXPR>`|
326
-
| 3.11 |`Parsable.run()` override | ✗ | Move eval logic into `DecimoArgs.run()` for cleaner separation |
| 3.13 | Documentation (user manual for CLI) | ✗ |`docs/user_manual_cli.md`; include shell completion setup |
329
-
| 3.14 | Build and distribute as single binary | ✗ ||
330
-
| 3.15 | Allow negative expressions | ✗ | This needs ArgMojo to regard arguments with a hyphen and followed by more than one letter as a positional argument |
| 3.5 | Shell completion (`--completions bash\|zsh\|fish`) | ✓ | Built-in — zero code; needs documentation in user manual and README |
321
+
| 3.6 |`allow_negative_numbers()` to allow pure negative numbers | ✓ | Superseded by 3.15 `allow_hyphen=True`; removed in favour of the more general approach |
322
+
| 3.7 | Numeric range on `precision`| ✓ |`has_range=True, range_min=1, range_max=1000000000`; rejects `--precision 0` or `-5`|
323
+
| 3.8 | Value names for help readability | ✓ |`--precision <N>`, `--delimiter <CHAR>`, `--rounding-mode <MODE>`|
324
+
| 3.9 | Argument groups in help output | ✓ |`Computation` and `Formatting` groups in `--help`|
325
+
| 3.10 | Custom usage line | ✓ |`Usage: decimo [OPTIONS] <EXPR>`|
326
+
| 3.11 |`Parsable.run()` override | ✗ | Move eval logic into `DecimoArgs.run()` for cleaner separation |
Negative numbers and many expressions starting with `-` can be passed directly as the positional argument. However, if the expression token looks like a CLI flag (e.g., `-e`), use `--` to force positional parsing. See [Negative Expressions](#negative-expressions) for details.
95
+
92
96
### Operators
93
97
94
98
| Operator | Description | Example | Result |
@@ -255,6 +259,38 @@ decimo "2 * (3 + 4)"
255
259
decimo 2 * (3 + 4)
256
260
```
257
261
262
+
### Negative Expressions
263
+
264
+
Most expressions starting with a hyphen (`-`) are treated as positional arguments, not as option flags:
265
+
266
+
```bash
267
+
# Negative number
268
+
decimo "-3.14"
269
+
# → -3.14
270
+
271
+
# Negative expression
272
+
decimo "-3*2"
273
+
# → -6
274
+
275
+
# Complex negative expression
276
+
decimo "-3*pi*(sin(1))"
277
+
# → -7.930677192244368536658197969…
278
+
279
+
# Options can appear before or after the expression
280
+
decimo -p 10 "-3*pi"
281
+
decimo "-3*pi" -p 10
282
+
```
283
+
284
+
**Caveat:** If the expression looks like an existing CLI flag (e.g., `-e` matches `--engineering`), ArgMojo will consume it as an option. Use `--` to force positional parsing in those cases:
285
+
286
+
```bash
287
+
# -e is the engineering flag, so use -- to treat it as an expression
288
+
decimo -- "-e"
289
+
# → -2.71828…
290
+
```
291
+
292
+
> **Note:** A future release will rename short flags to uppercase (`-S`, `-E`) to eliminate these collisions entirely.
293
+
258
294
### Using noglob
259
295
260
296
On zsh, you can use `noglob` to prevent shell interpretation:
0 commit comments