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
163
164
165
#![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;

#[macro_use]
extern crate error_chain;
pub mod errors;
pub use errors::*;

// #region Macros
// #endregion Macros

// #region Structs

// #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>,
    /// UUID
    uuid: String,
}
mod command;
// #endregion struct Command

// regions struct Remotes
#[derive(Serialize, Deserialize)]
pub struct Remotes {
    origins: HashSet<String>,
    #[serde(skip_serializing)]
    filename: PathBuf,
}
pub mod remotes;
// endregion struct Remotes

// #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,
}
// #endregion struct Commit

// #region struct Git
/// Git functionality
pub struct Git;
mod git;
// #endregion struct Git

pub struct Runner;
mod runner;

// #endregion Structs

// #region Enums
#[derive(Debug)]
pub enum Tasks {
    Clobber,
    Build,
    Test,
    Default,
}
// #endregion Enums

// #region Functions
// #endregion Functions
mod string;

// #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) -> errors::Result<Vec<u8>>;
    fn from_bytes<T: DeserializeOwned>(bytes: Vec<u8>) -> errors::Result<T>;

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

    fn open<T: DeserializeOwned>(path: &Path) -> errors::Result<T> {
        match std::fs::read(path) {
            Ok(bytes) => match serde_json::from_slice::<T>(&bytes) {
                Ok(value) => Ok(value),
                Err(e) => Err(errors::Error::from(e)),
            },
            Err(e) => Err(errors::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