verified deserializing manifests

unstable
Penguin 2 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
}
let created_project = match IglooProject::from_new(igloo, project_name)
let prj = match IglooProject::from_new(igloo, project_name)
{
Ok(v) => v,
Err(e) =>

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

@ -11,48 +11,53 @@ use crate::IglooType;
use crate::IglooType::*;
use crate::igloo_target::IglooTarget;
use serde::{Serialize, Deserialize};
use config::Config;
#[derive(Serialize, Deserialize, Debug)]
pub struct IglooProjectManifest
/// IglooTargetManifest - a manifest file locations which contain each target's
/// settings and configuration properties
#[derive(Serialize,Deserialize,Debug)]
pub struct IglooTargetManifest
{
name: String,
targets: Vec::<String>
targets: HashMap::<String, 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: Vec::default(),
targets: HashMap::new(),
}
}
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();
config.merge(
let mut target_manifest = config::Config::default();
target_manifest.merge(
config::File::with_name(
igloo.env
.cwd
.esfd
.clone()
.join("igloo.toml")
.to_str().unwrap())).unwrap();
let z = config.deserialize::<IglooProjectManifest>().unwrap();
println!("{:?}", z);
Ok(IglooProjectManifest::default())
.join("manifest")
.join("target-manifest.toml")
.to_str().unwrap()
)).unwrap();
let ret = target_manifest.try_into::<IglooTargetManifest>().unwrap();
println!("{:?}", ret);
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 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>
{
igloo: &'a Igloo,
name: String,
targets: Vec<IglooTarget>,
config: Settings,
}
impl<'a> IglooProject<'a>
@ -23,36 +96,33 @@ impl<'a> IglooProject<'a>
IglooProject
{
igloo: igloo_in,
name: String::new(),
targets: Vec::default(),
config: Settings::default(),
}
}
/// Used to populate an IglooProject from scratch
/// This means we do not yet have any project in storage
/// and we must generate those directories, files, and symlinks
/// and then populate the project in memory
/// This takes input from cli and generates the project in memory
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
{
name: ich_new_get_project_name(igloo_in),
/// targets -- a vector of targets added for this project
targets: Vec::default(),
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
/// 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
@ -68,4 +138,18 @@ impl<'a> IglooProject<'a>
}
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_env::IglooEnv;
use igloo_project::IglooProject;
use igloo_manifest::IglooTargetManifest;
#[derive(Debug)]
#[derive(PartialEq)]
@ -61,6 +62,7 @@ use IglooType::*;
pub struct Igloo
{
master_target_manifest: IglooTargetManifest,
cli_info: IglooCliInfo,
env: IglooEnv,
}
@ -73,6 +75,7 @@ impl Igloo
{
cli_info: IglooCliInfo::new(),
env: IglooEnv::get_env(),
master_target_manifest: IglooTargetManifest::default(),
}
}
@ -80,6 +83,8 @@ impl Igloo
{
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)
igloo_action::igloo_subcommand(&self.cli_info.raw)
}

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