verified deserializing manifests

unstable
Penguin 3 years ago
parent 7633bdf878
commit 11fd986d44

@ -0,0 +1 @@
penguin@gpenguin.2954:1640039390

@ -0,0 +1 @@
penguin@gpenguin.2954:1640039390

@ -85,7 +85,7 @@ pub fn ia_new(igloo: &Igloo, project_name: String, initial_target: String) -> Ig
return ret return ret
} }
let created_project = match IglooProject::from_new(igloo, project_name) let prj = match IglooProject::from_new(igloo, project_name)
{ {
Ok(v) => v, Ok(v) => v,
Err(e) => Err(e) =>

@ -1,5 +1,7 @@
use crate::{PathBuf, env, UserDirs}; use crate::{PathBuf, env, UserDirs};
static PROJECT_CONFIG_FILE_NAME: &str = "igloo.toml";
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct IglooEnv pub struct IglooEnv
{ {

@ -11,48 +11,53 @@ use crate::IglooType;
use crate::IglooType::*; use crate::IglooType::*;
use crate::igloo_target::IglooTarget; use crate::igloo_target::IglooTarget;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use config::Config; use config::Config;
#[derive(Serialize, Deserialize, Debug)] /// IglooTargetManifest - a manifest file locations which contain each target's
pub struct IglooProjectManifest /// settings and configuration properties
#[derive(Serialize,Deserialize,Debug)]
pub struct IglooTargetManifest
{ {
name: String, targets: HashMap::<String, String>,
targets: Vec::<String>
} }
impl IglooProjectManifest #[derive(Serialize,Deserialize,Debug)]
pub struct IglooMakeManifest
{ {
pub fn default() -> IglooProjectManifest
}
impl IglooTargetManifest
{
pub fn default() -> IglooTargetManifest
{ {
IglooProjectManifest IglooTargetManifest
{ {
name: String::from(""), targets: HashMap::new(),
targets: Vec::default(),
} }
} }
pub fn from_project_file(self, igloo: &Igloo) -> Result<IglooProjectManifest, IglooStatus> pub fn get(igloo: &Igloo) -> Result<IglooTargetManifest, IglooStatus>
{ {
let mut config = config::Config::default(); let mut target_manifest = config::Config::default();
config.merge( target_manifest.merge(
config::File::with_name( config::File::with_name(
igloo.env igloo.env
.cwd .esfd
.clone() .clone()
.join("igloo.toml") .join("manifest")
.to_str().unwrap())).unwrap(); .join("target-manifest.toml")
.to_str().unwrap()
let z = config.deserialize::<IglooProjectManifest>().unwrap(); )).unwrap();
println!("{:?}", z); let ret = target_manifest.try_into::<IglooTargetManifest>().unwrap();
println!("{:?}", ret);
Ok(IglooProjectManifest::default()) println!("{:?}", ret.targets["samd21j18a"]);
Ok(IglooTargetManifest::default())
} }
}
impl IglooMakeManifest
{
pub fn to_project_file(self, igloo: &Igloo) -> IglooStatus
{
IglooStatus::IS_GOOD
}
} }

@ -9,11 +9,84 @@ use crate::IglooStatus::*;
use crate::igloo_target::IglooTarget; use crate::igloo_target::IglooTarget;
use serde::{Serialize, Deserialize};
use config::Config;
#[derive(Serialize, Deserialize, Debug)]
pub struct Settings
{
testvar: String,
profile: Profile,
}
/// Basic profile settings
#[derive(Serialize, Deserialize, Debug)]
struct Profile
{
name: String,
targets: Vec::<String>
}
impl Profile
{
fn default() -> Profile
{
Profile
{
name: String::new(),
targets: Vec::new(),
}
}
}
impl Settings
{
pub fn default() -> Settings
{
Settings
{
testvar: String::new(),
profile: Profile::default(),
}
}
pub fn from_project_file(self, igloo: &Igloo) -> Result<Settings, IglooStatus>
{
let mut config = config::Config::default();
config.merge(
config::File::with_name(
igloo.env
.cwd
.clone()
.join("test")
.join("igloo.toml")
.to_str().unwrap())).unwrap();
let x = config.try_into::<Settings>().unwrap();
println!("{:?}", x);
Ok(x)
}
pub fn to_project_file(self, igloo: &Igloo) -> IglooStatus
{
IglooStatus::IS_GOOD
}
pub fn set_profile_name(&mut self, name: String)
{
self.profile.name = name;
}
pub fn add_target(&mut self, target_name: String)
{
self.profile.targets.push(target_name);
}
}
pub struct IglooProject<'a> pub struct IglooProject<'a>
{ {
igloo: &'a Igloo, igloo: &'a Igloo,
name: String, config: Settings,
targets: Vec<IglooTarget>,
} }
impl<'a> IglooProject<'a> impl<'a> IglooProject<'a>
@ -23,36 +96,33 @@ impl<'a> IglooProject<'a>
IglooProject IglooProject
{ {
igloo: igloo_in, igloo: igloo_in,
name: String::new(), config: Settings::default(),
targets: Vec::default(),
} }
} }
/// Used to populate an IglooProject from scratch /// Used to populate an IglooProject from scratch
/// This means we do not yet have any project in storage /// This takes input from cli and generates the project in memory
/// and we must generate those directories, files, and symlinks
/// and then populate the project in memory
pub fn from_new(igloo_in: &'a Igloo, project_name: String) -> Result<IglooProject, IglooStatus> pub fn from_new(igloo_in: &'a Igloo, project_name: String) -> Result<IglooProject, IglooStatus>
{ {
let mut settings = Settings::default();
settings.set_profile_name(project_name);
Ok(IglooProject Ok(IglooProject
{ {
name: ich_new_get_project_name(igloo_in),
/// targets -- a vector of targets added for this project
targets: Vec::default(),
igloo: igloo_in, igloo: igloo_in,
config: settings,
}) })
} }
/// Used to populate an IglooProject from an existing project /// Used to create an IglooProject from an existing project
/// So this will be called when things like /// So this will be called when things like
/// igloo run, push, pull, erase, etc... are called /// igloo run, push, pull, erase, etc... are called
pub fn from_existing(igloo: &'a Igloo) -> IglooProject pub fn from_existing(igloo_in: &'a Igloo) -> Result<IglooProject, IglooStatus>
{ {
IglooProject::default(igloo) Ok(IglooProject
{
igloo: igloo_in,
config: Settings::default().from_project_file(igloo_in).unwrap(),
})
} }
pub fn is_igloo_prj(path: &std::path::PathBuf) -> bool pub fn is_igloo_prj(path: &std::path::PathBuf) -> bool
@ -68,4 +138,18 @@ impl<'a> IglooProject<'a>
} }
return true return true
} }
/// creates project files
/// including igloo.toml
pub fn generate(self) -> IglooStatus
{
IglooStatus::IS_GOOD
}
pub fn add_target(&mut self, target: String) -> IglooStatus
{
let mut ret = IS_GOOD;
self.config.add_target(target);
ret
}
} }

