use std::path::PathBuf;
use super::builder_collections;
use crate::backend::Command;
use crate::options::Secret;
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into), on(PathBuf, into), on(bool, default))]
pub struct PluginInstall {
#[builder(start_fn)]
pub source: String,
pub version: Option<String>,
#[builder(default = true)]
pub verify: bool,
pub keyring: Option<PathBuf>,
pub cert_file: Option<PathBuf>,
pub key_file: Option<PathBuf>,
pub ca_file: Option<PathBuf>,
pub insecure_skip_tls_verify: bool,
pub plain_http: bool,
pub username: Option<String>,
}
impl PluginInstall {
#[must_use]
pub fn new(source: impl Into<String>) -> Self {
Self::builder(source).build()
}
}
impl Command for PluginInstall {
type Output = PluginInstalled;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginInstalled {
pub name: String,
pub verification: Option<PluginVerification>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into))]
pub struct PluginList {
pub kind: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Plugin {
pub name: String,
pub version: String,
pub kind: String,
pub api_version: String,
pub provenance: String,
pub source: Option<String>,
}
impl Command for PluginList {
type Output = Vec<Plugin>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Passphrase {
File(PathBuf),
Stdin(Secret),
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into), on(PathBuf, into), on(bool, default))]
pub struct PluginPackage {
#[builder(start_fn)]
pub path: PathBuf,
pub destination: Option<PathBuf>,
#[builder(default = true)]
pub sign: bool,
pub key: Option<String>,
pub keyring: Option<PathBuf>,
pub passphrase: Option<Passphrase>,
}
impl PluginPackage {
#[must_use]
pub fn new(path: impl Into<PathBuf>) -> Self {
Self::builder(path).build()
}
}
impl Command for PluginPackage {
type Output = ();
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(start_fn(name = start, vis = ""))]
pub struct PluginUninstall {
#[builder(field)]
pub names: Vec<String>,
}
builder_collections! {
PluginUninstallBuilder, plugin_uninstall_builder;
vec names / name: String, "`<plugin>` arguments", "the names of the plugins";
}
impl PluginUninstall {
pub fn builder(names: impl IntoIterator<Item = impl Into<String>>) -> PluginUninstallBuilder {
Self::start().names(names)
}
#[must_use]
pub fn new(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
Self::builder(names).build()
}
}
impl Command for PluginUninstall {
type Output = ();
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(start_fn(name = start, vis = ""))]
pub struct PluginUpdate {
#[builder(field)]
pub names: Vec<String>,
}
builder_collections! {
PluginUpdateBuilder, plugin_update_builder;
vec names / name: String, "`<plugin>` arguments", "the names of the plugins";
}
impl PluginUpdate {
pub fn builder(names: impl IntoIterator<Item = impl Into<String>>) -> PluginUpdateBuilder {
Self::start().names(names)
}
#[must_use]
pub fn new(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
Self::builder(names).build()
}
}
impl Command for PluginUpdate {
type Output = ();
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PluginVerification {
pub signed_by: Vec<String>,
pub fingerprint: String,
pub hash: String,
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(PathBuf, into))]
pub struct PluginVerify {
#[builder(start_fn)]
pub path: PathBuf,
pub keyring: Option<PathBuf>,
}
impl PluginVerify {
#[must_use]
pub fn new(path: impl Into<PathBuf>) -> Self {
Self::builder(path).build()
}
}
impl Command for PluginVerify {
type Output = PluginVerification;
}