Skip to main content

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 as xdr;
10
11mod cli;
12pub use cli::main;
13
14pub mod assembled;
15pub mod auth_mode;
16pub mod color;
17pub mod commands;
18pub mod config;
19mod env_vars;
20pub mod fixed_point;
21pub mod get_spec;
22pub mod key;
23pub mod log;
24pub mod output;
25pub mod print;
26pub mod resources;
27pub mod signer;
28pub mod tx;
29pub mod upgrade_check;
30pub mod utils;
31pub mod wasm;
32
33#[cfg(test)]
34pub mod test_utils;
35
36pub use commands::Root;
37
38pub fn parse_cmd<T>(s: &str) -> Result<T, clap::Error>
39where
40    T: clap::CommandFactory + clap::FromArgMatches,
41{
42    let input = shlex::split(s).ok_or_else(|| {
43        clap::Error::raw(
44            clap::error::ErrorKind::InvalidValue,
45            format!("Invalid input for command:\n{s}"),
46        )
47    })?;
48    T::from_arg_matches_mut(&mut T::command().no_binary_name(true).get_matches_from(input))
49}
50
51pub trait CommandParser<T> {
52    fn parse(s: &str) -> Result<T, clap::Error>;
53
54    fn parse_arg_vec(s: &[&str]) -> Result<T, clap::Error>;
55}
56
57impl<T> CommandParser<T> for T
58where
59    T: clap::CommandFactory + clap::FromArgMatches,
60{
61    fn parse(s: &str) -> Result<T, clap::Error> {
62        parse_cmd(s)
63    }
64
65    fn parse_arg_vec(args: &[&str]) -> Result<T, clap::Error> {
66        T::from_arg_matches_mut(&mut T::command().no_binary_name(true).get_matches_from(args))
67    }
68}
69
70pub trait Pwd {
71    fn set_pwd(&mut self, pwd: &Path);
72}