use std::str::FromStr;
use clap::{CommandFactory, FromArgMatches, Parser, command};
pub mod create_alias;
pub mod current_version;
pub mod deploy;
pub mod deploy_unnamed;
pub mod download;
pub mod fetch_contract_id;
pub mod fetch_hash;
pub mod global;
pub mod publish;
pub mod publish_hash;
pub mod register_contract;
pub mod rename_contract;
pub mod update_contract_address;
pub mod update_contract_owner;
pub mod upgrade;
pub mod version;
const ABOUT: &str = "Add, manage, and use Wasm packages & named contracts in the Stellar Registry";
#[derive(Parser, Debug)]
#[command(
name = "stellar-registry",
about = ABOUT,
disable_help_subcommand = true,
)]
pub struct Root {
#[command(subcommand)]
pub cmd: Cmd,
}
impl Root {
pub fn new() -> Result<Self, clap::Error> {
let mut matches = Self::command().get_matches();
Self::from_arg_matches_mut(&mut matches)
}
pub fn from_arg_matches<I, T>(itr: I) -> Result<Self, clap::Error>
where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
Self::from_arg_matches_mut(&mut Self::command().get_matches_from(itr))
}
pub async fn run(&mut self) -> Result<(), Error> {
match &mut self.cmd {
Cmd::CurrentVersion(cmd) => cmd.run().await?,
Cmd::Deploy(deploy) => deploy.run().await?,
Cmd::DeployUnnamed(cmd) => cmd.run().await?,
Cmd::Download(cmd) => cmd.run().await?,
Cmd::FetchContractId(cmd) => cmd.run().await?,
Cmd::FetchHash(cmd) => cmd.run().await?,
Cmd::Publish(p) => p.run().await?,
Cmd::PublishHash(cmd) => cmd.run().await?,
Cmd::CreateAlias(i) => i.run().await?,
Cmd::RegisterContract(cmd) => cmd.run().await?,
Cmd::RenameContract(cmd) => cmd.run().await?,
Cmd::UpdateContractAddress(cmd) => cmd.run().await?,
Cmd::UpdateContractOwner(cmd) => cmd.run().await?,
Cmd::Version(p) => p.run(),
Cmd::Upgrade(u) => u.run().await?,
}
Ok(())
}
}
impl FromStr for Root {
type Err = clap::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::from_arg_matches(s.split_whitespace())
}
}
#[derive(Parser, Debug)]
pub enum Cmd {
CreateAlias(Box<create_alias::Cmd>),
CurrentVersion(Box<current_version::Cmd>),
Deploy(Box<deploy::Cmd>),
DeployUnnamed(Box<deploy_unnamed::Cmd>),
Download(Box<download::Cmd>),
FetchContractId(Box<fetch_contract_id::Cmd>),
FetchHash(Box<fetch_hash::Cmd>),
Publish(Box<publish::Cmd>),
PublishHash(Box<publish_hash::Cmd>),
RegisterContract(Box<register_contract::Cmd>),
RenameContract(Box<rename_contract::Cmd>),
UpdateContractAddress(Box<update_contract_address::Cmd>),
UpdateContractOwner(Box<update_contract_owner::Cmd>),
Upgrade(Box<upgrade::Cmd>),
Version(version::Cmd),
}
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
CreateAlias(#[from] create_alias::Error),
#[error(transparent)]
CurrentVersion(#[from] current_version::Error),
#[error(transparent)]
Deploy(#[from] deploy::Error),
#[error(transparent)]
DeployUnnamed(#[from] deploy_unnamed::Error),
#[error(transparent)]
Download(#[from] download::Error),
#[error(transparent)]
FetchContractId(#[from] fetch_contract_id::Error),
#[error(transparent)]
FetchHash(#[from] fetch_hash::Error),
#[error(transparent)]
Publish(#[from] publish::Error),
#[error(transparent)]
PublishHash(#[from] publish_hash::Error),
#[error(transparent)]
RegisterContract(#[from] register_contract::Error),
#[error(transparent)]
RenameContract(#[from] rename_contract::Error),
#[error(transparent)]
UpdateContractAddress(#[from] update_contract_address::Error),
#[error(transparent)]
UpdateContractOwner(#[from] update_contract_owner::Error),
#[error(transparent)]
Upgrade(#[from] upgrade::Error),
}