Skip to main content

asimov_cli/commands/
handle.rs

1// This is free and unencumbered software released into the public domain.
2
3use asimov_id::{Handle, Id, PublicKey, PublicKeyEncoding};
4use clientele::{StandardOptions, crates::clap::Subcommand};
5use core::error::Error;
6use std::path::PathBuf;
7
8#[derive(Debug, Subcommand)]
9pub enum HandleCommand {
10    #[cfg(feature = "unstable")]
11    Add {
12        /// The handle
13        handle: Handle,
14
15        /// The public keys of the endpoints to associate with the handle
16        endpoints: Vec<PublicKey>,
17    },
18
19    /// Export all handles and their associated endpoints
20    Export {},
21
22    #[cfg(feature = "unstable")]
23    Import {
24        /// The paths to the input files (default: /dev/stdin)
25        inputs: Vec<PathBuf>,
26    },
27
28    /// List all handles that have endpoints associated with them
29    #[clap(aliases = ["ls"])]
30    List {},
31
32    #[cfg(feature = "unstable")]
33    #[clap(aliases = ["rm", "delete", "del"])]
34    Remove {
35        /// The handle
36        handle: Handle,
37
38        /// The public keys of the endpoints to disassociate with the handle
39        endpoints: Vec<PublicKey>,
40    },
41
42    /// Resolve a handle into a set of associated endpoints
43    #[clap(aliases = ["lookup"])]
44    Resolve {
45        /// The handle to resolve
46        handle: Id,
47
48        /// The encoding format for public keys (default: asimov)
49        #[clap(short, long)]
50        format: Option<PublicKeyEncoding>,
51    },
52}
53
54impl HandleCommand {
55    pub async fn run(&self, flags: &StandardOptions) -> Result<(), Box<dyn Error>> {
56        match self {
57            #[cfg(feature = "unstable")]
58            HandleCommand::Add { handle, endpoints } => add(handle, endpoints, flags).await,
59
60            HandleCommand::Export {} => export(flags).await,
61
62            #[cfg(feature = "unstable")]
63            HandleCommand::Import { inputs } => import(inputs, flags).await,
64
65            HandleCommand::List {} => list(flags).await,
66
67            #[cfg(feature = "unstable")]
68            HandleCommand::Remove { handle, endpoints } => remove(handle, endpoints, flags).await,
69
70            HandleCommand::Resolve { handle, format } => resolve(handle, format, flags).await,
71        }
72    }
73}
74
75#[cfg(feature = "unstable")]
76mod add;
77#[cfg(feature = "unstable")]
78pub use add::*;
79
80mod export;
81pub use export::*;
82
83#[cfg(feature = "unstable")]
84mod import;
85#[cfg(feature = "unstable")]
86pub use import::*;
87
88mod list;
89pub use list::*;
90
91#[cfg(feature = "unstable")]
92mod remove;
93#[cfg(feature = "unstable")]
94pub use remove::*;
95
96mod resolve;
97pub use resolve::*;