pub mod args;
mod aspa;
mod bgpsec;
mod bulk;
mod ca;
mod children;
mod config;
mod parents;
mod pubserver;
pub mod repo;
mod roas;
mod server;
use clap::Parser;
use crate::api::admin::Token;
use super::client::{KrillClient, ServerUri};
use super::report::{Report, ReportFormat};
#[derive(clap::Parser)]
#[command(
version,
about = "The Krill command line client.",
)]
pub struct Options {
#[command(flatten)]
pub general: GeneralOptions,
#[command(subcommand)]
pub command: Command,
}
impl Options {
pub fn from_args() -> Self {
Self::parse()
}
}
#[derive(clap::Args)]
#[command(version)]
pub struct GeneralOptions {
#[arg(
short, long,
env = "KRILL_CLI_SERVER",
default_value = "unix:///run/krill/krill.sock"
)]
pub server: ServerUri,
#[arg(
short, long,
env = "KRILL_CLI_TOKEN",
)]
pub token: Option<Token>,
#[arg(
short, long,
env = "KRILL_CLI_FORMAT",
default_value = "text",
)]
pub format: ReportFormat,
#[arg(long)]
pub api: bool,
}
#[derive(clap::Subcommand)]
pub enum Command {
#[command(subcommand)]
Config(config::Command),
Health(server::Health),
Info(server::Info),
List(ca::List),
Show(ca::Show),
#[command(subcommand)]
History(ca::History),
Add(ca::Add),
Delete(ca::Delete),
Issues(server::Issues),
#[command(subcommand)]
Children(children::Command),
#[command(subcommand)]
Parents(parents::Command),
#[command(subcommand)]
Keyroll(ca::Keyroll),
#[command(subcommand)]
Repo(repo::Command),
#[command(subcommand)]
Roas(roas::Command),
#[command(subcommand)]
Bgpsec(bgpsec::Command),
#[command(subcommand)]
Aspas(aspa::Command),
#[command(subcommand)]
Pubserver(pubserver::Command),
#[command(subcommand)]
Bulk(bulk::Command),
}
impl Command {
pub async fn run(self, client: &KrillClient) -> Report {
match self {
Self::Config(cmd) => cmd.run(client).await,
Self::Health(cmd) => cmd.run(client).await.into(),
Self::Info(cmd) => cmd.run(client).await.into(),
Self::List(cmd) => cmd.run(client).await.into(),
Self::Show(cmd) => cmd.run(client).await.into(),
Self::History(cmd) => cmd.run(client).await,
Self::Add(cmd) => cmd.run(client).await.into(),
Self::Delete(cmd) => cmd.run(client).await.into(),
Self::Issues(cmd) => cmd.run(client).await,
Self::Children(cmd) => cmd.run(client).await,
Self::Parents(cmd) => cmd.run(client).await,
Self::Keyroll(cmd) => cmd.run(client).await,
Self::Repo(cmd) => cmd.run(client).await,
Self::Roas(cmd) => cmd.run(client).await,
Self::Bgpsec(cmd) => cmd.run(client).await,
Self::Aspas(cmd) => cmd.run(client).await,
Self::Pubserver(cmd) => cmd.run(client).await,
Self::Bulk(cmd) => cmd.run(client).await,
}
}
}