Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an argument for template mode #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
39 changes: 30 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String>,
}

Expand Down Expand Up @@ -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![
Expand Down