cli: Be less confusing when asking for passphrase

The previous error didn't really make sense.
This commit is contained in:
Alexis Sellier 2023-09-02 13:11:01 +02:00 committed by cloudhead
parent 30f2e2260a
commit 5040f33025
No known key found for this signature in database
3 changed files with 8 additions and 9 deletions

View File

@ -178,10 +178,10 @@ pub fn authenticate(options: Options, profile: &Profile) -> anyhow::Result<()> {
); );
let passphrase = if options.stdin { let passphrase = if options.stdin {
term::passphrase_stdin() term::passphrase_stdin()?
} else { } else {
term::passphrase(RAD_PASSPHRASE) term::passphrase(RAD_PASSPHRASE)?
}?; };
register(&mut agent, profile, passphrase)?; register(&mut agent, profile, passphrase)?;
term::success!("Radicle key added to {}", term::format::dim("ssh-agent")); term::success!("Radicle key added to {}", term::format::dim("ssh-agent"));

View File

@ -3,7 +3,6 @@ use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom}; use std::io::{BufRead, BufReader, Read, Seek, SeekFrom};
use std::{process, thread, time}; use std::{process, thread, time};
use anyhow::Context as _;
use localtime::LocalTime; use localtime::LocalTime;
use radicle::node; use radicle::node;
@ -30,10 +29,10 @@ pub fn start(
} }
let envs = if profile.keystore.is_encrypted()? { let envs = if profile.keystore.is_encrypted()? {
// Ask passphrase here, otherwise it'll be a fatal error when running the daemon // Ask passphrase here, otherwise it'll be a fatal error when running the daemon
// without `RAD_PASSPHRASE`. To keep things consistent, we also use this in foreground mode. // without `RAD_PASSPHRASE`.
let passphrase = term::io::passphrase(profile::env::RAD_PASSPHRASE) let Ok(passphrase) = term::io::passphrase(profile::env::RAD_PASSPHRASE) else {
.context(format!("`{}` must be set", profile::env::RAD_PASSPHRASE))?; anyhow::bail!("your radicle passphrase is required to start your node");
};
Some((profile::env::RAD_PASSPHRASE, passphrase)) Some((profile::env::RAD_PASSPHRASE, passphrase))
} else { } else {
None None

View File

@ -199,7 +199,7 @@ where
Ok(value) Ok(value)
} }
pub fn passphrase<K: AsRef<OsStr>>(var: K) -> Result<Passphrase, anyhow::Error> { pub fn passphrase<K: AsRef<OsStr>>(var: K) -> Result<Passphrase, inquire::InquireError> {
if let Ok(p) = env::var(var) { if let Ok(p) = env::var(var) {
Ok(Passphrase::from(p)) Ok(Passphrase::from(p))
} else { } else {