libredefender 0.6.0

Light-weight antivirus scanner for Linux
use crate::errors::*;
use std::io::stdout;
use std::path::PathBuf;
use structopt::clap::{AppSettings, Shell};
use structopt::StructOpt;

#[derive(StructOpt)]
#[structopt(global_settings = &[AppSettings::ColoredHelp])]
pub struct Args {
    /// Only show warnings
    #[structopt(short, long, global = true)]
    pub quiet: bool,
    /// More verbose logs
    #[structopt(short, long, global = true, parse(from_occurrences))]
    pub verbose: u8,
    #[structopt(short = "C", long, global = true)]
    pub colors: bool,
    #[structopt(short = "D", long, global = true)]
    pub data: Option<PathBuf>,
    #[structopt(subcommand)]
    pub subcommand: Option<SubCommand>,
}

#[derive(StructOpt)]
pub enum SubCommand {
    /// Scan directories for signature matches
    Scan(Scan),
    /// Run a background service that scans periodically
    Scheduler(Scheduler),
    /// List threats that have been detected
    Infections(Infections),
    /// Send a test notification
    TestNotify,
    /// Load the configuration and print it as json for debugging
    DumpConfig,
    /// Generate shell completions
    Completions(Completions),
}

#[derive(StructOpt, Default)]
pub struct Scan {
    /// Paths that should be scanned
    pub paths: Vec<PathBuf>,
    /// Configure the number of scanning threads, defaults to number of cpu cores
    #[structopt(short = "j", long)]
    pub concurrency: Option<usize>,
}

#[derive(StructOpt)]
pub struct Scheduler {}

#[derive(StructOpt)]
pub struct Infections {
    /// Interactively offer deletion for every file
    #[structopt(short, long, group = "action")]
    pub delete: bool,
    /// Delete all files without further confirmation (DANGER!)
    #[structopt(long, group = "action")]
    pub delete_all: bool,
}

#[derive(Debug, Clone, StructOpt)]
pub struct Completions {
    #[structopt(possible_values=&Shell::variants())]
    pub shell: Shell,
}

impl Completions {
    pub fn gen_completions(&self) -> Result<()> {
        Args::clap().gen_completions_to("libredefender", self.shell, &mut stdout());
        Ok(())
    }
}