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
//! Run shell scripts inline with your rust code
//!
//! # Example
//! ```
//! #![feature(proc_macro_hygiene)]
//! use cmd_macro::cmd;
//!
//! fn main() {
//!     let who = "world";
//!     let output = cmd!(echo hello #who ##who).unwrap();
//!     let output = String::from_utf8(output.stdout).unwrap();
//!     assert_eq!(output, "hello world #who\n");
//!
//!     let s = "seq";
//!     let n = 3;
//!     let output = cmd!(#s #{2 * n}).unwrap();
//!     let output = String::from_utf8(output.stdout).unwrap();
//!     assert_eq!(output, "1\n2\n3\n4\n5\n6\n");
//! }
//! ```

#![forbid(unsafe_code)]

/// Run a series of commands
///
/// # Example
/// ```
/// #![feature(proc_macro_hygiene)]
/// use cmd_macro::cmd;
///
/// fn main() {
///     let who = "world";
///     let output = cmd!(echo hello #who ##who).unwrap();
///     let output = String::from_utf8(output.stdout).unwrap();
///     assert_eq!(output, "hello world #who\n");
///
///     let s = "seq";
///     let n = 3;
///     let output = cmd!(#s #{2 * n}).unwrap();
///     let output = String::from_utf8(output.stdout).unwrap();
///     assert_eq!(output, "1\n2\n3\n4\n5\n6\n");
/// }
/// ```
pub use cmd_derive::cmd;

pub mod env;

use thiserror::Error;

#[derive(Debug, Error)]
pub enum ShellError {
    #[error("expanding args")]
    ExpandError(#[from] std::env::VarError),
    #[error("parsing args")]
    ParseError(#[from] env::ParseError),
    #[error("executing command")]
    ExectutionError(#[from] std::io::Error),
}

pub type Result<T> = std::result::Result<T, ShellError>;