fix(rust): get default node command to stop mapping errors manually
-use crate::{util::exitcode, CommandGlobalOpts};
+use anyhow::anyhow;
use clap::Args;
+use crate::exitcode::UNAVAILABLE;
+use crate::CommandGlobalOpts;
+
#[derive(Clone, Debug, Args)]
pub struct GetDefaultNodeCommand {}
impl GetDefaultNodeCommand {
pub fn run(self, options: CommandGlobalOpts) {
- match options.config.get_default_node() {
- Some(name) => {
- println!("Current Default Node: {}", name)
+ if let Err(e) = run_impl(options) {
+ eprintln!("{}", e);
+ std::process::exit(e.code());
+ }
}
- None => {
- eprintln!("Default Node is not set");
- std::process::exit(exitcode::UNAVAILABLE);
}
+
+fn run_impl(opts: CommandGlobalOpts) -> crate::Result<()> {
+ match opts.config.get_default_node() {
+ Some(name) => {
+ println!("Current Default Node: {}", name);
+ Ok(())
}
+ None => Err(crate::error::Error::new(
+ UNAVAILABLE,
+ anyhow!("Default Node is not set"),
+ )),
}
}
