stellar_xdr/cli/
generate.rs

1pub mod arbitrary;
2pub mod default;
3
4use clap::{Args, Subcommand};
5
6use crate::cli::Channel;
7
8#[derive(thiserror::Error, Debug)]
9pub enum Error {
10    #[error("{0}")]
11    Default(#[from] default::Error),
12    #[error("{0}")]
13    Arbitrary(#[from] arbitrary::Error),
14}
15
16/// Generate XDR values
17#[derive(Args, Debug, Clone)]
18#[command()]
19pub struct Cmd {
20    #[command(subcommand)]
21    pub sub: Sub,
22}
23
24#[derive(Subcommand, Clone, Debug)]
25pub enum Sub {
26    Default(default::Cmd),
27    Arbitrary(arbitrary::Cmd),
28}
29
30impl Cmd {
31    /// Run the CLIs generate command.
32    ///
33    /// ## Errors
34    ///
35    /// If the sub-command panics.
36    ///
37    /// ## Panics
38    ///
39    /// If the sub-command panics.
40    pub fn run(&self, channel: &Channel) -> Result<(), Error> {
41        match &self.sub {
42            Sub::Default(c) => c.run(channel)?,
43            Sub::Arbitrary(c) => c.run(channel)?,
44        }
45        Ok(())
46    }
47}