From 972271288d512d9381a9dcc3eb1452d7f86c3da0 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 8 Oct 2024 11:06:30 +0200 Subject: [PATCH] feat: Add an argument for template mode --- .github/workflows/ci.yml | 2 +- src/main.rs | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 603b9e4..23a32fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,10 +42,10 @@ jobs: ] options: [ "", + "--template embassy", "-o alloc", "-o wifi -o alloc", "-o ble -o alloc", - "-o embassy", "-o probe-rs", "-o stack-protector" ] diff --git a/src/main.rs b/src/main.rs index def5926..eab4852 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,13 +92,6 @@ static OPTIONS: &[GeneratorOptionItem] = &[ Chip::Esp32H2, ], }), - GeneratorOptionItem::Option(GeneratorOption { - name: "embassy", - display_name: "Embassy", - enables: &[], - disables: &[], - chips: &[], - }), GeneratorOptionItem::Option(GeneratorOption { name: "probe-rs", display_name: "Flash via probe-rs, use defmt", @@ -164,6 +157,24 @@ static CHIP_VARS: &[(Chip, &[(&str, &str)])] = &[ ), ]; +#[derive(Clone, Copy, Debug, PartialEq, ValueEnum, Default)] +#[value(rename_all = "LOWER_CASE")] +pub enum Template { + #[default] + Blocking, + Embassy, +} + +impl std::fmt::Display for Template { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let template = match self { + Template::Blocking => "blocking", + Template::Embassy => "embassy", + }; + write!(f, "{}", template) + } +} + #[derive(Clone, Copy, Debug, PartialEq, ValueEnum)] #[value(rename_all = "LOWER_CASE")] pub enum Chip { @@ -204,15 +215,23 @@ impl Chip { #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { + /// Name of the project name: String, #[arg(short, long)] + /// Target chip chip: Chip, - #[arg(long)] + #[arg(short, long, default_value = "blocking")] + /// Template to use. + template: Template, + + #[arg(short, long)] + /// Run in headless mode headless: bool, #[arg(short, long)] + /// Options to enable option: Vec, } @@ -246,7 +265,9 @@ fn main() { } else { args.option.clone() }; - + // Add the template to the selected options + selected.push(args.template.to_string()); + // Add the architecture to the selected options selected.push(args.chip.architecture_name()); let mut variables = vec![