From 9ea23900787578359cc4e0092e0bfd160ea24275 Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 21 Aug 2020 17:21:23 -0500 Subject: [PATCH] added some subcommands --- src/.#igloo.rs | 1 + src/igloo.rs | 88 +++++++++++++++++++++++++++++++++++++++++++++++--- src/main.rs | 8 ++--- 3 files changed, 89 insertions(+), 8 deletions(-) create mode 120000 src/.#igloo.rs diff --git a/src/.#igloo.rs b/src/.#igloo.rs new file mode 120000 index 0000000..0f63bda --- /dev/null +++ b/src/.#igloo.rs @@ -0,0 +1 @@ +penguin@penguin-arch-home.18919:1598019580 \ No newline at end of file diff --git a/src/igloo.rs b/src/igloo.rs index 1052fcc..08640b2 100644 --- a/src/igloo.rs +++ b/src/igloo.rs @@ -1,4 +1,5 @@ #[derive(Debug)] +#[derive(PartialEq)] pub enum IglooInstType { IGLOO_NULL = -1, @@ -7,9 +8,18 @@ pub enum IglooInstType IGLOO_FLASH = 2, IGLOO_DEBUG = 3, IGLOO_CLEAN = 4, - IGLOO_GENDOC = 5 + IGLOO_ERASE = 5, + IGLOO_GENDOC = 6, } +#[derive(Debug)] +#[derive(PartialEq)] +pub enum IglooErrType +{ + IGLOO_ERR_UNKNOWN = 0, + IGLOO_CONFIG_NOT_FOUND = 1, + IGLOO_CONFIG_FOUND = 2, +} pub struct Igloo { @@ -28,14 +38,84 @@ impl Igloo } } - pub fn start(&self) -> Result + pub fn start(&self) -> Result { + let mut res_error = IglooErrType::IGLOO_ERR_UNKNOWN; + let mut res_type = IglooInstType::IGLOO_NULL; let matches = clap::App::new("igloo") .about(clap::crate_description!()) .version(clap::crate_version!()) - .get_matches(); + .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(); - Ok(IglooInstType::IGLOO_NULL) + match matches.subcommand_name() + { + Some("new") => + { + println!("Igloo new was called!"); + res_type = IglooInstType::IGLOO_NEW; + } + Some("run") => + { + println!("Igloo run was called!"); + res_type = IglooInstType::IGLOO_RUN; + } + Some("flash") => + { + println!("Igloo flash was called!"); + res_type = IglooInstType::IGLOO_FLASH; + } + Some("erase") => + { + println!("Igloo erase was called!"); + res_type = IglooInstType::IGLOO_ERASE; + } + None => unreachable!(), + _ => unreachable!(), + } + if res_type != IglooInstType::IGLOO_NULL + { + Ok(res_type) + } + else + { + Err(res_error) + } } pub fn run(&self) -> Result diff --git a/src/main.rs b/src/main.rs index 1da528e..d5db4fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ extern crate clap; extern crate config; mod igloo; -use clap::{crate_version, crate_description, crate_authors, App, Arg}; +use clap::{crate_version, crate_description, crate_authors, App, Arg, AppSettings}; use config::*; use std::collections::HashMap; @@ -11,9 +11,9 @@ fn main() let ig = igloo::Igloo::New(); match ig.start() { - Ok(d) => println!("{:?}", d), - Err(_) => panic!("FUCK"), + Ok(d) => println!("Ok: {:?}", d), + Err(e) => println!("Error: {:?}", e), } - + }