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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#![crate_name = "reef"]
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::marker::Sized;
use std::path::{Path, PathBuf};
use std::time::Duration;

// #region Macros
// #endregion Macros

// #region Structs

// #region struct Error
#[derive(Debug)]
/// The general error type for reef
pub struct Error {
    kind: String,
    message: String,
}
mod error;
// #endregion struct Error

// #region struct Env
#[derive(Serialize, Deserialize, Clone, Debug)]
/// 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 Paths
/// Functionality to help determine system paths
pub struct Paths;
mod paths;
// #endregion struct Paths

// #region struct Command
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
/// 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 start time of the command execution
    start: String,
    /// Environment metadata
    env: Env,
    /// Tags
    tags: HashSet<String>,
}
mod command;
// #endregion struct Command

// #region struct Commit
/// Metadata about a git commit
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct Commit {
    /// The remote origin
    origin: String,
    /// The commit id or tag name
    name: String, // CommitID or Tag or Other: e.g. d45e56..., v0.0.0, work-6/23/2020-11:39AM
    /// The branch
    branch: String,
    /// The author of the commit
    author: String,
    /// The commit message
    message: String,
    /// The commit date
    date: String,
    /// The size of the source directory for the commit
    size: i64,
    /// A command that is executed for the source directory for the commit
    command: Command,
}
// #endregion struct Commit

// #endregion Structs

// #region Enums
// #endregion Enums

// #region Functions

/*
/// Capture a specific match group
///
/// Example
///
/// ```
/// let text = "Denver, CO 80212";
/// let zip = reef::capture(text,r"([\d]+)",1).unwrap();
/// assert_eq!("80212",zip);
/// ```
///
pub fn capture(text: &str, regex: &str, index: usize) -> Result<String> {
    string::capture(text, regex, index)
}
mod string;
*/
// #endregion Functions

// #region Traits
// #region trait Format
/// A trait to provide conversion to and from bytes for a generic type
pub trait Format {
    fn to_bytes<T: Sized + Serialize>(value: T) -> Result<Vec<u8>>;
    fn from_bytes<T: DeserializeOwned>(bytes: Vec<u8>) -> Result<T>;

    fn save_as<T: Sized + Serialize>(value: T, path: &Path) -> Result<()> {
        match Self::to_bytes(&value) {
            Ok(bytes) => match std::fs::write(path, &bytes) {
                Ok(_) => Ok(()),
                Err(e) => Err(Error::from(e)),
            },
            Err(e) => Err(Error::from(e)),
        }
    }

    fn open<T: DeserializeOwned>(path: &Path) -> Result<T> {
        match std::fs::read(path) {
            Ok(bytes) => match serde_json::from_slice::<T>(&bytes) {
                Ok(value) => Ok(value),
                Err(e) => Err(Error::from(e)),
            },
            Err(e) => Err(Error::from(e)),
        }
    }
}
pub mod format;
// #endregion trait Format
// #endregion Traits

// #region Type Definitions
/// A specialized Result type for reef operations
pub type Result<T> = std::result::Result<T, Error>;
// #endregion

//mod doc;