Skip to content

Commit

Permalink
implement .reader()
Browse files Browse the repository at this point in the history
Output reader threads are now only spawned when output is captured,
rather than unconditionally. The `.read()` method is also now
implemented in terms of `.reader()`. That means that something like..

    let output = cmd!("foo").read()?;

...doesn't spawn any threads.

Closes #74.
  • Loading branch information
oconnor663 committed Sep 18, 2019
1 parent ec139d0 commit 0e04a27
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 95 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ let current_branch = cmd!("git", "symbolic-ref", "--short", "HEAD").read()?;
let args = &["log", &current_branch];
cmd("git", args).run()?;

// Log again, but this time read the output from a pipe of our own. We
// use the os_pipe crate to create the pipe, but any type implementing
// IntoRawFd works here, including File.
let (pipe_reader, pipe_writer) = os_pipe::pipe()?;
let child = cmd!("git", "log", "--oneline").stdout_handle(pipe_writer).start()?;
for line in BufReader::new(pipe_reader).lines() {
// Log again, but this time read the output one line at a time.
let reader = cmd!("git", "log", "--oneline").reader()?;
for line in BufReader::new(reader).lines() {
assert!(!line?.contains("heck"), "profanity filter triggered");
}
```
Expand Down
Loading

0 comments on commit 0e04a27

Please sign in to comment.