soroban_cli/
lib.rs

1#![allow(
2    clippy::missing_errors_doc,
3    clippy::must_use_candidate,
4    clippy::missing_panics_doc
5)]
6use std::path::Path;
7
8pub(crate) use soroban_rpc as rpc;
9pub use stellar_xdr::curr as xdr;
10
11mod cli;
12pub use cli::main;
13
14pub mod assembled;
15pub mod commands;
16pub mod config;
17mod env_vars;
18pub mod fee;
19pub mod get_spec;
20pub mod key;
21pub mod log;
22pub mod print;
23pub mod signer;
24pub mod toid;
25pub mod tx;
26pub mod upgrade_check;
27pub mod utils;
28pub mod wasm;
29
30pub use commands::Root;
31
32pub fn parse_cmd<T>(s: &str) -> Result<T, clap::Error>
33where
34    T: clap::CommandFactory + clap::FromArgMatches,
35{
36    let input = shlex::split(s).ok_or_else(|| {
37        clap::Error::raw(
38            clap::error::ErrorKind::InvalidValue,
39            format!("Invalid input for command:\n{s}"),
40        )
41    })?;
42    T::from_arg_matches_mut(&mut T::command().no_binary_name(true).get_matches_from(input))
43}
44
45pub trait CommandParser<T> {
46    fn parse(s: &str) -> Result<T, clap::Error>;
47
48    fn parse_arg_vec(s: &[&str]) -> Result<T, clap::Error>;
49}
50
51impl<T> CommandParser<T> for T
52where
53    T: clap::CommandFactory + clap::FromArgMatches,
54{
55    fn parse(s: &str) -> Result<T, clap::Error> {
56        parse_cmd(s)
57    }
58
59    fn parse_arg_vec(args: &[&str]) -> Result<T, clap::Error> {
60        T::from_arg_matches_mut(&mut T::command().no_binary_name(true).get_matches_from(args))
61    }
62}
63
64pub trait Pwd {
65    fn set_pwd(&mut self, pwd: &Path);
66}