diff --git a/src/bin/stellar-xdr/main.rs b/src/bin/stellar-xdr/main.rs index 443a11a4..cc85ea64 100644 --- a/src/bin/stellar-xdr/main.rs +++ b/src/bin/stellar-xdr/main.rs @@ -1,8 +1,9 @@ use clap::Error; +use std::env; use stellar_xdr::cli; fn main() { - if let Err(e) = cli::run() { + if let Err(e) = cli::run(env::args_os()) { Error::raw(clap::error::ErrorKind::ValueValidation, e).exit(); } } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ade110f9..3a823171 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -5,7 +5,7 @@ mod types; mod version; use clap::{Parser, Subcommand, ValueEnum}; -use std::{error::Error, fmt::Debug}; +use std::{error::Error, ffi::OsString, fmt::Debug}; #[derive(Parser, Debug, Clone)] #[command( @@ -54,15 +54,17 @@ enum Cmd { Version, } -/// Run the CLI. -/// -/// TODO: How to pass in input to run from other CLI? +/// Run the CLI with the given args. /// /// ## Errors /// /// If the input cannot be parsed. -pub fn run() -> Result<(), Box> { - let root = Root::try_parse()?; +pub fn run(args: I) -> Result<(), Box> +where + I: IntoIterator, + T: Into + Clone, +{ + let root = Root::try_parse_from(args)?; match root.cmd { Cmd::Types(c) => c.run(&root.channel)?, Cmd::Guess(c) => c.run(&root.channel)?,