#![allow(unused_doc_comment)]
use dev_prefix::*;
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub const REPO_VAR: &'static str = "repo";
pub const CWD_VAR: &'static str = "cwd";
pub const NAME_VALID_STR: &'static str = "(?:REQ|SPC|TST)(?:-[A-Z0-9_-]*[A-Z0-9_])?";
lazy_static!{
pub static ref NAME_VALID: Regex = Regex::new(
&format!("^{}$", NAME_VALID_STR)).unwrap();
pub static ref REPO_DIR: PathBuf = PathBuf::from(".art");
pub static ref SETTINGS_PATH: PathBuf = REPO_DIR.join("settings.toml");
}
error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
}
links {
}
foreign_links {
Io(::std::io::Error);
Fmt(::std::fmt::Error);
StrFmt(::strfmt::FmtError);
TomlError(::toml::de::Error);
}
errors {
Load(desc: String) {
description("Misc error while loading artifacts")
display("Error loading: {}", desc)
}
TomlParse(locs: String) {
description("Error while parsing TOML file")
display("Error parsing TOML: {}", locs)
}
MissingTable {
description("Must contain a single table")
}
InvalidName(desc: String) {
description("Invalid artifact name")
display("Invalid artifact name: \"{}\"", desc)
}
InvalidAttr(name: String, attr: String) {
description("Artifact has invalid attribute")
display("Artifact {} has invalid attribute: {}", name, attr)
}
InvalidSettings(desc: String) {
description("Invalid settings")
display("Invalid settings: {}", desc)
}
InvalidArtifact(name: String, desc: String) {
description("Invalid artifact")
display("Artifact {} is invalid: {}", name, desc)
}
MissingParent(name: String, parent: String) {
description("Missing parent artifact")
display("Parent {} does not exist for {}", parent, name)
}
InvalidTextVariables {
description("Couldn't resolve some text variables")
}
InvalidPartof {
description("Some artifacts have invalid partof attributes")
}
InvalidDone {
description("Some artifacts have invalid partof attributes")
}
NameNotFound(desc: String) {
description("Searched for names were not found")
display("The following artifacts do not exists: {}", desc)
}
LocNotFound {
description("Errors while finding implementation locations")
}
DoneTwice(desc: String) {
description("The artifact is done and implemented in code")
display("Referenced in code and `done` is set: {}", desc)
}
InvalidUnicode(path: String) {
description("We do not yet support non-unicode paths")
display("Invalid unicode in path: {}", path)
}
CmdError(desc: String) {
description("Error while running a command")
display("{}", desc)
}
PathNotFound(desc: String) {
description("Invalid path")
display("Path does not exist: {}", desc)
}
NotEqual(desc: String) {
description("Values not equal")
display("{}", desc)
}
Security(desc: String) {
description("Security vulnerability detected")
display("Security vulnerability: {}", desc)
}
Internal(desc: String) {
description("Internal error")
display("Internal error: {}", desc)
}
NothingDone {
description("Internal control flow")
}
}
}
pub trait LoadFromStr: Sized {
fn from_str(s: &str) -> Result<Self>;
}
pub type Artifacts = HashMap<NameRc, Artifact>;
pub type Names = HashSet<NameRc>;
pub type NameRc = Arc<Name>;
#[derive(Debug, Clone)]
pub struct Project {
pub artifacts: Artifacts,
pub settings: Settings,
pub files: HashSet<PathBuf>,
pub dne_locs: HashMap<Name, Loc>,
pub origin: PathBuf,
pub repo_map: HashMap<PathBuf, PathBuf>,
}
impl Default for Project {
fn default() -> Project {
Project {
artifacts: Artifacts::default(),
settings: Settings::default(),
files: HashSet::default(),
dne_locs: HashMap::default(),
origin: PathBuf::default(),
repo_map: HashMap::default(),
}
}
}
#[derive(Clone)]
pub struct Name {
pub raw: String,
pub value: Vec<String>,
pub ty: Type,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Type {
REQ,
SPC,
TST,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Loc {
pub path: PathBuf,
pub line: usize,
}
#[cfg(test)]
impl Loc {
pub fn fake() -> Loc {
Loc {
path: Path::new("fake").to_path_buf(),
line: 42,
}
}
}
impl fmt::Display for Loc {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}[{}]", self.path.display(), self.line)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Done {
Code(Loc),
Defined(String),
NotDone,
}
impl Done {
pub fn is_done(&self) -> bool {
match *self {
Done::Code(_) | Done::Defined(_) => true,
Done::NotDone => false,
}
}
}
impl fmt::Display for Done {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Done::Code(ref c) => write!(f, "{}", c),
Done::Defined(ref s) => write!(f, "{}", s),
Done::NotDone => write!(f, "not done"),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Artifact {
pub id: u64,
pub revision: u64,
pub def: PathBuf,
pub text: String,
pub partof: Names,
pub parts: Names,
pub done: Done,
pub completed: f32,
pub tested: f32,
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Settings {
pub artifact_paths: HashSet<PathBuf>,
pub exclude_artifact_paths: HashSet<PathBuf>,
pub code_paths: HashSet<PathBuf>,
pub exclude_code_paths: HashSet<PathBuf>,
}
impl Settings {
pub fn new() -> Settings {
Settings {
artifact_paths: HashSet::new(),
exclude_artifact_paths: HashSet::new(),
code_paths: HashSet::new(),
exclude_code_paths: HashSet::new(),
}
}
}
#[derive(Debug, Default, Clone, Serialize)]
pub struct ServeCmd {
pub addr: String,
pub readonly: bool,
pub path_url: String,
}