Added env info

unstable
penguin 4 years ago
parent 74bba47087
commit c43222a05d

@ -25,6 +25,18 @@ pub enum IglooErrType
IGLOO_FOLDER_ALREADY_EXISTS = 6, IGLOO_FOLDER_ALREADY_EXISTS = 6,
} }
#[derive(Debug)]
#[derive(PartialEq)]
pub struct IglooEnvInfo
{
// Current Working Directory
cwd: std::path::PathBuf,
// Home Directory
hd: std::path::PathBuf,
// ESF Directory
esfd: std::path::PathBuf,
}
use IglooInstType::*; use IglooInstType::*;
use IglooErrType::*; use IglooErrType::*;
@ -35,6 +47,7 @@ pub struct Igloo
{ {
conf: config::Config, conf: config::Config,
cli_conf: clap::ArgMatches, cli_conf: clap::ArgMatches,
env_info: IglooEnvInfo,
} }
impl Igloo impl Igloo
@ -50,6 +63,27 @@ impl Igloo
Igloo Igloo
{ {
conf: config::Config::default(), conf: config::Config::default(),
env_info:
{
IglooEnvInfo
{
cwd: std::env::current_dir().unwrap(),
hd: std::env::home_dir().unwrap(),
esfd: match std::env::var("IGLOO_DIR")
{
Ok(v) =>
{
std::path::PathBuf::from(v.to_owned() + "/ePenguin-Software-Framework")
}
Err(e) =>
{
// Note: Need to change New to return errors instead of exiting early
println!("Error: $IGLOO_DIR not defined as an environment variable -- {:?}", e);
std::process::exit(1);
}
}
}
},
cli_conf: clap::App::new("igloo") cli_conf: clap::App::new("igloo")
.about(clap::crate_description!()) .about(clap::crate_description!())
.version(clap::crate_version!()) .version(clap::crate_version!())
@ -103,7 +137,9 @@ impl Igloo
{ {
let mut res_error = IGLOO_ERR_NONE; let mut res_error = IGLOO_ERR_NONE;
let mut res_type = IGLOO_NULL; let mut res_type = IGLOO_NULL;
println!("Current Directory: {:?}", self.env_info.cwd.display());
println!("ESF Directory: {:?}", self.env_info.esfd.display());
println!("Home Directory: {:?}", self.env_info.hd.display());
match self.cli_conf.subcommand_name() match self.cli_conf.subcommand_name()
{ {
Some("new") => Some("new") =>
@ -167,15 +203,15 @@ impl Igloo
// Check if the project folder already exists // Check if the project folder already exists
// Don't want to accidentally overwrite anything // Don't want to accidentally overwrite anything
let prj_path = std::path::Path::new(prj_name); let mut prj_path_buf = std::path::PathBuf::from(prj_name);
if prj_path.exists() if std::path::Path::new(prj_name).exists()
{ {
res_err = IGLOO_FOLDER_ALREADY_EXISTS; res_err = IGLOO_FOLDER_ALREADY_EXISTS;
break; break;
} }
let prj_dir = std::fs::create_dir(prj_path).unwrap();
println!("{:?}", prj_path.canonicalize().unwrap()); // Create new directory
// populate new dir with defaults! let active_dir = self.env_info.cwd.clone();
} }
else else
{ {

Loading…
Cancel
Save