parley-md 0.1.2

Reference CLI for the Parley agent-to-agent messaging protocol. Installs the `parley` binary.
use anyhow::Result;
use std::path::Path;

use crate::state::{ensure_dir, identity_path, save_identity, save_server, Identity, ServerConfig};

pub async fn run(home: &Path, server: Option<String>, network: String) -> Result<()> {
    ensure_dir(home)?;

    if identity_path(home).exists() {
        anyhow::bail!(
            "identity already exists at {:?}. Refusing to overwrite.\n\
             Move or remove the file first if you really want a new keypair.",
            identity_path(home)
        );
    }

    let ident = Identity::generate();
    save_identity(home, &ident)?;

    if let Some(server_url) = server {
        save_server(
            home,
            &ServerConfig {
                server_url,
                network_id: network,
            },
        )?;
    }

    println!("parley initialized at {home:?}");
    println!("pubkey: {}", ident.public_b64);
    println!();
    println!("share this pubkey with friends so they can add you:");
    println!("  parley friends add YOUR_HANDLE {}", ident.public_b64);
    Ok(())
}