Supporting multiple boards
This commit is contained in:
@@ -10,6 +10,7 @@ static BASIC_TEMPLATE: Dir = include_dir!("$CARGO_MANIFEST_DIR/templates/basic")
|
||||
pub struct TemplateContext {
|
||||
pub project_name: String,
|
||||
pub anvil_version: String,
|
||||
pub board_name: String,
|
||||
pub fqbn: String,
|
||||
pub baud: u32,
|
||||
}
|
||||
@@ -142,6 +143,7 @@ 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("{{BOARD_NAME}}", &context.board_name)
|
||||
.replace("{{FQBN}}", &context.fqbn)
|
||||
.replace("{{BAUD}}", &context.baud.to_string())
|
||||
}
|
||||
@@ -176,14 +178,15 @@ mod tests {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "my_project".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "mega".to_string(),
|
||||
fqbn: "arduino:avr:mega:cpu=atmega2560".to_string(),
|
||||
baud: 9600,
|
||||
};
|
||||
let input = "Name: {{PROJECT_NAME}}, Version: {{ANVIL_VERSION}}, FQBN: {{FQBN}}, Baud: {{BAUD}}";
|
||||
let input = "Name: {{PROJECT_NAME}}, Board: {{BOARD_NAME}}, FQBN: {{FQBN}}, Baud: {{BAUD}}";
|
||||
let output = substitute_variables(input, &ctx);
|
||||
assert_eq!(
|
||||
output,
|
||||
"Name: my_project, Version: 1.0.0, FQBN: arduino:avr:mega:cpu=atmega2560, Baud: 9600"
|
||||
"Name: my_project, Board: mega, FQBN: arduino:avr:mega:cpu=atmega2560, Baud: 9600"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,6 +202,7 @@ mod tests {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "test_proj".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "uno".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
@@ -231,6 +235,7 @@ mod tests {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "my_sensor".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "uno".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user