From 5c863c95e60f45edfdd7421c8308d5c03e56c299 Mon Sep 17 00:00:00 2001 From: Syed Ahkam Date: Mon, 21 Aug 2023 11:40:22 +0530 Subject: [PATCH] feat: implement the devices command --- src/commands/devices.rs | 16 ++++++++++++++++ src/commands/mod.rs | 1 + src/lib.rs | 4 ++++ src/main.rs | 6 ++++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/commands/devices.rs diff --git a/src/commands/devices.rs b/src/commands/devices.rs new file mode 100644 index 0000000..6a50b0e --- /dev/null +++ b/src/commands/devices.rs @@ -0,0 +1,16 @@ +use anyhow::{bail, Result}; +use clap::Parser; + +#[derive(Parser, Debug)] +pub struct Devices {} + +pub fn handle(_args: Devices) -> Result<()> { + // Try to run adb devices + let query_status = android_cli::query_devices()?; + + if !query_status.success() { + bail!("failed to query devices"); + } + + Ok(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1a62c38..6fd47d0 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3,3 +3,4 @@ pub mod create; pub mod install; pub mod run; pub mod launch; +pub mod devices; diff --git a/src/lib.rs b/src/lib.rs index 66666c1..b21eccc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,3 +144,7 @@ pub fn launch_activity(package_id: String, activity_name: String) -> Result Result { + Ok(invoke_adb_command(&["devices"]).context("failed to invoke adb command")?) +} diff --git a/src/main.rs b/src/main.rs index 0518f45..681f775 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,8 @@ enum SubCommand { Build(commands::build::Build), Install(commands::install::Install), Run(commands::run::Run), - Launch(commands::launch::Launch) + Launch(commands::launch::Launch), + Devices(commands::devices::Devices) } fn main() { @@ -33,7 +34,8 @@ fn main() { SubCommand::Build(args) => commands::build::handle(args), SubCommand::Install(args) => commands::install::handle(args), SubCommand::Run(args) => commands::run::handle(args), - SubCommand::Launch(args) => commands::launch::handle(args) + SubCommand::Launch(args) => commands::launch::handle(args), + SubCommand::Devices(args) => commands::devices::handle(args) }; if result.is_err() {