use crate::errors::*;
use clap::{ArgAction, CommandFactory, Parser};
use clap_complete::Shell;
use std::io::stdout;
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(version)]
pub struct Args {
#[arg(short, long, global = true, action(ArgAction::Count))]
pub verbose: u8,
#[arg(
long,
global = true,
value_name = "choice",
env = "SPYTRAP_START_ADB_SERVER",
default_value = "auto"
)]
pub start_adb_server: AdbServerChoice,
#[command(subcommand)]
pub subcommand: Option<SubCommand>,
}
#[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
pub enum AdbServerChoice {
Auto,
Always,
Never,
}
#[derive(Debug, Parser)]
pub enum SubCommand {
Scan(Scan),
List(List),
DownloadIoc(DownloadIoc),
Completions(Completions),
}
#[derive(Debug, Parser)]
pub struct Scan {
pub serial: Option<String>,
#[arg(long)]
pub rules: Vec<PathBuf>,
#[arg(long)]
pub test_load_only: bool,
#[arg(long)]
pub skip_apps: bool,
}
#[derive(Debug, Parser)]
pub struct List {}
#[derive(Debug, Parser)]
pub struct DownloadIoc {}
#[derive(Debug, Parser)]
pub struct Completions {
pub shell: Shell,
}
impl Completions {
pub fn generate(&self) -> Result<()> {
clap_complete::generate(
self.shell,
&mut Args::command(),
"spytrap-adb",
&mut stdout(),
);
Ok(())
}
}