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;
8
9const ABOUT: &str = "Publish and install Soroban contracts";
10
11const LONG_ABOUT: &str = "LONG ABOUT";
13
14#[derive(Parser, Debug)]
15#[command(
16 name = "stellar-registry",
17 about = ABOUT,
18 long_about = ABOUT.to_string() + LONG_ABOUT,
19 disable_help_subcommand = true,
20)]
21pub struct Root {
22 #[command(subcommand)]
25 pub cmd: Cmd,
26}
27
28impl Root {
29 pub fn new() -> Result<Self, clap::Error> {
30 let mut matches = Self::command().get_matches();
31 Self::from_arg_matches_mut(&mut matches)
32 }
33
34 pub fn from_arg_matches<I, T>(itr: I) -> Result<Self, clap::Error>
35 where
36 I: IntoIterator<Item = T>,
37 T: Into<std::ffi::OsString> + Clone,
38 {
39 Self::from_arg_matches_mut(&mut Self::command().get_matches_from(itr))
40 }
41 pub async fn run(&mut self) -> Result<(), Error> {
42 match &mut self.cmd {
43 Cmd::Publish(p) => p.run().await?,
44 Cmd::Install(i) => i.run().await?,
45 Cmd::Deploy(deploy) => deploy.run().await?,
46 }
47 Ok(())
48 }
49}
50
51impl FromStr for Root {
52 type Err = clap::Error;
53
54 fn from_str(s: &str) -> Result<Self, Self::Err> {
55 Self::from_arg_matches(s.split_whitespace())
56 }
57}
58
59#[derive(Parser, Debug)]
60pub enum Cmd {
61 Publish(Box<publish::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}