@ -19,6 +19,7 @@ mod igloo_env;
use igloo_cli::IglooCliInfo; use igloo_cli::IglooCliInfo;
use igloo_env::IglooEnv; use igloo_env::IglooEnv;
use igloo_project::IglooProject; use igloo_project::IglooProject;
use igloo_manifest::IglooTargetManifest;
#[derive(Debug)] #[derive(Debug)]
#[derive(PartialEq)] #[derive(PartialEq)]
@ -61,6 +62,7 @@ use IglooType::*;
pub struct Igloo pub struct Igloo
{ {
master_target_manifest: IglooTargetManifest,
cli_info: IglooCliInfo, cli_info: IglooCliInfo,
env: IglooEnv, env: IglooEnv,
} }
@ -73,6 +75,7 @@ impl Igloo
{ {
cli_info: IglooCliInfo::new(), cli_info: IglooCliInfo::new(),
env: IglooEnv::get_env(), env: IglooEnv::get_env(),
master_target_manifest: IglooTargetManifest::default(),
} }
} }
@ -80,6 +83,8 @@ impl Igloo
{ {
let mut res: IglooType = IT_NULL; let mut res: IglooType = IT_NULL;
// get master target manifest
self.master_target_manifest = IglooTargetManifest::get(self).unwrap();
// Assign instance type (new, run, push, etc) // Assign instance type (new, run, push, etc)
igloo_action::igloo_subcommand(&self.cli_info.raw) igloo_action::igloo_subcommand(&self.cli_info.raw)
} }

@ -0,0 +1,4 @@
testvar = "djskaddfjlka"
[profile]
name = "myproject"
targets = ["samd21j18a"]
Loading…
Cancel
Save