Add board presets, devices --clear, and test/UX fixes
Board presets: - anvil new --board mega (uno, mega, nano, nano-old, leonardo, micro) - anvil new --list-boards shows presets with compatible clones - FQBN and baud rate flow into .anvil.toml via template variables - Defaults to uno when --board is omitted Devices --clear: - anvil devices --clear deletes .anvil.local, reverts to auto-detect
This commit is contained in:
@@ -10,6 +10,8 @@ static BASIC_TEMPLATE: Dir = include_dir!("$CARGO_MANIFEST_DIR/templates/basic")
|
||||
pub struct TemplateContext {
|
||||
pub project_name: String,
|
||||
pub anvil_version: String,
|
||||
pub fqbn: String,
|
||||
pub baud: u32,
|
||||
}
|
||||
|
||||
pub struct TemplateManager;
|
||||
@@ -140,6 +142,8 @@ fn substitute_variables(text: &str, context: &TemplateContext) -> String {
|
||||
text.replace("{{PROJECT_NAME}}", &context.project_name)
|
||||
.replace("{{ANVIL_VERSION}}", &context.anvil_version)
|
||||
.replace("{{ANVIL_VERSION_CURRENT}}", ANVIL_VERSION)
|
||||
.replace("{{FQBN}}", &context.fqbn)
|
||||
.replace("{{BAUD}}", &context.baud.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -172,10 +176,15 @@ mod tests {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "my_project".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:mega:cpu=atmega2560".to_string(),
|
||||
baud: 9600,
|
||||
};
|
||||
let input = "Name: {{PROJECT_NAME}}, Version: {{ANVIL_VERSION}}";
|
||||
let input = "Name: {{PROJECT_NAME}}, Version: {{ANVIL_VERSION}}, FQBN: {{FQBN}}, Baud: {{BAUD}}";
|
||||
let output = substitute_variables(input, &ctx);
|
||||
assert_eq!(output, "Name: my_project, Version: 1.0.0");
|
||||
assert_eq!(
|
||||
output,
|
||||
"Name: my_project, Version: 1.0.0, FQBN: arduino:avr:mega:cpu=atmega2560, Baud: 9600"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -190,6 +199,8 @@ mod tests {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "test_proj".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
let count = TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -220,6 +231,8 @@ mod tests {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "my_sensor".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -231,4 +244,4 @@ mod tests {
|
||||
".anvil.toml should contain project name"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user