Commit 4545045
authored
refactor: simplify fspy::Command API and add pre_exec hook (#23)
### 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:
```rust
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.1 parent d66556a commit 4545045
File tree
16 files changed
+270
-254
lines changed- crates
- fspy_e2e/src
- fspy_test_utils/src
- fspy
- examples
- src
- unix
- windows
- tests
- vite_task/src
16 files changed
+270
-254
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | | - | |
128 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
129 | 136 | | |
130 | 137 | | |
131 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 19 | + | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 12 | + | |
17 | 13 | | |
18 | | - | |
| 14 | + | |
19 | 15 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
24 | 20 | | |
25 | | - | |
| 21 | + | |
26 | 22 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
30 | 26 | | |
31 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
35 | 52 | | |
36 | 53 | | |
37 | | - | |
| 54 | + | |
38 | 55 | | |
39 | 56 | | |
40 | 57 | | |
| |||
57 | 74 | | |
58 | 75 | | |
59 | 76 | | |
60 | | - | |
| 77 | + | |
61 | 78 | | |
62 | 79 | | |
63 | 80 | | |
| |||
147 | 164 | | |
148 | 165 | | |
149 | 166 | | |
150 | | - | |
| 167 | + | |
151 | 168 | | |
152 | 169 | | |
153 | 170 | | |
| |||
179 | 196 | | |
180 | 197 | | |
181 | 198 | | |
182 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
183 | 215 | | |
184 | 216 | | |
185 | 217 | | |
| |||
205 | 237 | | |
206 | 238 | | |
207 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
208 | 246 | | |
209 | 247 | | |
210 | 248 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
0 commit comments