stellar_registry_cli/commands/
mod.rs1use std::str::FromStr;
2
3use clap::{command, CommandFactory, FromArgMatches, Parser};
4
5pub mod deploy;
6pub mod install;
7pub mod publish;
8pub mod version;
9
10const ABOUT: &str = "Publish and install Soroban contracts";
11
12#[derive(Parser, Debug)]
13#[command(
14 name = "stellar-registry",
15 about = ABOUT,
16 disable_help_subcommand = true,
17)]
18pub struct Root {
19 #[command(subcommand)]
22 pub cmd: Cmd,
23}
24
25impl Root {
26 pub fn new() -> Result<Self, clap::Error> {
27 let mut matches = Self::command().get_matches();
28 Self::from_arg_matches_mut(&mut matches)
29 }
30
31 pub fn from_arg_matches<I, T>(itr: I) -> Result<Self, clap::Error>
32 where
33 I: IntoIterator<Item = T>,
34 T: Into<std::ffi::OsString> + Clone,
35 {
36 Self::from_arg_matches_mut(&mut Self::command().get_matches_from(itr))
37 }
38 pub async fn run(&mut self) -> Result<(), Error> {
39 match &mut self.cmd {
40 Cmd::Publish(p) => p.run().await?,
41 Cmd::Version(p) => p.run(),
42 Cmd::Install(i) => i.run().await?,
43 Cmd::Deploy(deploy) => deploy.run().await?,
44 }
45 Ok(())
46 }
47}
48
49impl FromStr for Root {
50 type Err = clap::Error;
51
52 fn from_str(s: &str) -> Result<Self, Self::Err> {
53 Self::from_arg_matches(s.split_whitespace())
54 }
55}
56
57#[derive(Parser, Debug)]
58pub enum Cmd {
59 Publish(Box<publish::Cmd>),
61 Version(version::Cmd),
63 Deploy(Box<deploy::Cmd>),
65 Install(Box<install::Cmd>),
67}
68
69#[derive(thiserror::Error, Debug)]
70pub enum Error {
71 #[error(transparent)]
72 Publish(#[from] publish::Error),
73 #[error(transparent)]
74 Deploy(#[from] deploy::Error),
75 #[error(transparent)]
76 Install(#[from] install::Error),
77}