mod command;
use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use tracing_subscriber::{fmt, EnvFilter};
use crate::util::default_data_dir;
use command::Cmd;
#[derive(Parser)]
#[command(
name = "rdrop",
about = "P2P streamed file transfer with ring-based access control.\n\
Built on iroh and bao protocols.",
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::Share) {
"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)?,
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::Share => command::share::run(&data_dir).await?,
Cmd::Receive {
ticket,
dest,
force_overwrite,
} => {
command::receive::run(&ticket, dest, force_overwrite, &data_dir).await?;
}
Cmd::Tag {
target,
rings,
open,
} => {
command::tag::run_tag(target, rings, open, &data_dir).await?;
}
Cmd::Tags { target } => command::tag::run_tags(target, &data_dir).await?,
Cmd::Id => command::id::run(&data_dir)?,
}
Ok(())
}