#![allow(clippy::large_enum_variant)]
use rebuilderd_common::Status;
use rebuilderd_common::errors::*;
use glob::Pattern;
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, long, global = true, parse(from_occurrences))]
pub verbose: u8,
#[structopt(short="H", long)]
pub endpoint: Option<String>,
#[structopt(short, long)]
pub config: Option<PathBuf>,
#[structopt(short="C", long, global=true)]
pub color: bool,
#[structopt(subcommand)]
pub subcommand: SubCommand,
}
#[derive(Debug, StructOpt)]
pub enum SubCommand {
Status,
Pkgs(Pkgs),
Queue(Queue),
Completions(Completions),
}
#[derive(Debug, StructOpt)]
pub enum Pkgs {
Sync(PkgsSync),
Ls(PkgsList),
SyncProfile(PkgsSyncProfile),
SyncStdin(PkgsSyncStdin),
Requeue(PkgsRequeue),
Log(PkgsLog),
Diffoscope(PkgsDiffoscope),
Attestation(PkgsAttestation),
}
#[derive(Debug, StructOpt)]
pub struct PkgsSyncProfile {
#[structopt(long="print-json")]
pub print_json: bool,
pub profile: String,
#[structopt(long="sync-config", default_value="/etc/rebuilderd-sync.conf")]
pub config_file: String,
}
#[derive(Debug, StructOpt)]
pub struct PkgsSyncStdin {
pub distro: String,
pub suite: String,
}
#[derive(Debug, StructOpt)]
pub struct PkgsSync {
pub distro: String,
pub suite: String,
pub source: String,
#[structopt(long="architecture")]
pub architectures: Vec<String>,
#[structopt(long="print-json")]
pub print_json: bool,
#[structopt(long="maintainer")]
pub maintainers: Vec<String>,
#[structopt(long="release")]
pub releases: Vec<String>,
#[structopt(long="pkg")]
pub pkgs: Vec<Pattern>,
#[structopt(long="exclude")]
pub excludes: Vec<Pattern>,
#[structopt(long)]
pub sync_method: Option<String>,
}
#[derive(Debug, StructOpt)]
pub struct PkgsFilter {
#[structopt(long)]
pub name: Option<String>,
#[structopt(long, possible_values=&["GOOD", "BAD", "UNKWN"])]
pub status: Option<Status>,
#[structopt(long)]
pub distro: Option<String>,
#[structopt(long)]
pub suite: Option<String>,
#[structopt(long)]
pub architecture: Option<String>,
}
#[derive(Debug, StructOpt)]
pub struct PkgsList {
#[structopt(flatten)]
pub filter: PkgsFilter,
#[structopt(long)]
pub json: bool,
}
#[derive(Debug, StructOpt)]
pub struct PkgsRequeue {
#[structopt(flatten)]
pub filter: PkgsFilter,
#[structopt(long, default_value="0")]
pub priority: i32,
#[structopt(long)]
pub reset: bool,
}
#[derive(Debug, StructOpt)]
pub struct PkgsLog {
#[structopt(flatten)]
pub filter: PkgsFilter,
}
#[derive(Debug, StructOpt)]
pub struct PkgsDiffoscope {
#[structopt(flatten)]
pub filter: PkgsFilter,
}
#[derive(Debug, StructOpt)]
pub struct PkgsAttestation {
#[structopt(flatten)]
pub filter: PkgsFilter,
}
#[derive(Debug, StructOpt)]
pub enum Queue {
Ls(QueueList),
Push(QueuePush),
#[structopt(name="drop")]
Delete(QueueDrop),
}
#[derive(Debug, StructOpt)]
pub struct QueueList {
#[structopt(long)]
pub head: bool,
#[structopt(long)]
pub json: bool,
}
#[derive(Debug, StructOpt)]
pub struct QueuePush {
pub distro: String,
pub suite: String,
pub name: String,
pub version: Option<String>,
#[structopt(long)]
pub architecture: Option<String>,
#[structopt(long, default_value="0")]
pub priority: i32,
}
#[derive(Debug, StructOpt)]
pub struct QueueDrop {
pub distro: String,
pub suite: String,
#[structopt(long)]
pub architecture: Option<String>,
pub name: String,
pub version: Option<String>,
}
#[derive(Debug, StructOpt)]
pub struct Completions {
#[structopt(possible_values=&Shell::variants())]
pub shell: Shell,
}
pub fn gen_completions(args: &Completions) -> Result<()> {
Args::clap().gen_completions_to("rebuildctl", args.shell, &mut stdout());
Ok(())
}