Skip to content

refactor: simplify fspy::Command API and add pre_exec hook#23

Merged
branchseer merged 6 commits intomainfrom
11-11-refactor_simplify_fspy_command_api_and_add_pre_exec_hook
Nov 11, 2025
Merged

refactor: simplify fspy::Command API and add pre_exec hook#23
branchseer merged 6 commits intomainfrom
11-11-refactor_simplify_fspy_command_api_and_add_pre_exec_hook

Conversation

@branchseer
Copy link
Member

@branchseer branchseer commented Nov 11, 2025

TL;DR

Refactored the fspy crate to simplify the API by removing the Spy struct and making Command the primary entry point.

What changed?

  • Removed the Spy struct and replaced it with a global SPY_IMPL static using LazyLock
  • Made Command::new() the primary entry point for creating commands instead of Spy::new_command()
  • Renamed SpyInner to SpyImpl and moved spawn implementation into this struct
  • Added pre_exec support to Command on Unix platforms
  • Made most Command fields private with proper accessors
  • Added derive_more dependency for better Debug implementations
  • Updated all tests and examples to use the new API

How to test?

  • Run the existing test suite to verify the refactored API works correctly
  • Try creating and running commands with the new API:
    let mut command = fspy::Command::new("program");
    command.args(["arg1", "arg2"]);
    let child = command.spawn().await?;

Why make this change?

This refactoring simplifies the API by removing an unnecessary abstraction layer. The Spy struct was mostly a wrapper around creating commands, and having a global instance was redundant. By making Command the primary entry point and using a global implementation internally, the API becomes more intuitive and follows patterns similar to standard libraries. The change also improves encapsulation by making fields private and adding proper accessors.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@branchseer branchseer marked this pull request as ready for review November 11, 2025 08:23
@branchseer branchseer merged commit 4545045 into main Nov 11, 2025
6 checks passed
@Brooooooklyn Brooooooklyn deleted the 11-11-refactor_simplify_fspy_command_api_and_add_pre_exec_hook branch December 11, 2025 06:39
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.

2 participants