Skip to content

Commit

Permalink
feat: implement the devices command
Browse files Browse the repository at this point in the history
  • Loading branch information
SyedAhkam committed Aug 21, 2023
1 parent 4bb6c45 commit 5c863c9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/commands/devices.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod create;
pub mod install;
pub mod run;
pub mod launch;
pub mod devices;
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ pub fn launch_activity(package_id: String, activity_name: String) -> Result<Exit
])
.context("failed to invoke adb command")?)
}

pub fn query_devices() -> Result<ExitStatus> {
Ok(invoke_adb_command(&["devices"]).context("failed to invoke adb command")?)
}
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 5c863c9

Please sign in to comment.