mod command;
use std::path::PathBuf;
const ABOUT: &str = "P2P streamed file transfer with ring-based access control.\n\
Built on iroh and bao protocols.";
const LONG_ABOUT: &str = concat!(
"P2P streamed file transfer with ring-based access control.\n",
"Built on iroh and bao protocols.\n\n",
"Full CLI reference: https://github.com/rikettsie/ringdrop/blob/v",
env!("CARGO_PKG_VERSION"),
"/docs/cli.md"
);
use anyhow::Result;
use clap::Parser;
use tracing_subscriber::{fmt, EnvFilter};
use crate::util::default_data_dir;
use command::{Cmd, DaemonCmd};
#[derive(Parser)]
#[command(
name = "rdrop",
about = ABOUT,
long_about = LONG_ABOUT,
version
)]
struct Cli {
#[arg(long, env = "RINGDROP_DATA_DIR")]
data_dir: Option<PathBuf>,
#[command(subcommand)]
command: Cmd,
}
pub async fn run() -> Result<()> {
let cli = Cli::parse();
let default_filter = if matches!(cli.command, Cmd::Daemon(DaemonCmd::Run)) {
"ringdrop=info,iroh_rings=info"
} else {
"warn"
};
fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(default_filter)),
)
.with_target(false)
.compact()
.init();
let data_dir = cli.data_dir.unwrap_or_else(default_data_dir);
match cli.command {
Cmd::Ring(cmd) => command::ring::run(cmd, &data_dir).await?,
Cmd::Peer(cmd) => command::peer::run(cmd, &data_dir).await?,
Cmd::Blob(cmd) => command::blob::run(cmd, &data_dir).await?,
Cmd::Import { path, rings, open } => {
command::blob::run_import(path, rings, open, &data_dir).await?;
}
Cmd::Daemon(cmd) => match cmd {
DaemonCmd::Start => command::daemon::run_start(&data_dir).await?,
DaemonCmd::Stop => command::daemon::run_stop(&data_dir).await?,
DaemonCmd::Status => command::daemon::run_status(&data_dir).await?,
DaemonCmd::Run => command::daemon::run_serve(&data_dir).await?,
},
Cmd::Receive {
ticket,
dest,
force_overwrite,
} => {
command::receive::run(&ticket, dest, force_overwrite, &data_dir).await?;
}
Cmd::Grant(cmd) => command::grant::run(cmd, &data_dir).await?,
Cmd::Remote(cmd) => command::remote::run(cmd, &data_dir).await?,
Cmd::Id => command::id::run(&data_dir).await?,
Cmd::Info { ticket } => command::info::run(&ticket)?,
}
Ok(())
}