soroban_cli/commands/keys/
mod.rs

1use crate::commands::global;
2use clap::Parser;
3
4pub mod add;
5pub mod default;
6pub mod fund;
7pub mod generate;
8pub mod ls;
9pub mod public_key;
10pub mod rm;
11pub mod secret;
12pub mod unset;
13
14#[derive(Debug, Parser)]
15pub enum Cmd {
16    /// Add a new identity (keypair, ledger, OS specific secure store)
17    Add(add::Cmd),
18
19    /// Given an identity return its address (public key)
20    #[command(visible_alias = "address")]
21    PublicKey(public_key::Cmd),
22
23    /// Fund an identity on a test network
24    Fund(fund::Cmd),
25
26    /// Generate a new identity using a 24-word seed phrase
27    /// The seed phrase can be stored in a config file (default) or in an OS-specific secure store.
28    Generate(generate::Cmd),
29
30    /// List identities
31    Ls(ls::Cmd),
32
33    /// Remove an identity
34    Rm(rm::Cmd),
35
36    /// Output an identity's secret key
37    Secret(secret::Cmd),
38
39    /// Set the default identity that will be used on all commands.
40    /// This allows you to skip `--source-account` or setting a environment
41    /// variable, while reusing this value in all commands that require it.
42    #[command(name = "use")]
43    Default(default::Cmd),
44
45    /// Unset the default key identity defined previously with `keys use <identity>`
46    Unset(unset::Cmd),
47}
48
49#[derive(thiserror::Error, Debug)]
50pub enum Error {
51    #[error(transparent)]
52    Add(#[from] add::Error),
53
54    #[error(transparent)]
55    Address(#[from] public_key::Error),
56
57    #[error(transparent)]
58    Fund(#[from] fund::Error),
59
60    #[error(transparent)]
61    Generate(#[from] generate::Error),
62
63    #[error(transparent)]
64    Rm(#[from] rm::Error),
65
66    #[error(transparent)]
67    Ls(#[from] ls::Error),
68
69    #[error(transparent)]
70    Show(#[from] secret::Error),
71
72    #[error(transparent)]
73    Default(#[from] default::Error),
74
75    #[error(transparent)]
76    Unset(#[from] unset::Error),
77}
78
79impl Cmd {
80    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
81        match self {
82            Cmd::Add(cmd) => cmd.run(global_args)?,
83            Cmd::PublicKey(cmd) => cmd.run().await?,
84            Cmd::Fund(cmd) => cmd.run(global_args).await?,
85            Cmd::Generate(cmd) => cmd.run(global_args).await?,
86            Cmd::Ls(cmd) => cmd.run()?,
87            Cmd::Rm(cmd) => cmd.run(global_args)?,
88            Cmd::Secret(cmd) => cmd.run()?,
89            Cmd::Default(cmd) => cmd.run(global_args)?,
90            Cmd::Unset(cmd) => cmd.run(global_args)?,
91        }
92        Ok(())
93    }
94}