workmn 0.0.5

Manages the lifecycle of projects on the local machine
Documentation
use config::Value;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::path::PathBuf;

#[derive(Debug, Clone)]
pub(crate) struct RawProject {
    pub name: String,
    pub value: HashMap<String, Value>,
}

impl TryFrom<(String, Value)> for RawProject {
    type Error = config::ConfigError;

    fn try_from((name, value): (String, Value)) -> Result<Self, Self::Error> {
        Ok(Self {
            name,
            value: value.try_into()?,
        })
    }
}

#[derive(Debug, Clone)]
pub struct ProjectInfo<'a> {
    raw: &'a RawProject,
}

impl<'a> ProjectInfo<'a> {
    pub(crate) fn new(raw: &'a RawProject) -> Self {
        Self { raw }
    }

    pub fn name(&self) -> &str {
        &self.raw.name
    }

    pub fn raw_path(&self) -> Option<String> {
        match self.raw.value.get("path") {
            Some(val) => val.clone().into_str().ok(),
            _ => None,
        }
    }

    pub fn path(&self) -> Option<PathBuf> {
        self.raw_path()
            .map(|raw| shellexpand::tilde(&raw).to_string().into())
    }
}