Ability to pipe stdin to the non-interactive cli mode #30

Open
opened 2025-10-20 12:33:51 +01:00 by Vylpes · 3 comments
Owner

Milestone: 0.3.0
Story Points: 5


AS a user scripting calculator evaluations
I WANT to pipe expressions into the CLI non-interactive mode
SO THAT I can batch-evaluate expressions from a file or shell pipeline without entering interactive mode

Acceptance Criteria

GIVEN I run calculator cli with no expression argument
WHEN stdin is not a TTY (e.g. echo "2 + 3" | calculator cli or calculator cli < expressions.txt)
THEN the CLI reads from stdin until EOF instead of showing the interactive prompt/banner

GIVEN stdin is piped or redirected into calculator cli
WHEN each non-empty line contains a valid expression
THEN the numeric result is printed to stdout (result only — no = prefix, matching calculator cli "expr" output)
AND each result is on its own line

GIVEN stdin contains multiple non-empty lines
WHEN I pipe them into calculator cli
THEN each line is evaluated independently in order
AND I receive one result line per valid expression

GIVEN a piped/redirected line is empty or whitespace-only
WHEN the CLI processes stdin
THEN the line is skipped (no output, no error)

GIVEN a piped/redirected line contains an invalid expression
WHEN the CLI evaluates that line
THEN a clear error message is printed to stderr
AND processing continues for subsequent lines
AND the process exits with a non-zero exit code after all input is consumed if any line failed

GIVEN I run calculator cli "2 + 3" with an expression argument
WHEN stdin may or may not be piped
THEN behaviour is unchanged from today (single-expression mode; argument takes precedence)

GIVEN I run calculator cli with stdin attached to a TTY (interactive terminal)
WHEN no expression argument is provided
THEN the existing interactive REPL mode is unchanged (banner, > prompt, quit/exit)

Subtasks

  • Detect non-TTY stdin when no expression argument is provided
  • Read and evaluate stdin line-by-line until EOF
  • Match single-expression stdout format for piped results
  • Handle per-line errors (stderr + non-zero exit if any failure)
  • Add unit/integration tests for piped stdin scenarios
  • Verify interactive TTY mode and calculator cli "expr" are unaffected (regression)

