soroban_cli/commands/contract/
bindings.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
pub mod json;
pub mod python;
pub mod rust;
pub mod typescript;

#[derive(Debug, clap::Subcommand)]
pub enum Cmd {
    /// Generate Json Bindings
    Json(json::Cmd),

    /// Generate Rust bindings
    Rust(rust::Cmd),

    /// Generate a TypeScript / JavaScript package
    Typescript(typescript::Cmd),

    /// Generate Python bindings
    Python(python::Cmd),
}

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

    #[error(transparent)]
    Rust(#[from] rust::Error),

    #[error(transparent)]
    Typescript(#[from] typescript::Error),

    #[error(transparent)]
    Python(#[from] python::Error),
}

impl Cmd {
    pub async fn run(&self) -> Result<(), Error> {
        match &self {
            Cmd::Json(json) => json.run()?,
            Cmd::Rust(rust) => rust.run()?,
            Cmd::Typescript(ts) => ts.run().await?,
            Cmd::Python(python) => python.run()?,
        }
        Ok(())
    }
}