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