use crate::cli::handler::{RunError, RunErrorKind, RunOutput, RunResult};
#[derive(Debug)]
pub enum HelpResult {
Matches(clap::ArgMatches),
Help(String),
PagedHelp(String),
Error(clap::Error),
}
#[derive(Debug)]
pub(crate) enum HelpDisplay {
Rendered {
text: String,
paged: bool,
},
Clap(clap::Error),
RenderFailed(clap::Error),
}
impl From<HelpDisplay> for HelpResult {
fn from(display: HelpDisplay) -> Self {
match display {
HelpDisplay::Rendered { text, paged: true } => HelpResult::PagedHelp(text),
HelpDisplay::Rendered { text, paged: false } => HelpResult::Help(text),
HelpDisplay::Clap(e) | HelpDisplay::RenderFailed(e) => HelpResult::Error(e),
}
}
}
impl From<HelpDisplay> for RunResult {
fn from(display: HelpDisplay) -> Self {
match display {
HelpDisplay::Rendered { text, paged } => RunResult::Handled(if paged {
RunOutput::paged_help(text)
} else {
RunOutput::clap_help(text)
}),
HelpDisplay::Clap(e) if e.use_stderr() => {
RunResult::Error(RunError::new(e.to_string(), RunErrorKind::ClapUsage))
}
HelpDisplay::Clap(e) => RunResult::Handled(RunOutput::clap_help(e.to_string())),
HelpDisplay::RenderFailed(e) => {
RunResult::Error(RunError::new(e.to_string(), RunErrorKind::Render))
}
}
}
}