Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/everlastingbugstopper/shell-candy
🍬 shell-candy is a library that wraps Rust's `std::process::Command`, providing a functional mechanism for handling stdout/stderr streams of spawned tasks..
https://github.com/everlastingbugstopper/shell-candy
Last synced: 10 days ago
JSON representation
🍬 shell-candy is a library that wraps Rust's `std::process::Command`, providing a functional mechanism for handling stdout/stderr streams of spawned tasks..
- Host: GitHub
- URL: https://github.com/everlastingbugstopper/shell-candy
- Owner: EverlastingBugstopper
- License: mit
- Created: 2022-10-07T22:33:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-15T21:00:28.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T13:36:55.650Z (26 days ago)
- Language: Rust
- Homepage:
- Size: 27.3 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🍬 `shell-candy`
This crate wraps `std::process::Command`, providing an easier mechanism for handling individual log lines from external tools.
## Usage
This example shows the basic usage of `ShellTask`: create one from a POSIX-style command, and then run it with a log line handler that you write yourself. This handler can either continue for every line for the length of the program, or it can return early and shut down the program.
You could use this function to pass log lines through your own log formatter like so:
```rust
use anyhow::Result;
use shell_candy::{ShellTaskLog, ShellTaskBehavior, ShellTask};fn main() -> Result<()> {
let task = ShellTask::new("rustc --version")?;
task.run(|line| {
match line {
ShellTaskLog::Stdout(message) | ShellTaskLog::Stderr(message) => eprintln!("info: {}", &message),
}
ShellTaskBehavior::<()>::Passthrough
})?;
Ok(())
}
```You could also use this function to return early if a command meets a specific criteria (like encountering an unrecoverable error):
```rust
use anyhow::{anyhow, Error, Result};
use shell_candy::{ShellTaskLog, ShellTaskBehavior, ShellTask};fn main() -> Result<()> {
let task = ShellTask::new("git log")?;
task.run(|line| {
match line {
ShellTaskLog::Stdout(message) | ShellTaskLog::Stderr(message) => {
if message.contains("an error that is unlikely to be in your git logs but just might be") {
return ShellTaskBehavior::<()>::EarlyReturn(Err(anyhow!("encountered an error while running 'git log'").into()));
}
},
}
ShellTaskBehavior::<()>::Passthrough
})?;
Ok(())
}
```## More information
See [the docs](https://docs.rs/shell-candy) for more detailed information and example usage.