|
|
|
@ -16,33 +16,40 @@ pub enum IglooInstType
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
|
pub enum IglooErrType
|
|
|
|
|
{
|
|
|
|
|
IGLOO_ERR_UNKNOWN = 0,
|
|
|
|
|
IGLOO_CONFIG_NOT_FOUND = 1,
|
|
|
|
|
IGLOO_CONFIG_FOUND = 2,
|
|
|
|
|
IGLOO_ERR_NONE = 0,
|
|
|
|
|
IGLOO_ERR_UNKNOWN = 1,
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
inst_type: IglooInstType,
|
|
|
|
|
conf: config::Config,
|
|
|
|
|
cli_conf: clap::ArgMatches,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
Igloo
|
|
|
|
|
{
|
|
|
|
|
inst_type: IglooInstType::IGLOO_NULL,
|
|
|
|
|
conf: config::Config::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn start(&self) -> Result<IglooInstType, IglooErrType>
|
|
|
|
|
{
|
|
|
|
|
let mut res_error = IglooErrType::IGLOO_ERR_UNKNOWN;
|
|
|
|
|
let mut res_type = IglooInstType::IGLOO_NULL;
|
|
|
|
|
let matches = clap::App::new("igloo")
|
|
|
|
|
cli_conf: clap::App::new("igloo")
|
|
|
|
|
.about(clap::crate_description!())
|
|
|
|
|
.version(clap::crate_version!())
|
|
|
|
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
|
|
|
@ -81,9 +88,22 @@ impl Igloo
|
|
|
|
|
clap::App::new("erase")
|
|
|
|
|
.about("Erases flash from target mcu or target mcus")
|
|
|
|
|
)
|
|
|
|
|
.get_matches();
|
|
|
|
|
.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>
|
|
|
|
|
{
|
|
|
|
|
let mut res_error = IGLOO_ERR_NONE;
|
|
|
|
|
let mut res_type = IGLOO_NULL;
|
|
|
|
|
|
|
|
|
|
match matches.subcommand_name()
|
|
|
|
|
match self.cli_conf.subcommand_name()
|
|
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|
{
|
|
|
|
|
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 =>
|
|
|
|
|
{
|
|
|
|
|
Ok(String::from("Hello, we are running!\n"))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
IGLOO_RUN =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
_ => println!("Stufff"),
|
|
|
|
|
} break; }
|
|
|
|
|
if res_err == IGLOO_ERR_NONE
|
|
|
|
|
{
|
|
|
|
|
Ok(String::from("We won!"))
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Err(res_err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|