Skip to main content

uiautomator_cli/
cli.rs

1//! CLI 命令行接口定义
2//!
3//! 使用 clap 库定义命令行参数和子命令
4
5use clap::{Parser, Subcommand};
6
7/// uiautomator CLI 工具
8/// # Examples
9///
10/// ```
11/// use clap::Parser;
12/// use uiautomator_cli::cli::{Cli, Commands};
13///
14/// let cli = Cli::parse_from(["uiautomator", "--serial", "emulator-5554", "status"]);
15/// assert_eq!(cli.serial.as_deref(), Some("emulator-5554"));
16/// assert!(matches!(cli.command, Commands::Status));
17/// ```
18#[derive(Parser, Debug)]
19#[command(name = "uiautomator")]
20#[command(version)]
21#[command(about = "Android UI 自动化工具 - ATX-Agent 管理器", long_about = None)]
22pub struct Cli {
23    /// 设备序列号(可选,默认使用第一个连接的设备)
24    #[arg(short, long, global = true)]
25    pub serial: Option<String>,
26
27    /// 子命令
28    #[command(subcommand)]
29    pub command: Commands,
30}
31
32/// 可用的子命令
33/// # Examples
34///
35/// ```
36/// use clap::Parser;
37/// use uiautomator_cli::cli::{Cli, Commands};
38///
39/// let cli = Cli::parse_from(["uiautomator", "init", "--force"]);
40/// assert!(matches!(cli.command, Commands::Init { force: true }));
41/// ```
42#[derive(Subcommand, Debug)]
43pub enum Commands {
44    /// 初始化设备(安装并启动 ATX-Agent)
45    Init {
46        /// 强制重新安装(即使已安装)
47        #[arg(short, long)]
48        force: bool,
49    },
50
51    /// 查看 ATX-Agent 状态
52    Status,
53
54    /// 重启 ATX-Agent 服务
55    Restart,
56
57    /// 卸载 ATX-Agent
58    Uninstall,
59
60    /// 显示版本信息
61    Version,
62}