Add ParseCommand error

This commit is contained in:
fluo10 2025-06-06 08:22:36 +09:00
parent 0f12dabfc1
commit 4b5758ba51
3 changed files with 8 additions and 5 deletions

View file

@ -81,7 +81,9 @@ impl ConsoleArgs {
loop {
match rl.readline(">> ") {
Ok(line) => {
commands.parse_and_run(line).await?
if let Err(e) = commands.parse_and_run(line).await {
println!("{e}");
}
},
Err(x) => Err(x)?,
};

View file

@ -23,7 +23,7 @@ pub struct ConsoleNodeArgs {
pub args: NodeArgs,
}
impl ConsoleNodeArgs {
impl NodeArgs {
pub async fn run(self) -> Result<(), Error> {
println!("{self:?}");
Ok(())
@ -31,8 +31,7 @@ impl ConsoleNodeArgs {
}
pub async fn parse_and_run_console_node_command(s:Vec<String>) -> Result<(), Error> {
let args = ConsoleNodeArgs::parse_from(s);
args.run().await
ConsoleNodeArgs::try_parse_from(s)?.args.run().await
}
#[derive(Args, Debug)]

View file

@ -18,6 +18,8 @@ pub enum Error {
Multiaddr(#[from] libp2p::multiaddr::Error),
#[error("Noise error: {0}")]
Noise(#[from] libp2p::noise::Error),
#[error("Parse args error: {0}")]
ParseCommand(#[from] clap::Error),
#[error("Readline error: {0}")]
Readline(#[from] rustyline::error::ReadlineError),
#[error("Shell word split error: {0}")]