cli: wrap clap::Error within Arc to make CommandError cloneable

This allows us to load workspace by using &Result<T, CommandError>. Even
though load_workspace() wouldn't be called more than once, consuming self
there is annoying.
This commit is contained in:
Yuya Nishihara 2023-01-10 09:42:48 +09:00
parent 1df1603b0b
commit c3903cb914

View file

@ -58,7 +58,7 @@ use crate::merge_tools::{ConflictResolveError, DiffEditError};
use crate::templater::TemplateFormatter;
use crate::ui::{ColorChoice, Ui};
#[derive(Debug)]
#[derive(Clone, Debug)]
pub enum CommandError {
UserError {
message: String,
@ -68,7 +68,7 @@ pub enum CommandError {
/// Invalid command line
CliError(String),
/// Invalid command line detected by clap
ClapCliError(clap::Error),
ClapCliError(Arc<clap::Error>),
BrokenPipe,
InternalError(String),
}
@ -216,7 +216,7 @@ impl From<glob::PatternError> for CommandError {
impl From<clap::Error> for CommandError {
fn from(err: clap::Error) -> Self {
CommandError::ClapCliError(err)
CommandError::ClapCliError(Arc::new(err))
}
}