Add ParseCommand error
This commit is contained in:
parent
0f12dabfc1
commit
4b5758ba51
3 changed files with 8 additions and 5 deletions
|
@ -44,7 +44,7 @@ impl ConsoleCommands {
|
||||||
println!("Invalid command: {command_name}");
|
println!("Invalid command: {command_name}");
|
||||||
self.print_commands();
|
self.print_commands();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,9 @@ impl ConsoleArgs {
|
||||||
loop {
|
loop {
|
||||||
match rl.readline(">> ") {
|
match rl.readline(">> ") {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
commands.parse_and_run(line).await?
|
if let Err(e) = commands.parse_and_run(line).await {
|
||||||
|
println!("{e}");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(x) => Err(x)?,
|
Err(x) => Err(x)?,
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub struct ConsoleNodeArgs {
|
||||||
pub args: NodeArgs,
|
pub args: NodeArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConsoleNodeArgs {
|
impl NodeArgs {
|
||||||
pub async fn run(self) -> Result<(), Error> {
|
pub async fn run(self) -> Result<(), Error> {
|
||||||
println!("{self:?}");
|
println!("{self:?}");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -31,8 +31,7 @@ impl ConsoleNodeArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn parse_and_run_console_node_command(s:Vec<String>) -> Result<(), Error> {
|
pub async fn parse_and_run_console_node_command(s:Vec<String>) -> Result<(), Error> {
|
||||||
let args = ConsoleNodeArgs::parse_from(s);
|
ConsoleNodeArgs::try_parse_from(s)?.args.run().await
|
||||||
args.run().await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
|
|
|
@ -18,6 +18,8 @@ pub enum Error {
|
||||||
Multiaddr(#[from] libp2p::multiaddr::Error),
|
Multiaddr(#[from] libp2p::multiaddr::Error),
|
||||||
#[error("Noise error: {0}")]
|
#[error("Noise error: {0}")]
|
||||||
Noise(#[from] libp2p::noise::Error),
|
Noise(#[from] libp2p::noise::Error),
|
||||||
|
#[error("Parse args error: {0}")]
|
||||||
|
ParseCommand(#[from] clap::Error),
|
||||||
#[error("Readline error: {0}")]
|
#[error("Readline error: {0}")]
|
||||||
Readline(#[from] rustyline::error::ReadlineError),
|
Readline(#[from] rustyline::error::ReadlineError),
|
||||||
#[error("Shell word split error: {0}")]
|
#[error("Shell word split error: {0}")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue