From ced913495a8ac2214407de093622b24b83a5b6a3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 21 Dec 2023 14:23:37 +0900 Subject: [PATCH] guest_rust: if --list-sensors option is specified, only print the list --- guest_rust/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/guest_rust/src/lib.rs b/guest_rust/src/lib.rs index 9ecc938..172aae6 100644 --- a/guest_rust/src/lib.rs +++ b/guest_rust/src/lib.rs @@ -158,6 +158,7 @@ fn process_frame(frame: &wasi::buffer_pool::buffer_pool::FrameInfo) -> Result<() fn main2() -> Result<()> { let args: Vec = env::args().collect(); let mut opts = Options::new(); + opts.optflag("", "list-sensors", "list sensor names"); opts.optopt("", "pool", "pool name", "POOL"); opts.optopt("", "sensor", "device name", "DEVICE"); opts.optopt("", "sampling-rate", "samples per sec", "RATE"); @@ -168,6 +169,11 @@ fn main2() -> Result<()> { return Err(f.into()); } }; + if matches.opt_present("list-sensors") { + let device_names = wasi::sensor::sensor::Device::list_names()?; + println!("available devices: {:?}", device_names); + return Ok(()); + } let pool_name = matches.opt_str("pool").unwrap_or("my-pool".to_string()); let device_name = matches .opt_str("sensor") @@ -185,9 +191,6 @@ fn main2() -> Result<()> { &pool_name, )?; - let device_names = wasi::sensor::sensor::Device::list_names()?; - println!("available devices: {:?}", device_names); - let sensor = wasi::sensor::sensor::Device::open(&device_name)?; println!("opened sensor {:?}", sensor);