Skip to content

refactor: introduce ShellConfig for centralized shell configuration#57

Merged
cdprice02 merged 5 commits intomainfrom
refactor/issue-14-shell-config
Apr 8, 2026
Merged

refactor: introduce ShellConfig for centralized shell configuration#57
cdprice02 merged 5 commits intomainfrom
refactor/issue-14-shell-config

Conversation

@cdprice02
Copy link
Copy Markdown
Owner

Description

Closes #14.

Introduces ShellConfig in src/ctx.rs as the single source of truth for configurable shell behavior (prompt, history path, max history size). ShellCtx gains a config: ShellConfig field; the hardcoded "🦀> " prompt in shell.rs is replaced with self.ctx.config.prompt.

ShellBuilder gains two new builder methods:

  • with_config(ShellConfig) — replace the full config
  • with_prompt(String) — override just the prompt string

ShellConfig is re-exported from lib.rs for downstream use.

Type of change

  • Refactor

Test checklist

  • cargo test passes
  • cargo clippy --all-targets --all-features -- -D warnings passes

cdprice02 and others added 4 commits April 6, 2026 18:58
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>
Copilot AI review requested due to automatic review settings April 8, 2026 01:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ShellConfig to ShellCtx as a central configuration object (prompt/history settings).
  • Update Shell::run() to use ctx.config.prompt and return an ExitCode to callers (with builder helpers to override config/prompt).
  • Propagate exit codes to main and 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.

@cdprice02 cdprice02 merged commit ad20274 into main Apr 8, 2026
8 checks passed
@cdprice02 cdprice02 deleted the refactor/issue-14-shell-config branch April 8, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Centralize shell configuration in ShellCtx

2 participants