spytrap_adb/
args.rs

1use crate::errors::*;
2use clap::{ArgAction, CommandFactory, Parser};
3use clap_complete::Shell;
4use std::io::stdout;
5use std::path::PathBuf;
6
7#[derive(Debug, Parser)]
8#[command(version)]
9pub struct Args {
10    /// More verbose logs
11    #[arg(short, long, global = true, action(ArgAction::Count))]
12    pub verbose: u8,
13    /// Configure if an adb server should be started if needed
14    #[arg(
15        long,
16        global = true,
17        value_name = "choice",
18        env = "SPYTRAP_START_ADB_SERVER",
19        default_value = "auto"
20    )]
21    pub start_adb_server: AdbServerChoice,
22    #[command(subcommand)]
23    pub subcommand: Option<SubCommand>,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
27pub enum AdbServerChoice {
28    Auto,
29    Always,
30    Never,
31}
32
33#[derive(Debug, Parser)]
34pub enum SubCommand {
35    Scan(Scan),
36    List(List),
37    DownloadIoc(DownloadIoc),
38    Completions(Completions),
39}
40
41/// Run a scan on a given device
42#[derive(Debug, Parser)]
43pub struct Scan {
44    pub serial: Option<String>,
45    /// Use specific rule files instead of latest downloaded
46    #[arg(long)]
47    pub rules: Vec<PathBuf>,
48    #[arg(long)]
49    pub test_load_only: bool,
50    /// Do not scan apps for suspicious permissions
51    #[arg(long)]
52    pub skip_apps: bool,
53}
54
55/// List all available devices
56#[derive(Debug, Parser)]
57pub struct List {}
58
59/// Download the latest version of stalkerware-indicators ioc.yaml
60#[derive(Debug, Parser)]
61pub struct DownloadIoc {}
62
63/// Generate shell completions
64#[derive(Debug, Parser)]
65pub struct Completions {
66    pub shell: Shell,
67}
68
69impl Completions {
70    pub fn generate(&self) -> Result<()> {
71        clap_complete::generate(
72            self.shell,
73            &mut Args::command(),
74            "spytrap-adb",
75            &mut stdout(),
76        );
77        Ok(())
78    }
79}