feat: Pipe

This commit is contained in:
2025-01-29 00:04:00 -05:00
parent 6fa4b21c4f
commit 9d944c3218
15 changed files with 888 additions and 235 deletions

View File

@@ -11,8 +11,8 @@ Add `comlexr` to your project's `Cargo.toml`:
comlexr = "1.2.0"
```
### Rust Edition
This project uses Rust **2018 edition** to ensure compatibility and stable language features.
## MSRV
The minimum supported Rust version is `1.60.0` for broader support.
## Usage
@@ -206,14 +206,42 @@ assert_eq!(
);
```
### Piping commands
When using the `pipe` feature, you can make use of `pipe!` to chain the stdout of commands to stdin. Execution is lazy so commands aren't run until `status()` or `output()` is called.
```rust
use comlexr::{pipe, cmd};
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("out");
let mut pipe = pipe!(cmd!("echo", "test") | cmd!("tee", &file));
let status = pipe.status().unwrap();
assert!(status.success());
```
### Sending variables to stdin
You can also send data to the stdin of the first command in the chain.
```rust
use comlexr::{pipe, cmd};
let mut pipe = pipe!(stdin = "test"; cmd!("sed", "s|e|oa|"));
let output = pipe.output().unwrap();
assert!(output.status.success());
assert_eq!(String::from_utf8_lossy(&output.stdout), "toast");
```
## Features
- Conditional expressions (`if`, `if let`)
- Iteration constructs (`for`, `for in`)
- Pattern matching (`match`)
- Support for closures and dynamic expressions
- Piping stdout from one command to the stdin of another
## Examples
See the [tests](./tests/) directory for more examples on how to use `comlexr` effectively in your project.
## License
This project is licensed under the [MIT License](LICENSE).
This project is licensed under the [MIT License](./LICENSE).