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:
33
src/main.rs
33
src/main.rs
@@ -31,9 +31,17 @@ enum Commands {
|
||||
#[arg(long, short = 't', value_name = "TEMPLATE")]
|
||||
template: Option<String>,
|
||||
|
||||
/// Board preset (uno, mega, nano, leonardo, micro)
|
||||
#[arg(long, short = 'b', value_name = "BOARD")]
|
||||
board: Option<String>,
|
||||
|
||||
/// List available templates
|
||||
#[arg(long, conflicts_with = "name")]
|
||||
list_templates: bool,
|
||||
|
||||
/// List available board presets
|
||||
#[arg(long, conflicts_with = "name")]
|
||||
list_boards: bool,
|
||||
},
|
||||
|
||||
/// Check system health and diagnose issues
|
||||
@@ -45,13 +53,17 @@ enum Commands {
|
||||
/// List connected boards and serial ports
|
||||
Devices {
|
||||
/// Save a port to .anvil.local for this project
|
||||
#[arg(long, conflicts_with = "get")]
|
||||
#[arg(long, conflicts_with_all = ["get", "clear"])]
|
||||
set: bool,
|
||||
|
||||
/// Show the saved port for this project
|
||||
#[arg(long, conflicts_with = "set")]
|
||||
#[arg(long, conflicts_with_all = ["set", "clear"])]
|
||||
get: bool,
|
||||
|
||||
/// Remove .anvil.local (revert to auto-detect)
|
||||
#[arg(long, conflicts_with_all = ["set", "get"])]
|
||||
clear: bool,
|
||||
|
||||
/// Port name (e.g. COM3, /dev/ttyUSB0). Auto-detects if omitted with --set.
|
||||
port_or_dir: Option<String>,
|
||||
|
||||
@@ -80,18 +92,23 @@ fn main() -> Result<()> {
|
||||
print_banner();
|
||||
|
||||
match cli.command {
|
||||
Commands::New { name, template, list_templates } => {
|
||||
if list_templates {
|
||||
Commands::New { name, template, board, list_templates, list_boards } => {
|
||||
if list_boards {
|
||||
commands::new::list_boards()
|
||||
} else if list_templates {
|
||||
commands::new::list_templates()
|
||||
} else if let Some(project_name) = name {
|
||||
commands::new::create_project(
|
||||
&project_name,
|
||||
template.as_deref(),
|
||||
board.as_deref(),
|
||||
)
|
||||
} else {
|
||||
anyhow::bail!(
|
||||
"Project name required.\n\
|
||||
Usage: anvil new <n>\n\
|
||||
Usage: anvil new <name>\n\
|
||||
Usage: anvil new <name> --board mega\n\
|
||||
List boards: anvil new --list-boards\n\
|
||||
List templates: anvil new --list-templates"
|
||||
);
|
||||
}
|
||||
@@ -102,7 +119,7 @@ fn main() -> Result<()> {
|
||||
Commands::Setup => {
|
||||
commands::setup::run_setup()
|
||||
}
|
||||
Commands::Devices { set, get, port_or_dir, dir } => {
|
||||
Commands::Devices { set, get, clear, port_or_dir, dir } => {
|
||||
if set {
|
||||
commands::devices::set_port(
|
||||
port_or_dir.as_deref(),
|
||||
@@ -112,6 +129,10 @@ fn main() -> Result<()> {
|
||||
commands::devices::get_port(
|
||||
dir.as_deref().or(port_or_dir.as_deref()),
|
||||
)
|
||||
} else if clear {
|
||||
commands::devices::clear_port(
|
||||
dir.as_deref().or(port_or_dir.as_deref()),
|
||||
)
|
||||
} else {
|
||||
commands::devices::scan_devices()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user