use asimov_id::{Handle, Id, PublicKey, PublicKeyEncoding};
use clientele::{StandardOptions, crates::clap::Subcommand};
use core::error::Error;
use std::path::PathBuf;
#[derive(Debug, Subcommand)]
pub enum HandleCommand {
#[cfg(feature = "unstable")]
Add {
handle: Handle,
endpoints: Vec<PublicKey>,
},
Export {},
#[cfg(feature = "unstable")]
Import {
inputs: Vec<PathBuf>,
},
#[clap(aliases = ["ls"])]
List {},
#[cfg(feature = "unstable")]
#[clap(aliases = ["rm", "delete", "del"])]
Remove {
handle: Handle,
endpoints: Vec<PublicKey>,
},
#[clap(aliases = ["lookup"])]
Resolve {
handle: Id,
#[clap(short, long)]
format: Option<PublicKeyEncoding>,
},
}
impl HandleCommand {
pub async fn run(&self, flags: &StandardOptions) -> Result<(), Box<dyn Error>> {
match self {
#[cfg(feature = "unstable")]
HandleCommand::Add { handle, endpoints } => add(handle, endpoints, flags).await,
HandleCommand::Export {} => export(flags).await,
#[cfg(feature = "unstable")]
HandleCommand::Import { inputs } => import(inputs, flags).await,
HandleCommand::List {} => list(flags).await,
#[cfg(feature = "unstable")]
HandleCommand::Remove { handle, endpoints } => remove(handle, endpoints, flags).await,
HandleCommand::Resolve { handle, format } => resolve(handle, format, flags).await,
}
}
}
#[cfg(feature = "unstable")]
mod add;
#[cfg(feature = "unstable")]
pub use add::*;
mod export;
pub use export::*;
#[cfg(feature = "unstable")]
mod import;
#[cfg(feature = "unstable")]
pub use import::*;
mod list;
pub use list::*;
#[cfg(feature = "unstable")]
mod remove;
#[cfg(feature = "unstable")]
pub use remove::*;
mod resolve;
pub use resolve::*;