Notes

  • Current CLI modes (src/cli.rs on develop / release/0.1.0):
    • calculator cli "expr" — single expression, prints result
    • calculator cli — interactive REPL with prompts
  • This story adds a piped stdin batch mode as a third path when no expression arg and stdin is not a TTY
  • Related: #31 (save interactive session to file) is separate; this story does not write session logs
  • GUI mode is out of scope
  • Expression syntax and evaluation rules follow whatever the engine supports at implementation time (including multi-operation left-to-right from #22 when merged)
Milestone: 0.3.0 Story Points: 5 --- AS a user scripting calculator evaluations I WANT to pipe expressions into the CLI non-interactive mode SO THAT I can batch-evaluate expressions from a file or shell pipeline without entering interactive mode ## Acceptance Criteria GIVEN I run `calculator cli` with no expression argument WHEN stdin is **not** a TTY (e.g. `echo "2 + 3" | calculator cli` or `calculator cli < expressions.txt`) THEN the CLI reads from stdin until EOF instead of showing the interactive prompt/banner GIVEN stdin is piped or redirected into `calculator cli` WHEN each non-empty line contains a valid expression THEN the numeric result is printed to stdout (result only — no `=` prefix, matching `calculator cli "expr"` output) AND each result is on its own line GIVEN stdin contains multiple non-empty lines WHEN I pipe them into `calculator cli` THEN each line is evaluated independently in order AND I receive one result line per valid expression GIVEN a piped/redirected line is empty or whitespace-only WHEN the CLI processes stdin THEN the line is skipped (no output, no error) GIVEN a piped/redirected line contains an invalid expression WHEN the CLI evaluates that line THEN a clear error message is printed to stderr AND processing continues for subsequent lines AND the process exits with a non-zero exit code after all input is consumed if any line failed GIVEN I run `calculator cli "2 + 3"` with an expression argument WHEN stdin may or may not be piped THEN behaviour is unchanged from today (single-expression mode; argument takes precedence) GIVEN I run `calculator cli` with stdin attached to a TTY (interactive terminal) WHEN no expression argument is provided THEN the existing interactive REPL mode is unchanged (banner, `>` prompt, `quit`/`exit`) ## Subtasks - [ ] Detect non-TTY stdin when no expression argument is provided - [ ] Read and evaluate stdin line-by-line until EOF - [ ] Match single-expression stdout format for piped results - [ ] Handle per-line errors (stderr + non-zero exit if any failure) - [ ] Add unit/integration tests for piped stdin scenarios - [ ] Verify interactive TTY mode and `calculator cli "expr"` are unaffected (regression) ## Notes - Current CLI modes (`src/cli.rs` on `develop` / `release/0.1.0`): - `calculator cli "expr"` — single expression, prints result - `calculator cli` — interactive REPL with prompts - This story adds a **piped stdin batch mode** as a third path when no expression arg and stdin is not a TTY - Related: #31 (save interactive session to file) is separate; this story does not write session logs - GUI mode is out of scope - Expression syntax and evaluation rules follow whatever the engine supports at implementation time (including multi-operation left-to-right from #22 when merged)
Vylpes added this to the 0.3.0 milestone 2025-10-20 12:34:28 +01:00
Member

Fleshed out acceptance criteria for piping stdin into the CLI non-interactive mode.

Key points:

  • CLI only — no GUI changes
  • When calculator cli is run without an expression argument and stdin is not a TTY (piped or redirected), read expressions from stdin until EOF instead of entering interactive mode
  • One expression per line; output matches existing single-expression mode (numeric result only, one line per expression)
  • Interactive TTY mode (calculator cli with a terminal) and single-expression mode (calculator cli "2 + 3") remain unchanged
  • Errors go to stderr; process exits non-zero if any line fails (remaining lines still processed)

Criteria are specific enough to estimate. Moving to needs/estimate.

Fleshed out acceptance criteria for piping stdin into the CLI non-interactive mode. Key points: - **CLI only** — no GUI changes - When `calculator cli` is run **without** an expression argument and **stdin is not a TTY** (piped or redirected), read expressions from stdin until EOF instead of entering interactive mode - **One expression per line**; output matches existing single-expression mode (numeric result only, one line per expression) - **Interactive TTY mode** (`calculator cli` with a terminal) and **single-expression mode** (`calculator cli "2 + 3"`) remain unchanged - Errors go to stderr; process exits non-zero if any line fails (remaining lines still processed) Criteria are specific enough to estimate. Moving to `needs/estimate`.
Member

Story point estimate: 5

CLI stdin batch mode. Criteria are specific enough to size.

Work Points Rationale
Non-TTY stdin detection + read-until-EOF path in cli.rs 2 New third CLI path alongside single-expression and interactive REPL; is_terminal() branching
Line-by-line evaluation loop (result-only stdout, one line per expression) 1 Reuses existing eval path per line; skip empty/whitespace lines
Per-line error handling (stderr, continue, non-zero exit if any failure) 1 Error aggregation across lines without aborting early
Unit/integration tests (pipe, redirect, TTY regression, empty lines, invalid lines) 1 Well-defined scenarios in acceptance criteria
Total 5

Reference: focused CLI change in a single module (src/cli.rs); no GUI work. Interactive TTY mode and calculator cli "expr" are regression-only.

Moving to needs/tests.

## Story point estimate: **5** CLI stdin batch mode. Criteria are specific enough to size. | Work | Points | Rationale | |------|--------|-----------| | Non-TTY stdin detection + read-until-EOF path in `cli.rs` | 2 | New third CLI path alongside single-expression and interactive REPL; `is_terminal()` branching | | Line-by-line evaluation loop (result-only stdout, one line per expression) | 1 | Reuses existing eval path per line; skip empty/whitespace lines | | Per-line error handling (stderr, continue, non-zero exit if any failure) | 1 | Error aggregation across lines without aborting early | | Unit/integration tests (pipe, redirect, TTY regression, empty lines, invalid lines) | 1 | Well-defined scenarios in acceptance criteria | | **Total** | **5** | | Reference: focused CLI change in a single module (`src/cli.rs`); no GUI work. Interactive TTY mode and `calculator cli "expr"` are regression-only. Moving to `needs/tests`.
Member

QA Testing Scripts

Story: Ability to pipe stdin to the non-interactive CLI mode
Estimate: 5 story points

TC-01 — Single expression via pipe (non-TTY stdin)

  • Given the calculator CLI is built and on $PATH
  • When I run echo "2 + 3" | calculator cli
  • Then 5 is printed to stdout (result only — no = prefix)
  • And the process exits with code 0

TC-02 — Single expression via stdin redirect (non-TTY stdin)

  • Given a file expressions.txt containing 10 - 4
  • When I run calculator cli < expressions.txt
  • Then 6 is printed to stdout
  • And the process exits with code 0

TC-03 — Multiple valid lines, one result per line

  • Given stdin contains:
    2 + 3
    10 / 2
    7 * 8
    
  • When I pipe that input into calculator cli
  • Then stdout is exactly:
    5
    5
    56
    
  • And each result is on its own line
  • And the process exits with code 0

TC-04 — Empty and whitespace-only lines are skipped

  • Given stdin contains:
    2 + 2
    
    
    3 + 1
    
  • When I pipe that input into calculator cli
  • Then stdout is exactly:
    4
    4
    
  • And no error is printed to stderr
  • And the process exits with code 0

TC-05 — Invalid line: error to stderr, processing continues

  • Given stdin contains:
    2 + 3
    5 + *
    4 + 1
    
  • When I pipe that input into calculator cli
  • Then stdout is exactly:
    5
    5
    
  • And a clear error message for the invalid line is printed to stderr
  • And the process exits with a non-zero exit code after all input is consumed

TC-06 — All lines invalid: non-zero exit, no stdout results

  • Given stdin contains only invalid expressions (e.g. 5 + * and 10 / 0)
  • When I pipe that input into calculator cli
  • Then no numeric results are printed to stdout
  • And clear error messages are printed to stderr for each failed line
  • And the process exits with a non-zero exit code

TC-07 — Single-expression mode unchanged when argument provided

  • Given the calculator CLI is available
  • When I run echo "99 + 1" | calculator cli "2 + 3"
  • Then 5 is printed to stdout (argument takes precedence; piped stdin is ignored)
  • And the process exits with code 0

TC-08 — Interactive TTY mode unchanged (regression)

  • Given I run calculator cli with stdin attached to a TTY and no expression argument
  • When the CLI starts
  • Then the existing interactive banner and > prompt are shown
  • And entering 2 + 3 prints 5
  • And quit or exit ends the session normally

TC-09 — Piped output format matches existing single-expression CLI

  • Given the calculator CLI is available
  • When I run calculator cli "2 + 3" and separately echo "2 + 3" | calculator cli
  • Then both commands produce identical stdout (5 only, same formatting)

TC-10 — Multi-operation expressions follow engine rules in piped mode

  • Given multi-operation left-to-right evaluation from #22 is available in the build
  • When I run echo "5 + 2 * 6" | calculator cli
  • Then 42 is printed to stdout (same result as calculator cli "5 + 2 * 6")

TC-11 — Automated tests cover piped stdin scenarios

  • Given the project test suite
  • When I run the unit/integration tests added for this story
  • Then tests pass for: pipe input, redirect input, multiple lines, skipped empty lines, per-line errors with non-zero exit, and regression checks for TTY interactive mode and calculator cli "expr" mode

TC-12 — GUI mode unaffected (regression)

  • Given the calculator GUI is available
  • When I launch and use the GUI normally
  • Then behaviour is unchanged (this story is CLI-only)

Criteria are specific enough to test. Moving to needs/approval for human sign-off before implementation.

## QA Testing Scripts **Story:** Ability to pipe stdin to the non-interactive CLI mode **Estimate:** 5 story points ### TC-01 — Single expression via pipe (non-TTY stdin) - **Given** the calculator CLI is built and on `$PATH` - **When** I run `echo "2 + 3" | calculator cli` - **Then** `5` is printed to stdout (result only — no `=` prefix) - **And** the process exits with code 0 ### TC-02 — Single expression via stdin redirect (non-TTY stdin) - **Given** a file `expressions.txt` containing `10 - 4` - **When** I run `calculator cli < expressions.txt` - **Then** `6` is printed to stdout - **And** the process exits with code 0 ### TC-03 — Multiple valid lines, one result per line - **Given** stdin contains: ``` 2 + 3 10 / 2 7 * 8 ``` - **When** I pipe that input into `calculator cli` - **Then** stdout is exactly: ``` 5 5 56 ``` - **And** each result is on its own line - **And** the process exits with code 0 ### TC-04 — Empty and whitespace-only lines are skipped - **Given** stdin contains: ``` 2 + 2 3 + 1 ``` - **When** I pipe that input into `calculator cli` - **Then** stdout is exactly: ``` 4 4 ``` - **And** no error is printed to stderr - **And** the process exits with code 0 ### TC-05 — Invalid line: error to stderr, processing continues - **Given** stdin contains: ``` 2 + 3 5 + * 4 + 1 ``` - **When** I pipe that input into `calculator cli` - **Then** stdout is exactly: ``` 5 5 ``` - **And** a clear error message for the invalid line is printed to stderr - **And** the process exits with a non-zero exit code after all input is consumed ### TC-06 — All lines invalid: non-zero exit, no stdout results - **Given** stdin contains only invalid expressions (e.g. `5 + *` and `10 / 0`) - **When** I pipe that input into `calculator cli` - **Then** no numeric results are printed to stdout - **And** clear error messages are printed to stderr for each failed line - **And** the process exits with a non-zero exit code ### TC-07 — Single-expression mode unchanged when argument provided - **Given** the calculator CLI is available - **When** I run `echo "99 + 1" | calculator cli "2 + 3"` - **Then** `5` is printed to stdout (argument takes precedence; piped stdin is ignored) - **And** the process exits with code 0 ### TC-08 — Interactive TTY mode unchanged (regression) - **Given** I run `calculator cli` with stdin attached to a TTY and no expression argument - **When** the CLI starts - **Then** the existing interactive banner and `>` prompt are shown - **And** entering `2 + 3` prints `5` - **And** `quit` or `exit` ends the session normally ### TC-09 — Piped output format matches existing single-expression CLI - **Given** the calculator CLI is available - **When** I run `calculator cli "2 + 3"` and separately `echo "2 + 3" | calculator cli` - **Then** both commands produce identical stdout (`5` only, same formatting) ### TC-10 — Multi-operation expressions follow engine rules in piped mode - **Given** multi-operation left-to-right evaluation from #22 is available in the build - **When** I run `echo "5 + 2 * 6" | calculator cli` - **Then** `42` is printed to stdout (same result as `calculator cli "5 + 2 * 6"`) ### TC-11 — Automated tests cover piped stdin scenarios - **Given** the project test suite - **When** I run the unit/integration tests added for this story - **Then** tests pass for: pipe input, redirect input, multiple lines, skipped empty lines, per-line errors with non-zero exit, and regression checks for TTY interactive mode and `calculator cli "expr"` mode ### TC-12 — GUI mode unaffected (regression) - **Given** the calculator GUI is available - **When** I launch and use the GUI normally - **Then** behaviour is unchanged (this story is CLI-only) --- Criteria are specific enough to test. Moving to `needs/approval` for human sign-off before implementation.
Smithy-bot removed their assignment 2026-09-17 12:15:18 +01:00
Vylpes removed their assignment 2026-09-17 12:28:19 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
RabbitLabs/calculator#30
No description provided.