Avoid eprintln in favor of wprintln.

This commit is contained in:
Justus Winter 2024-09-02 12:34:12 +02:00
parent 9a1dee4563
commit 9c4dfdaf11
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
11 changed files with 51 additions and 45 deletions

View File

@ -341,7 +341,7 @@ impl<'c, 'store, 'rstore> DecryptionHelper for Helper<'c, 'store, 'rstore>
});
wprintln!("No key to decrypt message. The message appears \
to be encrypted to:");
eprintln!();
wprintln!();
for recipient in recipients.into_iter() {
let certs = self.sq.lookup(
std::iter::once(KeyHandle::from(recipient)),
@ -354,7 +354,8 @@ impl<'c, 'store, 'rstore> DecryptionHelper for Helper<'c, 'store, 'rstore>
match certs {
Ok(certs) => {
for cert in certs {
eprintln!(" - {}, {}",
wprintln!(initial_indent = " - ",
"{}, {}",
cert.fingerprint(),
self.sq.best_userid(&cert, true));
}
@ -363,16 +364,18 @@ impl<'c, 'store, 'rstore> DecryptionHelper for Helper<'c, 'store, 'rstore>
if let Some(StoreError::NotFound(_))
= err.downcast_ref()
{
eprintln!(" - {}, certificate not found",
wprintln!(initial_indent = " - ",
"{}, certificate not found",
recipient);
} else {
eprintln!(" - {}, error looking up certificate: {}",
wprintln!(initial_indent = " - ",
"{}, error looking up certificate: {}",
recipient, err);
}
}
};
}
eprintln!();
wprintln!();
return
Err(anyhow::anyhow!("No key to decrypt message"));

View File

@ -154,7 +154,7 @@ pub fn encrypt<'a, 'b: 'a>(
"{} is not present on keystore", kh)),
1 => (),
n => {
eprintln!("Warning: {} is present on multiple \
wprintln!("Warning: {} is present on multiple \
({}) devices",
kh, n);
}
@ -177,7 +177,7 @@ pub fn encrypt<'a, 'b: 'a>(
let keyid = KeyID::from(&fpr);
if let Some(msg) = msg {
eprintln!("{}", msg);
wprintln!("{}", msg);
}
loop {
let password = Password::from(rpassword::prompt_password(
@ -200,11 +200,12 @@ pub fn encrypt<'a, 'b: 'a>(
| Ok(Protection::ExternalOther(msg)) =>
{
// Locked.
eprint!("Key is locked");
if let Some(msg) = msg {
eprint!(": {}", msg);
}
eprintln!();
wprintln!("Key is locked{}",
if let Some(msg) = msg {
format!(": {}", msg)
} else {
"".into()
});
}
Err(err) => {
// Failed to get the key's locked status. Just print

View File

@ -121,10 +121,10 @@ pub fn adopt(sq: Sq, mut command: cli::key::AdoptCommand) -> Result<()>
Ok((cert, key, builder)) => Some((cert, key, builder)),
Err(err) => {
if ! missing {
eprintln!("Missing keys:");
wprintln!("Missing keys:");
}
eprintln!(" - {}: {}", id, err);
wprintln!(initial_indent = " - ", "{}: {}", id, err);
missing = true;
None

View File

@ -34,7 +34,8 @@ fn list(sq: Sq, cmd: approvals::ListCommand) -> Result<()> {
let uid_filter = make_userid_filter(
&cmd.names, &cmd.emails, &cmd.userids)?;
for uid in vcert.userids().filter(uid_filter) {
eprintln!("- {}", String::from_utf8_lossy(uid.value()));
wprintln!(initial_indent = " - ", "{}",
String::from_utf8_lossy(uid.value()));
let approved =
uid.attested_certifications().collect::<BTreeSet<_>>();
@ -58,7 +59,7 @@ fn list(sq: Sq, cmd: approvals::ListCommand) -> Result<()> {
}
}
eprintln!(" - {}: {}",
wprintln!(initial_indent = " - ", "{}: {}",
issuer.as_ref()
.and_then(|i| Some(sq.best_userid(i.to_cert().ok()?, true)
.to_string()))
@ -80,7 +81,7 @@ fn list(sq: Sq, cmd: approvals::ListCommand) -> Result<()> {
}
if ! any {
eprintln!(" - no {} certifications",
wprintln!(initial_indent = " - ", "no {} certifications",
if cmd.pending {
"unapproved"
} else {
@ -139,7 +140,8 @@ fn update(
let uid_filter = make_userid_filter(
&command.names, &command.emails, &command.userids)?;
for uid in vcert.userids().filter(uid_filter) {
eprintln!("- {}", String::from_utf8_lossy(uid.value()));
wprintln!(initial_indent = " - ", "{}",
String::from_utf8_lossy(uid.value()));
let previously_approved =
uid.attested_certifications().collect::<BTreeSet<_>>();
@ -223,7 +225,7 @@ fn update(
}
}
eprintln!(" {} {}: {}",
wprintln!(initial_indent = " ", "{} {}: {}",
match (prev, next) {
(false, false) => '.',
(true, false) => '-',
@ -253,7 +255,7 @@ fn update(
}
if ! any {
eprintln!(" no certifications");
wprintln!(" no certifications");
}
attestation_signatures.append(&mut uid.attest_certifications2(

View File

@ -140,7 +140,7 @@ fn authenticate<'store, 'rstore>(
// and thus the authentication confidence must be
// 0, and the certificate should only be shown
// when `--gossip` is passed.
eprintln!("Certificate {} contains the subkey {}.",
wprintln!("Certificate {} contains the subkey {}.",
fpr, kh);
}
certificate_dealiased = Some(KeyHandle::from(&fpr));

View File

@ -96,10 +96,10 @@ impl OutputType for ConciseHumanReadableOutputNetwork<'_, '_, '_> {
.unwrap_or("".to_string());
if ! first_shown {
eprintln!();
wprintln!();
}
eprintln!("{}{}", fingerprint, expired);
wprintln!("{}{}", fingerprint, expired);
}
let revoked = vc
@ -120,7 +120,7 @@ impl OutputType for ConciseHumanReadableOutputNetwork<'_, '_, '_> {
.next()
});
eprintln!(" [ {} ] {}",
wprintln!(initial_indent = " ", "[ {} ] {}",
if revoked.is_some() {
"revoked".to_string()
} else if aggregated_amount >= self.required_amount {

View File

@ -103,7 +103,7 @@ pub fn get_keys<'a>(sq: &'a Sq,
{
ka
} else {
eprintln!("{} does not contain {}",
wprintln!("{} does not contain {}",
cert.fingerprint(), key);
not_found_key_count += 1;
continue;
@ -119,7 +119,7 @@ pub fn get_keys<'a>(sq: &'a Sq,
};
if no_secret_key_material {
eprintln!("{} does not contain any secret key material",
wprintln!("{} does not contain any secret key material",
key);
no_secret_key_material_count += 1;
continue;

View File

@ -82,7 +82,7 @@ pub fn export(sq: Sq,
}
Err(err) => {
if loud {
eprintln!("Exporting {}: {}",
wprintln!("Exporting {}: {}",
key.fingerprint(), err);
}
}

View File

@ -69,7 +69,7 @@ pub fn password(sq: Sq,
if ! unlocked {
if let Some(hint) = hint {
eprintln!("{}", hint);
wprintln!("{}", hint);
}
loop {
@ -83,7 +83,7 @@ pub fn password(sq: Sq,
break;
}
Err(err) => {
eprintln!("Failed to unlock key: {}", err);
wprintln!("Failed to unlock key: {}", err);
}
}
}

View File

@ -138,14 +138,14 @@ pub(crate) fn lint_userids(uids: &[UserID]) -> Result<(), anyhow::Error> {
} else {
if non_canonical.len() == 1 {
wprintln!("{}.", non_canonical[0]);
eprintln!();
wprintln!();
} else {
wprintln!("The following user IDs are not in canonical form:");
eprintln!();
wprintln!();
for err in non_canonical.iter() {
eprintln!(" - {}", err);
wprintln!(initial_indent = " - ", "{}", err);
}
eprintln!();
wprintln!();
}
let bare_email = non_canonical.iter()
@ -169,7 +169,7 @@ pub(crate) fn lint_userids(uids: &[UserID]) -> Result<(), anyhow::Error> {
} else {
"".to_string()
});
eprintln!();
wprintln!();
Err(anyhow::anyhow!("\
Some user IDs are not in canonical form"))
@ -221,14 +221,14 @@ pub fn lint_names(names: &[String]) -> Result<(), anyhow::Error> {
} else {
if non_canonical.len() == 1 {
wprintln!("{}.", non_canonical[0]);
eprintln!();
wprintln!();
} else {
wprintln!("The following names have issues:");
eprintln!();
wprintln!();
for err in non_canonical.iter() {
eprintln!(" - {}", err);
wprintln!(initial_indent = " - ", "{}", err);
}
eprintln!();
wprintln!();
}
Err(anyhow::anyhow!("Some names had issues"))
@ -280,14 +280,14 @@ pub fn lint_emails(emails: &[String]) -> Result<(), anyhow::Error> {
} else {
if non_canonical.len() == 1 {
wprintln!("{}.", non_canonical[0]);
eprintln!();
wprintln!();
} else {
wprintln!("The following email addresses have issues:");
eprintln!();
wprintln!();
for err in non_canonical.iter() {
eprintln!(" - {}", err);
wprintln!(initial_indent = " - ", "{}", err);
}
eprintln!();
wprintln!();
}
Err(anyhow::anyhow!("Some email addresses had issues"))

View File

@ -1271,7 +1271,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
.is_none()
{
if let Some(hint) = hint {
eprintln!("{}", hint);
wprintln!("{}", hint);
}
loop {
@ -1280,7 +1280,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
ka.cert().keyid(), ka.keyid(), uid))?;
if p == "".into() {
eprintln!("Giving up.");
wprintln!("Giving up.");
continue 'key;
}
@ -1290,7 +1290,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
break;
}
Err(err) => {
eprintln!("Failed to unlock key: {}", err);
wprintln!("Failed to unlock key: {}", err);
}
}
}