Improv device listing

This commit is contained in:
clerie 2025-01-01 16:28:53 +01:00
parent 197ba19520
commit b28183fd53

View File

@ -46,7 +46,7 @@ impl Default for DeviceCommands {
#[command(arg_required_else_help = true)] #[command(arg_required_else_help = true)]
enum Commands { enum Commands {
/// List available serial devices /// List available serial devices
ListDevices, List,
/// Device /// Device
Device { Device {
/// Path to the serial device /// Path to the serial device
@ -76,12 +76,13 @@ async fn main() -> Result<()>{
let command = &cli.command.context("No command provided")?.clone(); let command = &cli.command.context("No command provided")?.clone();
match &command { match &command {
Commands::ListDevices => { Commands::List => {
println!("{}", tokio_serial::available_ports() println!("{}", tokio_serial::available_ports()
.context("Failed to list available ports")? .context("Failed to list available ports")?
.iter() .iter()
.map(|serialport| serialport.port_name.clone()) .map(|serialport| serialport.port_name.clone())
.fold(String::new(), |a, b| a + &b + &String::from("\n"))); .collect::<Vec<String>>()
.join("\n"));
}, },
Commands::Device {path, baud_rate, device_command} => { Commands::Device {path, baud_rate, device_command} => {
match &device_command.clone().unwrap_or_default() { match &device_command.clone().unwrap_or_default() {