added some subcommands

unstable
penguin 4 years ago
parent cb86cecfd7
commit 9ea2390078

@ -0,0 +1 @@
penguin@penguin-arch-home.18919:1598019580

@ -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<IglooInstType, String>
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")
.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<String, String>

@ -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,8 +11,8 @@ 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),
}

Loading…
Cancel
Save