From e646a85c5ecccfa02cf64b087ba89eb5d86b3f10 Mon Sep 17 00:00:00 2001 From: penguin Date: Wed, 21 Oct 2020 12:19:42 -0500 Subject: [PATCH] Project creation works mostly. just need symlinks and initial file spawns --- .gdb_history | 49 +++++++++++++++++++ src/igloo.rs | 16 +++++-- src/igloo_action.rs | 74 +++++++---------------------- src/igloo_manifest.rs | 83 ++++++++++++++++++++------------ src/igloo_prj.rs | 107 +++++++++++++++++++++++++++++++++++++----- src/main.rs | 2 +- 6 files changed, 225 insertions(+), 106 deletions(-) diff --git a/.gdb_history b/.gdb_history index bca70f3..4a21c06 100644 --- a/.gdb_history +++ b/.gdb_history @@ -1 +1,50 @@ q +break main +r +n +r +n +q +break igloo_manifest.rs:15 +r +s +s +n +n +n +n +n +n +n +n +n +n +n +n +n +q +break igloo_manifest.rs:15 +r +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +n +q diff --git a/src/igloo.rs b/src/igloo.rs index 2da06f4..15ca535 100644 --- a/src/igloo.rs +++ b/src/igloo.rs @@ -28,10 +28,13 @@ pub enum IglooErrType IGLOO_INVALID_PROJECT_NAME = 7, IGLOO_ENV_INFO_INVALID = 8, IGLOO_INVALID_TARGET = 9, + IGLOO_FAILED_TO_LOAD_MAKE_MAN = 10, + IGLOO_FAILED_TO_LOAD_TARG_MAN = 11, } #[derive(Debug)] #[derive(PartialEq)] +#[derive(Clone)] pub struct IglooEnvInfo { // Current Working Directory @@ -129,18 +132,18 @@ impl Igloo /// It is really only here to help me debug. /// /// The Inst Type is only returned for usage outside of this struct. - pub fn start(&self) -> Result + pub fn start(&mut self) -> Result { let mut res_error = IGLOO_ERR_NONE; let mut res_type = IGLOO_NULL; // Load manifests first - self.make_manifest.clone().merge( + self.make_manifest.merge( config::File::with_name( IglooEnvInfo::info().esfd.join("manifest/make-manifest.toml") .to_str() .unwrap())) .unwrap(); - self.target_manifest.clone().merge( + self.target_manifest.merge( config::File::with_name( IglooEnvInfo::info().esfd.join("manifest/target-manifest.toml") .to_str() @@ -208,7 +211,12 @@ impl Igloo .unwrap().1 .value_of("target") .unwrap(); - IglooAction::new(prj_name, target); + let res_err = IglooAction::new( + self, prj_name, target); + if res_err != IglooErrType::IGLOO_ERR_NONE + { + return Err(res_err) + } } else { diff --git a/src/igloo_action.rs b/src/igloo_action.rs index d0957fa..51b013c 100644 --- a/src/igloo_action.rs +++ b/src/igloo_action.rs @@ -1,14 +1,16 @@ -/// Contains subcommand functions for igloo actions like new, run, push, etc.. pub mod IglooAction { + use crate::igloo_manifest::IglooManifest; use crate::igloo::{Igloo, IglooErrType, IglooEnvInfo}; + use crate::igloo_prj::IglooPrj; + pub fn run(prj_name: &str, target: &str) -> IglooErrType { let res_err: IglooErrType = IglooErrType::IGLOO_ERR_NONE; res_err } - pub fn new(prj_name: &str, target: &str) + pub fn new(inst: &Igloo, prj_name: &str, target: &str) -> IglooErrType { let mut res_err: IglooErrType = IglooErrType::IGLOO_ERR_NONE; @@ -27,66 +29,22 @@ pub mod IglooAction res_err = IglooErrType::IGLOO_FOLDER_ALREADY_EXISTS; return res_err } - // Create new directory - let mut active_dir = IglooEnvInfo::info().cwd; - println!("Active Directory: {:?}", active_dir.display()); - active_dir.push(prj_name); - match std::fs::create_dir(&active_dir) - { - Err(e) => println!("{:?}", e), - _ => (), - } - println!("Active Directory: {:?}", active_dir.display()); - println!("Creating .igloo dir..."); - match std::fs::create_dir( - std::path::Path::new(&active_dir) - .join(".igloo")) - { - Err(e) => println!("{:?}", e), - _ => (), - } - match std::fs::create_dir( - std::path::Path::new(&active_dir) - .join("src")) - { - Err(e) => println!("{:?}", e), - _ => (), - } - match std::fs::create_dir( - std::path::Path::new(&active_dir) - .join("inc")) - { - Err(e) => println!("{:?}", e), - _ => (), - } - match std::fs::create_dir( - std::path::Path::new(&active_dir) - .join("cfg")) - { - Err(e) => println!("{:?}", e), - _ => (), - } - match std::fs::create_dir( - std::path::Path::new(&active_dir) - .join("ESF")) - { - Err(e) => println!("{:?}", e), - _ => (), - } - // load targets - //create symlinks in ESF - match std::os::unix::fs::symlink("", "") - { - Err(e) => println!("{:?}", e), + let mut project = IglooPrj::new(inst, prj_name, target); + match project + { + Err(e) => + { + println!("Error spawning project: {:?}", e); + res_err = e; + return res_err + } _ => (), } - println!("Displaying contents of {:?}", active_dir.display()); - for entry in active_dir.read_dir() - .unwrap() + let res_err = project.unwrap().populate(); + if res_err != IglooErrType::IGLOO_ERR_NONE { - let dir = entry.unwrap(); - println!("{:?}", dir.file_name()); + return res_err } res_err } diff --git a/src/igloo_manifest.rs b/src/igloo_manifest.rs index d0fac13..61a7410 100644 --- a/src/igloo_manifest.rs +++ b/src/igloo_manifest.rs @@ -2,50 +2,71 @@ pub mod IglooManifest { use crate::igloo::{Igloo, IglooErrType, IglooEnvInfo}; - pub fn target_exists(inst: &Igloo, name: &str) -> bool + pub fn target_exists(inst: &Igloo, name: &str) -> Result { - let mut ret: bool = false; - loop + let mut ret: bool = true; + let mut res_err = IglooErrType::IGLOO_ERR_NONE; + if name.is_empty() { - if name.is_empty() - { - ret = false; - break; - } + return Err(IglooErrType::IGLOO_INVALID_TARGET) + } - let make_table = inst.target_manifest.get_table("target.make").unwrap(); - let manifest_table = inst.target_manifest.get_table("target.manifest").unwrap(); - - match make_table.get(name) + + let make_table = inst.target_manifest.get_table("target.make"); + match make_table + { + Ok(v) => { - Some(v) => + match v.get(name) { - println!("target.make entry for \"{}\" exists!", name); - ret = true; + Some(v) => + { + println!("target.make entry for \"{}\" exists!", name); + } + None => + { + println!("target.make entry for \"{}\" does not exist", name); + ret = false; + } } - None => - { - ret = false; - } - } - if !ret + } + Err(e) => { - break; + println!("{:?}", e); + return Err(IglooErrType::IGLOO_FAILED_TO_LOAD_MAKE_MAN) } + } - match manifest_table.get(name) + if !ret + { + return Ok(ret) + } + + let target_table = inst.target_manifest.get_table("target.manifest"); + match target_table + { + Ok(v) => { - Some(v) => - { - println!("target.manifest entry for \"{}\" exists!", name); - } - None => + match v.get(name) { - ret = false; + Some(v) => + { + println!("target.manifest entry for \"{}\" exists!", name); + } + None => + { + ret = false; + } } } - break; } - ret + Err(e) => + { + println!("{:?}", e); + return Err(IglooErrType::IGLOO_FAILED_TO_LOAD_TARG_MAN) + } + } + + Ok(ret) } } diff --git a/src/igloo_prj.rs b/src/igloo_prj.rs index af6d059..063705d 100644 --- a/src/igloo_prj.rs +++ b/src/igloo_prj.rs @@ -1,5 +1,5 @@ use crate::igloo::{Igloo, IglooEnvInfo, IglooErrType}; -use crate::igloo_manifest::{IglooManifest}; +use crate::igloo_manifest::IglooManifest; use std::collections::HashMap; // New Project // --- Verify location @@ -35,7 +35,7 @@ impl IglooPrj } } - pub fn new(nameIn: &str, targetIn: &str, env_infoIn: &IglooEnvInfo) + pub fn new(inst: &Igloo, nameIn: &str, targetIn: &str) -> Result { let mut res_err = IglooErrType::IGLOO_ERR_NONE; @@ -54,6 +54,26 @@ impl IglooPrj { return Err(res_err) } + match IglooManifest::target_exists(inst, targetIn) + { + Ok(v) => + { + if v + { + println!("Verified target exists {}", nameIn); + } + else + { + println!("Couldn't verify target exists {}", nameIn); + return Err(IglooErrType::IGLOO_INVALID_TARGET) + } + } + Err(e) => + { + return Err(e) + } + } + Ok(IglooPrj { @@ -62,6 +82,79 @@ impl IglooPrj env_info: IglooEnvInfo::info(), }) } + + pub fn populate(&self) -> IglooErrType + { + // Create new directory + let mut active_dir = IglooEnvInfo::info().cwd; + //println!("Active Directory: {:?}", active_dir.display()); + println!("NAME: {}", self.name); + active_dir.push(&self.name); + match std::fs::create_dir(&active_dir) + { + Err(e) => println!("{:?}", e), + _ => (), + } + //println!("Active Directory: {:?}", active_dir.display()); + println!("Creating .igloo dir..."); + match std::fs::create_dir( + std::path::Path::new(&active_dir) + .join(".igloo")) + { + Err(e) => println!("{:?}", e), + _ => (), + } + match std::fs::create_dir( + std::path::Path::new(&active_dir) + .join("src")) + { + Err(e) => println!("{:?}", e), + _ => (), + } + match std::fs::create_dir( + std::path::Path::new(&active_dir) + .join("inc")) + { + Err(e) => println!("{:?}", e), + _ => (), + } + match std::fs::create_dir( + std::path::Path::new(&active_dir) + .join("cfg")) + { + Err(e) => println!("{:?}", e), + _ => (), + } + match std::fs::create_dir( + std::path::Path::new(&active_dir) + .join("ESF")) + { + Err(e) => println!("{:?}", e), + _ => (), + } + + // load targets + //create symlinks in ESF + // match std::os::unix::fs::symlink("", "") + // { + // Err(e) => println!("{:?}", e), + // _ => (), + // } + println!("Displaying contents of {:?}", active_dir.display()); + for entry in active_dir.read_dir() + .unwrap() + { + let dir = entry.unwrap(); + println!("{:?}", dir.file_name()); + } + + IglooErrType::IGLOO_ERR_NONE + } + + pub fn env(self) -> IglooEnvInfo + { + self.env_info.clone() + } } impl IglooTarget @@ -76,16 +169,6 @@ impl IglooTarget } } - pub fn from(inst: &Igloo, nameIn: &str) -> Result - { - if !IglooManifest::target_exists(inst, nameIn) - { - return Err(IglooErrType::IGLOO_INVALID_TARGET) - } - - - Ok(IglooTarget::default()) - } } diff --git a/src/main.rs b/src/main.rs index 09b2799..6dd63ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ mod igloo_manifest; fn main() { - let ig = igloo::Igloo::new(); + let mut ig = igloo::Igloo::new(); let _start_ret = match ig.start() { Ok(it) =>