Skip to main content

stellar_xdr/cli/
generate.rs

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