Skip to content

Commit 6cf318d

Browse files
committed
Enhance README and examples; add stdin_reader for streaming input and support for rename events in watch functionality
1 parent 1430e80 commit 6cf318d

File tree

5 files changed

+308
-42
lines changed

5 files changed

+308
-42
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,24 @@ fn main() -> qshr::Result<()> {
137137

138138
Within `qshr!`, any Rust statement is permitted, so you can loop, branch, or shadow variables while the string literals do the repetitive shell work for you.
139139

140-
### 6. Lazy filesystem helpers
140+
### 6. Stream stdin from a reader
141+
142+
```rust
143+
use qshr::prelude::*;
144+
use std::fs::File;
145+
146+
fn main() -> qshr::Result<()> {
147+
let file = File::open("README.md")?;
148+
let output = cmd("wc").arg("-l").stdin_reader(file).stdout_text()?;
149+
println!("README has {output}");
150+
Ok(())
151+
}
152+
```
153+
154+
When you need to stream data into a child process (large files, sockets, pipes),
155+
`stdin_reader` avoids buffering everything into memory up front.
156+
157+
### 7. Lazy filesystem helpers
141158

142159
Every filesystem iterator (`ls`, `walk_files`, `glob_entries`, etc.) yields a `Shell<Result<_>>`, so you can lazily stream and short-circuit as needed:
143160

@@ -224,6 +241,10 @@ if let Ok(event) = rx.try_recv() {
224241
}
225242
```
226243

244+
Rename operations surface as `WatchEvent::Renamed`, giving you access to both
245+
`event.path()` (the destination) and `event.from_path()` for the source when
246+
files move without being rewritten.
247+
227248
When you need to reuse glob metadata multiple times (copy/move operations, filtering), resolve once via `GlobCache::new("src/**/*.rs")` and call `.entries()` to avoid repeated `fs::metadata` calls.
228249

229250
Need backwards iteration? Wrap in `DoubleEndedShell::from_vec(vec)` and call `next_back()` on it before converting back into a plain `Shell`.
@@ -243,8 +264,8 @@ Browse `examples/` for small scripts—`script.rs`, `watch_glob.rs`,
243264
## Git hooks
244265

245266
There is a repo-local pre-commit hook at `.githooks/pre-commit` that runs
246-
`cargo fmt --all -- --check`, `cargo clippy --all-targets --all-features -- -D warnings`,
247-
and `cargo test --all-targets --all-features` before allowing a commit. Opt in by
267+
`cargo fmt --all` and `cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features`
268+
before allowing a commit. Opt in by
248269
pointing Git at the hooks directory once:
249270

250271
```

examples/watch_build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ fn main() -> qshr::Result<()> {
2020
WatchEvent::Removed { path, .. } => {
2121
println!("Removed {}", path.display());
2222
}
23+
WatchEvent::Renamed { from, to, .. } => {
24+
println!("Renamed {} -> {}", from.display(), to.display());
25+
}
2326
}
2427
}
2528
Ok(())

examples/watch_trigger.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ fn main() -> qshr::Result<()> {
2121
WatchEvent::Removed { path, .. } => {
2222
println!("Removed {}", path.display());
2323
}
24+
WatchEvent::Renamed { from, to, .. } => {
25+
println!("Renamed {} -> {}", from.display(), to.display());
26+
}
2427
}
2528
}
2629

0 commit comments

Comments
 (0)