From 81291e0655be268dd2abfd0d68cf3b9ec68d0cf9 Mon Sep 17 00:00:00 2001 From: Angel J <78835633+iamanaws@users.noreply.github.com> Date: Wed, 17 Jun 2026 22:14:41 -0700 Subject: [PATCH] fix(cli): avoid duplicate error output --- crates/uad-cli/src/commands.rs | 14 ++++---------- crates/uad-cli/src/device.rs | 6 ++++-- crates/uad-cli/src/main.rs | 13 ++++++++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/uad-cli/src/commands.rs b/crates/uad-cli/src/commands.rs index 25b5bc0..62286bd 100644 --- a/crates/uad-cli/src/commands.rs +++ b/crates/uad-cli/src/commands.rs @@ -10,7 +10,7 @@ use uad_core::sync::{ use uad_core::uad_lists::{Package, PackageState, Removal, UadList, load_debloat_lists}; use uad_core::utils::{matches_search, truncate_description}; -use crate::device::{get_target_device, get_user}; +use crate::device::{NO_DEVICES_FOUND, get_target_device, get_user}; use crate::filters::{ListFilter, RemovalFilter, StateFilter}; use crate::{Cli, print_or_exit, println_or_exit}; @@ -20,8 +20,7 @@ pub fn list_devices() -> Result<(), Box> { let devices = get_devices_list(); if devices.is_empty() { - eprintln!("No devices found. Make sure ADB is installed and devices are connected."); - return Err("No devices found".into()); + return Err(NO_DEVICES_FOUND.into()); } println_or_exit!("\nFound {} device(s):\n", devices.len()); @@ -250,7 +249,6 @@ pub fn change_package_state( action_name: &str, ) -> Result<(), Box> { if packages.is_empty() { - eprintln!("Error: No packages specified"); return Err("No packages specified".into()); } @@ -365,8 +363,7 @@ pub fn execute_with_fallback( match run_adb_shell_action(&device.adb_id, cmd.as_str()) { Ok(_) => println!("{}✓ {}", indent, cmd), Err(e) => { - eprintln!("{}✗ Failed: {:?}", indent, e); - return Err(format!("Failed to execute: {}", cmd).into()); + return Err(format!("{indent}✗ Failed to execute `{cmd}`: {e:?}").into()); } } } @@ -461,10 +458,7 @@ pub fn update_lists() -> Result<(), Box> { println!("✓ Successfully updated package lists"); Ok(()) } - Err(_lists) => { - eprintln!("✗ Failed to update lists from remote, using cached version"); - Err("Failed to update lists".into()) - } + Err(_lists) => Err("Failed to update lists from remote, using cached version".into()), } } diff --git a/crates/uad-cli/src/device.rs b/crates/uad-cli/src/device.rs index ddc23a9..54fee8c 100644 --- a/crates/uad-cli/src/device.rs +++ b/crates/uad-cli/src/device.rs @@ -1,12 +1,14 @@ use uad_core::sync::{Phone, User, get_devices_list}; +pub const NO_DEVICES_FOUND: &str = + "No devices found. Make sure ADB is installed and devices are connected."; + /// Get target device, either by serial or first available pub fn get_target_device(device: Option) -> Result> { let devices = get_devices_list(); if devices.is_empty() { - eprintln!("Error: No devices found"); - return Err("No devices found".into()); + return Err(NO_DEVICES_FOUND.into()); } let target_device = if let Some(device_id) = device { diff --git a/crates/uad-cli/src/main.rs b/crates/uad-cli/src/main.rs index d2e4bd4..f473e28 100644 --- a/crates/uad-cli/src/main.rs +++ b/crates/uad-cli/src/main.rs @@ -9,6 +9,7 @@ use clap::{Parser, Subcommand}; use clap_complete::Shell; +use std::process::ExitCode; use uad_core::uad_lists::PackageState; mod commands; @@ -156,7 +157,17 @@ enum Commands { } #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> ExitCode { + match run() { + Ok(()) => ExitCode::SUCCESS, + Err(err) => { + eprintln!("Error: {err}"); + ExitCode::FAILURE + } + } +} + +fn run() -> Result<(), Box> { let cli = Cli::parse(); match cli.command {