devcon 0.2.0

Runs devcontainer projects.
use std::path::Path;
use std::path::PathBuf;

use crate::devcontainers::Devcontainer;

pub fn run(dir: &Option<String>) -> std::io::Result<()> {
    let directory = get_project_directory(dir)?;
    let devcontainer = Devcontainer::load(directory);
    devcontainer.run(true)?;

    Ok(())
}

fn get_project_directory(dir: &Option<String>) -> std::io::Result<PathBuf> {
    if let Some(path) = dir {
        let mut expanded = shellexpand::env(path).expect("Could not expand dir");

        Path::new(expanded.to_mut()).canonicalize()
    } else {
        std::env::current_dir()
    }
}