From 68e355690b265a3aedfa0b1d862ca581a94cb82b Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Fri, 13 Dec 2024 23:57:36 +0100 Subject: [PATCH] Don't make impossible recommendations. - Only recommend that they user try `--add-userid` if the command actually supports it. --- src/common/types/userid_designator.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common/types/userid_designator.rs b/src/common/types/userid_designator.rs index 9dbe3500..0d7809f9 100644 --- a/src/common/types/userid_designator.rs +++ b/src/common/types/userid_designator.rs @@ -13,6 +13,7 @@ use openpgp::cert::amalgamation::ValidateAmalgamation; use crate::Result; use crate::cli::types::UserIDDesignators; use crate::cli::types::userid_designator::AddArgs; +use crate::cli::types::userid_designator::PlainIsAdd; use crate::cli::types::userid_designator::ResolvedUserID; use crate::cli::types::userid_designator::UserIDDesignator; use crate::cli::types::userid_designator::UserIDDesignatorSemantics; @@ -52,6 +53,7 @@ where let arguments = Arguments::to_usize(); let add_args = (arguments & AddArgs::to_usize()) > 0; + let plain_is_add = (arguments & PlainIsAdd::to_usize()) > 0; // Find the matching User IDs. let mut userids = Vec::new(); @@ -306,7 +308,7 @@ where } if missing { - if add_args { + if add_args && ! plain_is_add { weprintln!("Use `--add-userid` or `--add-email` to use \ a user ID even if it isn't self signed, or has \ an invalid self signature."); @@ -314,15 +316,23 @@ where return Err(anyhow::anyhow!("No matching self-signed user ID")); } if ambiguous_email { - weprintln!("Use `--userid` with the full user ID, or \ - `--add-userid` to add a new user ID."); + if add_args && ! plain_is_add { + weprintln!("Use `--userid` with the full user ID, or \ + `--add-userid` to add a new user ID."); + } else { + weprintln!("Use `--userid` with the full user ID."); + } return Err(anyhow::anyhow!("\ An email address does not unambiguously designate a \ self-signed user ID")); } if ambiguous_name { - weprintln!("Use `--userid` with the full user ID, or \ - `--add-userid` to add a new user ID."); + if add_args && ! plain_is_add { + weprintln!("Use `--userid` with the full user ID, or \ + `--add-userid` to add a new user ID."); + } else { + weprintln!("Use `--userid` with the full user ID."); + } return Err(anyhow::anyhow!("\ A name does not unambiguously designate a \ self-signed user ID"));