refactor: introduce ShellConfig for centralized shell configuration#57
Merged
refactor: introduce ShellConfig for centralized shell configuration#57
Conversation
Shell::run() now returns anyhow::Result<ExitCode> instead of Result<()>. main() calls std::process::exit() with the returned code so that exit 0 and exit 1 are reflected in the ferrish process exit status. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- main() returns anyhow::Result<std::process::ExitCode>; ? propagates fatal errors with full anyhow context, and the Termination impl exits the process with the shell's actual exit code - Add From<ExitCode> for std::process::ExitCode to exit.rs; avoids accessing the inner field directly from main - Remove stale TODO from run_script(); exit code is already returned - Restore #[allow(dead_code)] on exit_code field and method; harness.rs compiles into multiple test binaries, only repl.rs uses exit_code() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
BufRead::read_until returns 0 bytes at EOF; continuing the loop caused the REPL to repeatedly print the prompt when stdin was closed (Ctrl-D or piped input exhausted). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds ShellConfig (prompt, history_path, max_history) to src/ctx.rs as the single source of truth for configurable shell behavior. ShellCtx gains a config field; the hardcoded prompt in shell.rs is replaced with self.ctx.config.prompt. ShellBuilder gains with_config() and with_prompt() methods. ShellConfig is re-exported from lib.rs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR centralizes configurable shell behavior by introducing ShellConfig in ShellCtx, wiring the prompt through that config, and propagating ExitCode from the REPL up to the binary entrypoint.
Changes:
- Add
ShellConfigtoShellCtxas a central configuration object (prompt/history settings). - Update
Shell::run()to usectx.config.promptand return anExitCodeto callers (with builder helpers to override config/prompt). - Propagate exit codes to
mainand extend integration tests to assert exit code behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/repl.rs | Adds integration tests asserting exit N propagates the process exit code. |
| tests/harness.rs | Extends the test harness to capture and expose the shell exit code. |
| src/shell.rs | Uses config-driven prompt rendering; changes run() to return ExitCode; adds builder config/prompt overrides. |
| src/main.rs | Converts library ExitCode into std::process::ExitCode for OS-level propagation. |
| src/lib.rs | Re-exports ShellConfig and changes run() to return ExitCode. |
| src/exit.rs | Adds conversion from ExitCode to std::process::ExitCode. |
| src/ctx.rs | Introduces ShellConfig and stores it on ShellCtx. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #14.
Introduces
ShellConfiginsrc/ctx.rsas the single source of truth for configurable shell behavior (prompt, history path, max history size).ShellCtxgains aconfig: ShellConfigfield; the hardcoded"🦀> "prompt inshell.rsis replaced withself.ctx.config.prompt.ShellBuildergains two new builder methods:with_config(ShellConfig)— replace the full configwith_prompt(String)— override just the prompt stringShellConfigis re-exported fromlib.rsfor downstream use.Type of change
Test checklist
cargo testpassescargo clippy --all-targets --all-features -- -D warningspasses