clidispatch: punch "@prog@" variables in abort messages

Summary: This way you can use "prog@" more conviently when bailing out with an error that gives advice on what command to run.

Reviewed By: sggutier

Differential Revision: D50570658

fbshipit-source-id: 87b2bfe4e01a0a219df89d8bc29fbc0ddad49af6
This commit is contained in:
Muir Manders 2023-10-23 15:51:48 -07:00 committed by Facebook GitHub Bot
parent c136fc3192
commit 272d970c85
2 changed files with 11 additions and 5 deletions

View File

@ -45,10 +45,17 @@ pub struct RepoRequired(pub String);
#[error("malformed --config option: '{0}' (use --config section.name=value)")]
pub struct MalformedConfigOption(pub String);
#[derive(Debug, Error)]
#[error("{0}")]
#[derive(Debug)]
pub struct Abort(pub Cow<'static, str>);
impl std::error::Error for Abort {}
impl std::fmt::Display for Abort {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", identity::default().punch(&self.0))
}
}
/// Print an error suitable for end-user consumption.
///
/// This function adds `hg:` or `abort:` to error messages.

View File

@ -7,6 +7,7 @@
use anyhow::bail;
use anyhow::Result;
use clidispatch::abort;
use clidispatch::fallback;
use clidispatch::ReqCtx;
use cliparser::define_flags;
@ -85,9 +86,7 @@ pub fn run(ctx: ReqCtx<GotoOpts>, repo: &mut Repo, wc: &mut WorkingCopy) -> Resu
}
if dest.is_empty() {
bail!(identity::default().punch(
r#"You must specify a destination to update to, for example "@prog@ goto main"."#,
));
abort!(r#"You must specify a destination to update to, for example "@prog@ goto main"."#);
}
if dest.len() > 1 {
bail!(