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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/*!
This crate provides a library for executing system commands.

# Usage

This crate is [on crates.io](https://crates.io/crates/reef) and can be
used by adding `reef` to your dependencies in your project's `Cargo.toml`.

```toml
[dependencies]
reef = "0"
```

If you're using Rust 2015, then you'll also need to add it to your crate root:

```rust
extern crate reef;
```

# Example: execute a command that is in the system PATH

note: git must be available in the system PATH for this example to work.

```rust
use reef::Command;
let git_version = Command::new("git --version",&std::env::temp_dir()).exec().unwrap();
assert!(git_version.stdout().contains("git version"));
```

*/

#![crate_name = "reef"]
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::path::PathBuf;
use std::time::Duration;

#[macro_use]
extern crate error_chain;
mod errors;

/// A structure to represent errors coming out of the reef library
//#[derive(Debug)]
//pub struct Error(errors::Error);
/// A Result type for the reef library
//pub type Result<T> = errors::Result<T>;

// #region Structs
// #region struct Env
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
/// Metadata about the environment
pub struct Env {
    /// The username
    username: String,
    /// The hostname,
    hostname: String,
    /// The distro
    distro: String,
    /// The real name for the user
    realname: String,
    /// The device name
    devicename: String,
}
mod env;
// #endregion struct Env

// #region struct Command
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
/// Metadata about a std::process::Command
pub struct Command {
    /// The working directory
    dir: PathBuf,
    /// The command name
    name: String,
    /// The command arguments
    args: Vec<String>,
    /// The standard output text
    stdout: String,
    /// The standard error text
    stderr: String,
    /// Indication of success or failure
    success: bool,
    /// The exit code of the process
    exit_code: i32,
    /// The duration of the command execution
    duration: Duration,
    /// The timeout duration for the command execution
    timeout: Duration,
    /// The start time of the command execution
    start: String,
    /// Environment metadata
    env: Env,
    /// Tags
    tags: HashSet<String>,
    /// UUID
    uuid: String,
}
mod command;
// #endregion struct Command
// #endregion Structs