use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Parser, Debug, Clone)]
#[command(author, version, about)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Args, Debug, Clone)]
pub struct Create {
pub source: Vec<PathBuf>,
#[arg(long, short)]
pub archive: Option<PathBuf>,
#[arg(long, default_value = "false", overrides_with = "_no_follow")]
pub follow: bool,
#[arg(long = "no-follow", default_value = "true")]
pub _no_follow: bool,
#[arg(long = "recursive", default_value = "true")]
_recursive: bool,
#[arg(long, default_value = "false", overrides_with = "_recursive")]
pub no_recursive: bool,
#[arg(long = "preserve", default_value = "true")]
_preserve: bool,
#[arg(long, default_value = "false", overrides_with = "_preserve")]
pub no_preserve: bool,
}
#[derive(Args, Debug, Clone)]
pub struct Extract {
#[arg(default_value = ".")]
pub dest: PathBuf,
#[arg(long, short)]
pub archive: PathBuf,
#[arg(short, long)]
pub source: Vec<PathBuf>,
#[arg(long = "recursive", default_value = "true")]
_recursive: bool,
#[arg(long, default_value = "false", overrides_with = "_recursive")]
pub no_recursive: bool,
}
#[derive(Args, Debug, Clone)]
pub struct Archive {
pub source: PathBuf,
pub dest: Option<PathBuf>,
#[arg(long, short)]
pub archive: PathBuf,
#[arg(long, default_value = "false", overrides_with = "_no_follow")]
pub follow: bool,
#[arg(long = "no-follow", default_value = "true")]
pub _no_follow: bool,
#[arg(long = "recursive", default_value = "true")]
_recursive: bool,
#[arg(long, default_value = "false", overrides_with = "_recursive")]
pub no_recursive: bool,
#[arg(long = "preserve", default_value = "true")]
_preserve: bool,
#[arg(long, default_value = "false", overrides_with = "_preserve")]
pub no_preserve: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum FileType {
File,
Dir,
Symlink,
}
impl From<FileType> for sqlarfs::FileType {
fn from(kind: FileType) -> Self {
match kind {
FileType::File => sqlarfs::FileType::File,
FileType::Dir => sqlarfs::FileType::Dir,
FileType::Symlink => sqlarfs::FileType::Symlink,
}
}
}
#[derive(Args, Debug, Clone)]
pub struct List {
pub parent: Option<PathBuf>,
#[arg(long, short)]
pub archive: PathBuf,
#[arg(long, default_value = "true", conflicts_with = "children")]
pub tree: bool,
#[arg(long, short, default_value = "false", conflicts_with = "tree")]
pub children: bool,
#[arg(long, short, value_enum)]
pub r#type: Option<FileType>,
}
#[derive(Args, Debug, Clone)]
pub struct Remove {
pub path: PathBuf,
#[arg(long, short)]
pub archive: PathBuf,
}
#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
#[command(visible_alias = "c")]
Create(Create),
#[command(visible_alias = "ex")]
Extract(Extract),
#[command(visible_alias = "ar")]
Archive(Archive),
#[command(visible_alias = "ls")]
List(List),
#[command(visible_alias = "rm")]
Remove(Remove),
}