1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
//! A simple annonymous UNIX pipe type.
//!
//! ## Usage
//!
//! ### try_from(&str)
//!
//! The probably easiest way to create a pipe is by parsing a command string:
//!
//! ```
//! # fn main() -> Result<(), apipe::error::APipeError> {
//! use apipe::CommandPipe;
//!
//! let mut pipe = CommandPipe::try_from(r#"echo "This is a test." | grep -Eo \w\w\sa[^.]*"#)?;
//!
//! let output = pipe.spawn_with_output()?;
//!
//! assert_eq!(output.stdout(), "is a test\n".as_bytes());
//!
//! # Ok(())
//! # }
//! ```
//! This requires the `parser` feature to be enabled.
//!
//! ### Pipe Command Objects
//!
//! Create the individual Commands and then contruct a pipe from them:
//!
//! ```
//! # fn main() -> Result<(), apipe::error::APipeError> {
//! use apipe::Command;
//!
//! let mut pipe = Command::parse_str(r#"echo "This is a test.""#)?
//! | Command::parse_str(r#"grep -Eo \w\w\sa[^.]*"#)?;
//!
//! // or:
//!
//! let mut pipe = Command::new("echo").arg("This is a test.")
//! | Command::new("grep").args(&["-Eo", r"\w\w\sa[^.]*"]);
//!
//! let output = pipe.spawn_with_output()?;
//!
//! assert_eq!(output.stdout(), "is a test\n".as_bytes());
//!
//! # Ok(())
//! # }
//! ```
//!
//! [Command]s can also be constructed manually if you want:
//!
//! ```
//! # use apipe::Command;
//! let mut command = Command::new("ls").arg("-la");
//! ```
//!
//! ### Builder
//!
//! There is also a conventional builder syntax:
//!
//! ```
//! # fn main() -> Result<(), apipe::error::APipeError> {
//! use apipe::CommandPipe;
//!
//! let output = apipe::CommandPipe::new()
//! .add_command("echo")
//! .arg("This is a test.")
//! .add_command("grep")
//! .args(&["-Eo", r"\w\w\sa[^.]*"])
//! .spawn_with_output()?;
//!
//! assert_eq!(output.stdout(), "is a test\n".as_bytes());
//! # Ok(())
//! # }
//! ```
pub use Command;
pub use APipeError;
pub use CommandPipe;