added more stuff and stuff

unstable
penguin 4 years ago
parent 9ea2390078
commit 9d384adecd

@ -16,74 +16,94 @@ pub enum IglooInstType
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum IglooErrType pub enum IglooErrType
{ {
IGLOO_ERR_UNKNOWN = 0, IGLOO_ERR_NONE = 0,
IGLOO_CONFIG_NOT_FOUND = 1, IGLOO_ERR_UNKNOWN = 1,
IGLOO_CONFIG_FOUND = 2, IGLOO_CONFIG_NOT_FOUND = 2,
IGLOO_CONFIG_FOUND = 3,
IGLOO_UNKNOWN_INST_TYPE = 4,
IGLOO_NEW_CALLED_INSIDE_PRJ = 5,
} }
use IglooInstType::*;
use IglooErrType::*;
/// Igloo should contain a config and any important environment information.
/// Upon running igloo, an instanc is created, env information is stored, and then
/// things happen.
pub struct Igloo pub struct Igloo
{ {
inst_type: IglooInstType,
conf: config::Config, conf: config::Config,
cli_conf: clap::ArgMatches,
} }
impl Igloo impl Igloo
{ {
/// The New function creates an instance of igloo. The idea is I create an igloo,
/// run start on it so I can collect environment information and process what command
/// the user would like to run, and then I run that command or deal with errors.
///
/// This function handles all cli input and stores it. It is parsed for errors in the
/// start function.
pub fn New() -> Igloo pub fn New() -> Igloo
{ {
Igloo Igloo
{ {
inst_type: IglooInstType::IGLOO_NULL,
conf: config::Config::default(), conf: config::Config::default(),
cli_conf: clap::App::new("igloo")
.about(clap::crate_description!())
.version(clap::crate_version!())
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(
clap::App::new("new")
.about("Creates a new igloo project")
.arg(
clap::Arg::new("project_name")
.required(true)
.about("The name of the project to be created"),
),
)
.subcommand(
clap::App::new("run")
.about("Compiles if needed, Flashes mcu and runs current project on default target")
.arg(
clap::Arg::new("build_type")
.required(false)
.about("Release or Debug build type\nDefaults to Debug"),
),
)
.subcommand(
clap::App::new("flash")
.about("Flashes target mcu or multiple mcus")
.arg(
clap::Arg::new("build_type")
.required(false)
.about("Release or Debug build type\nDefaults to Debug"),
),
)
.subcommand(
clap::App::new("clean")
.about("Cleans project build files")
)
.subcommand(
clap::App::new("erase")
.about("Erases flash from target mcu or target mcus")
)
.get_matches()
} }
} }
/// The start function processes the command you want igloo to run
/// It theoretically should never return an error. It should just exit.
/// If an error was returned, It was my fault and not the users.
/// 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<IglooInstType, IglooErrType> pub fn start(&self) -> Result<IglooInstType, IglooErrType>
{ {
let mut res_error = IglooErrType::IGLOO_ERR_UNKNOWN; let mut res_error = IGLOO_ERR_NONE;
let mut res_type = IglooInstType::IGLOO_NULL; let mut res_type = IGLOO_NULL;
let matches = clap::App::new("igloo")
.about(clap::crate_description!()) match self.cli_conf.subcommand_name()
.version(clap::crate_version!())
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(
clap::App::new("new")
.about("Creates a new igloo project")
.arg(
clap::Arg::new("project_name")
.required(true)
.about("The name of the project to be created"),
),
)
.subcommand(
clap::App::new("run")
.about("Compiles if needed, Flashes mcu and runs current project on default target")
.arg(
clap::Arg::new("build_type")
.required(false)
.about("Release or Debug build type\nDefaults to Debug"),
),
)
.subcommand(
clap::App::new("flash")
.about("Flashes target mcu or multiple mcus")
.arg(
clap::Arg::new("build_type")
.required(false)
.about("Release or Debug build type\nDefaults to Debug"),
),
)
.subcommand(
clap::App::new("clean")
.about("Cleans project build files")
)
.subcommand(
clap::App::new("erase")
.about("Erases flash from target mcu or target mcus")
)
.get_matches();
match matches.subcommand_name()
{ {
Some("new") => Some("new") =>
{ {
@ -118,9 +138,61 @@ impl Igloo
} }
} }
pub fn run(&self) -> Result<String, String> /// The run function processes the request from the user.
/// On success, it will give some string indicating the success of the operation.
/// On failure, it will return some error type.
pub fn run(&self, inst_type: IglooInstType) -> Result<String, IglooErrType>
{ {
Ok(String::from("Hello, we are running!\n")) let mut res_err = IGLOO_ERR_NONE;
loop { match inst_type
{
IGLOO_NULL => res_err = IGLOO_ERR_UNKNOWN,
IGLOO_NEW =>
{
if let ("new", new_matches) = self.cli_conf.subcommand()
{
let prj_name: &str = new_matches.unwrap().value_of("project_name").unwrap();
// Check if we are already inside of an igloo project
// Creating an igloo project inside an igloo project
// is a no no
if std::path::Path::new(".igloo").exists()
{
res_err = IGLOO_NEW_CALLED_INSIDE_PRJ;
}
if std::path::Path::new(prj_name).exists()
{
}
}
else
{
}
}
IGLOO_FLASH =>
{
}
IGLOO_RUN =>
{
}
_ => println!("Stufff"),
} break; }
if res_err == IGLOO_ERR_NONE
{
Ok(String::from("We won!"))
}
else
{
Err(res_err)
}
} }
} }

@ -2,18 +2,24 @@ extern crate clap;
extern crate config; extern crate config;
mod igloo; mod igloo;
use clap::{crate_version, crate_description, crate_authors, App, Arg, AppSettings}; use clap::{crate_version, crate_description, crate_authors, App, Arg, AppSettings, ArgMatches};
use config::*; use config::*;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path;
fn main() fn main()
{ {
let ig = igloo::Igloo::New(); let ig = igloo::Igloo::New();
match ig.start() match ig.start()
{ {
Ok(d) => println!("Ok: {:?}", d), Ok(it) => {
match ig.run(it)
{
Ok(s) => println!("{}", s),
Err(e) => println!("Run Error: {:?}", e),
}
}
Err(e) => println!("Error: {:?}", e), Err(e) => println!("Error: {:?}", e),
} }
} }

Loading…
Cancel
Save