use std::path::PathBuf;
use anyhow::Result;
use clap::{ArgGroup, Subcommand};
use iroh_blobs::{BlobFormat, Hash};
use crate::core::Node;
pub mod blob;
pub mod id;
pub mod receive;
pub mod ring;
pub mod share;
pub mod tag;
#[derive(Subcommand)]
pub enum Cmd {
#[command(subcommand)]
Ring(RingCmd),
#[command(subcommand)]
Blob(BlobCmd),
Import {
path: PathBuf,
#[arg(long = "ring", conflicts_with = "open")]
rings: Vec<String>,
#[arg(long, conflicts_with = "rings")]
open: bool,
},
Share,
Receive {
ticket: String,
#[arg(long, default_value = ".")]
dest: PathBuf,
#[arg(long)]
force_overwrite: bool,
},
#[command(group(ArgGroup::new("access").required(true).args(["rings", "open"])))]
Tag {
target: String,
#[arg(long = "ring", conflicts_with = "open")]
rings: Vec<String>,
#[arg(long, conflicts_with = "rings")]
open: bool,
},
Tags {
target: String,
},
Id,
}
#[derive(Subcommand)]
pub enum BlobCmd {
Import {
path: PathBuf,
#[arg(long = "ring", conflicts_with = "open")]
rings: Vec<String>,
#[arg(long, conflicts_with = "rings")]
open: bool,
},
Remove {
target: String,
},
List,
}
#[derive(Subcommand)]
pub enum RingCmd {
New {
name: String,
},
List,
Add {
ring: String,
#[arg(value_name = "PEER-ID")]
peer: String,
#[arg(long)]
nickname: Option<String>,
},
Remove {
ring: String,
#[arg(value_name = "PEER-ID")]
peer: String,
},
Members { ring: String },
}
async fn import_path(node: &Node, path: &std::path::Path) -> Result<(Hash, BlobFormat)> {
if path.is_dir() {
node.import_directory(path).await
} else {
node.import_file(path).await
}
}