soroban_cli/commands/keys/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use crate::commands::global;
use clap::Parser;

pub mod add;
pub mod address;
pub mod default;
pub mod fund;
pub mod generate;
pub mod ls;
pub mod rm;
pub mod show;

#[derive(Debug, Parser)]
pub enum Cmd {
    /// Add a new identity (keypair, ledger, macOS keychain)
    Add(add::Cmd),

    /// Given an identity return its address (public key)
    Address(address::Cmd),

    /// Fund an identity on a test network
    Fund(fund::Cmd),

    /// Generate a new identity with a seed phrase, currently 12 words
    Generate(generate::Cmd),

    /// List identities
    Ls(ls::Cmd),

    /// Remove an identity
    Rm(rm::Cmd),

    /// Given an identity return its private key
    Show(show::Cmd),

    /// Set the default identity that will be used on all commands.
    /// This allows you to skip `--source-account` or setting a environment
    /// variable, while reusing this value in all commands that require it.
    #[command(name = "use")]
    Default(default::Cmd),
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error(transparent)]
    Add(#[from] add::Error),

    #[error(transparent)]
    Address(#[from] address::Error),

    #[error(transparent)]
    Fund(#[from] fund::Error),

    #[error(transparent)]
    Generate(#[from] generate::Error),

    #[error(transparent)]
    Rm(#[from] rm::Error),

    #[error(transparent)]
    Ls(#[from] ls::Error),

    #[error(transparent)]
    Show(#[from] show::Error),

    #[error(transparent)]
    Default(#[from] default::Error),
}

impl Cmd {
    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
        match self {
            Cmd::Add(cmd) => cmd.run()?,
            Cmd::Address(cmd) => cmd.run()?,
            Cmd::Fund(cmd) => cmd.run().await?,
            Cmd::Generate(cmd) => cmd.run(global_args).await?,
            Cmd::Ls(cmd) => cmd.run()?,
            Cmd::Rm(cmd) => cmd.run()?,
            Cmd::Show(cmd) => cmd.run()?,
            Cmd::Default(cmd) => cmd.run(global_args)?,
        };
        Ok(())
    }
}