Make `Profile::init` more flexible
Allow passing a custom home. Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
66d1f99a1e
commit
fd936becf1
|
|
@ -4,6 +4,7 @@ use std::ffi::OsString;
|
|||
use anyhow::anyhow;
|
||||
|
||||
use radicle::crypto::ssh;
|
||||
use radicle::profile;
|
||||
use radicle::Profile;
|
||||
|
||||
use crate::git;
|
||||
|
|
@ -76,9 +77,10 @@ pub fn init(options: Options) -> anyhow::Result<()> {
|
|||
term::blank();
|
||||
}
|
||||
|
||||
let home = profile::home()?;
|
||||
let passphrase = term::read_passphrase(options.stdin, true)?;
|
||||
let spinner = term::spinner("Creating your 🌱 Ed25519 keypair...");
|
||||
let profile = Profile::init(passphrase.as_str())?;
|
||||
let profile = Profile::init(home, passphrase.as_str())?;
|
||||
spinner.finish();
|
||||
|
||||
term::success!(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use radicle::profile;
|
||||
use radicle::profile::{Error, Profile};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let profile = match Profile::load() {
|
||||
Ok(profile) => profile,
|
||||
Err(Error::NotFound(_)) => Profile::init("radicle")?,
|
||||
Err(Error::NotFound(_)) => Profile::init(profile::home()?, "radicle")?,
|
||||
Err(err) => anyhow::bail!(err),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -57,11 +57,9 @@ pub struct Profile {
|
|||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn init(passphrase: &str) -> Result<Self, Error> {
|
||||
let home = self::home()?;
|
||||
pub fn init(home: impl AsRef<Path>, passphrase: &str) -> Result<Self, Error> {
|
||||
let home = home.as_ref().to_path_buf();
|
||||
let storage = Storage::open(&home.join("storage"))?;
|
||||
// TODO: This should generate a keypair at the given location.
|
||||
// For now, we use ssh-keygen?
|
||||
let keystore = Keystore::new(&home.join("keys"));
|
||||
let public_key = keystore.init("radicle", passphrase)?;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue