use crate::errors::*;
use std::io::stdout;
use std::path::PathBuf;
use structopt::StructOpt;
use structopt::clap::{AppSettings, Shell};
#[derive(Debug, StructOpt)]
#[structopt(global_settings = &[AppSettings::ColoredHelp])]
pub struct Args {
#[structopt(short="v", long="verbose",
global=true, parse(from_occurrences))]
pub verbose: u8,
#[structopt(short = "n", long = "workers", default_value = "16")]
pub workers: usize,
#[structopt(short = "o", long = "output")]
pub output: Option<String>,
#[structopt(subcommand)]
pub subcommand: SubCommand,
}
#[derive(Debug, StructOpt)]
pub enum SubCommand {
Dict(Dict),
Combo(Combo),
Enum(Enum),
Run(Run),
Fsck(Fsck),
Completions(Completions),
}
#[derive(Debug, StructOpt)]
pub struct Dict {
pub users_path: PathBuf,
pub passwords_path: PathBuf,
#[structopt(required=true)]
pub scripts: Vec<String>,
}
#[derive(Debug, StructOpt)]
pub struct Combo {
pub path: PathBuf,
#[structopt(required=true)]
pub scripts: Vec<String>,
}
#[derive(Debug, StructOpt)]
pub struct Enum {
pub users: String,
#[structopt(required=true)]
pub scripts: Vec<String>,
}
#[derive(Debug, StructOpt)]
pub struct Run {
pub script: String,
pub user: String,
pub password: Option<String>,
#[structopt(short = "x", long = "exitcode")]
pub exitcode: bool,
}
#[derive(Debug, StructOpt)]
pub struct Fsck {
#[structopt(short = "q", long = "quiet")]
pub quiet: bool,
#[structopt(short = "s", long = "silent")]
pub silent: bool,
#[structopt(short = "c", long = "colon")]
pub require_colon: bool,
pub paths: Vec<String>,
}
#[derive(Debug, StructOpt)]
pub struct Completions {
#[structopt(possible_values=&Shell::variants())]
pub shell: Shell,
}
impl Completions {
pub fn gen(&self) -> Result<()> {
Args::clap().gen_completions_to("authoscope", self.shell, &mut stdout());
Ok(())
}
}