cmd_macro/
lib.rs

1//! Run shell scripts inline with your rust code
2//!
3//! # Example
4//! ```
5//! #![feature(proc_macro_hygiene)]
6//! use cmd_macro::cmd;
7//!
8//! fn main() {
9//!     let who = "world";
10//!     let output = cmd!(echo hello #who ##who).unwrap();
11//!     let output = String::from_utf8(output.stdout).unwrap();
12//!     assert_eq!(output, "hello world #who\n");
13//!
14//!     let s = "seq";
15//!     let n = 3;
16//!     let output = cmd!(#s #{2 * n}).unwrap();
17//!     let output = String::from_utf8(output.stdout).unwrap();
18//!     assert_eq!(output, "1\n2\n3\n4\n5\n6\n");
19//! }
20//! ```
21
22#![forbid(unsafe_code)]
23
24/// Run a series of commands
25///
26/// # Example
27/// ```
28/// #![feature(proc_macro_hygiene)]
29/// use cmd_macro::cmd;
30///
31/// fn main() {
32///     let who = "world";
33///     let output = cmd!(echo hello #who ##who).unwrap();
34///     let output = String::from_utf8(output.stdout).unwrap();
35///     assert_eq!(output, "hello world #who\n");
36///
37///     let s = "seq";
38///     let n = 3;
39///     let output = cmd!(#s #{2 * n}).unwrap();
40///     let output = String::from_utf8(output.stdout).unwrap();
41///     assert_eq!(output, "1\n2\n3\n4\n5\n6\n");
42/// }
43/// ```
44pub use cmd_derive::cmd;
45
46pub mod env;
47
48use thiserror::Error;
49
50#[derive(Debug, Error)]
51pub enum ShellError {
52    #[error("expanding args")]
53    ExpandError(#[from] std::env::VarError),
54    #[error("parsing args")]
55    ParseError(#[from] env::ParseError),
56    #[error("executing command")]
57    ExectutionError(#[from] std::io::Error),
58}
59
60pub type Result<T> = std::result::Result<T, ShellError>;