use clap::{Parser, ValueEnum};
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum OutputFormat {
Human,
Json,
}
#[derive(Parser)]
#[command(name = "pkq", author, version, about = "跨发行版 Linux 软件包查询工具")]
pub struct Cli {
#[arg(short, long, global = true, value_enum, default_value_t = OutputFormat::Human, help = "输出格式")]
pub output: OutputFormat,
#[arg(
long,
global = true,
help = "JSON 输出压缩为单行(默认美化缩进)/ Compact single-line JSON"
)]
pub compact: bool,
#[arg(
short = 'v',
long,
global = true,
action = clap::ArgAction::Count,
help = "增加日志详细度(-v DEBUG,-vv TRACE)/ Increase log verbosity"
)]
pub verbose: u8,
#[arg(long, global = true, help = "强制刷新仓库元数据缓存")]
pub refresh: bool,
#[arg(long, global = true, help = "离线模式,仅使用本地缓存")]
pub offline: bool,
#[arg(
long,
global = true,
default_value_t = 86400,
help = "缓存 TTL(秒,默认 86400)"
)]
pub cache_ttl: u64,
#[arg(
long,
global = true,
help = "兼容模式:无论结果如何均以 0 退出(v0.1 行为)"
)]
pub legacy_exit_code: bool,
#[command(subcommand)]
pub command: Commands,
}
#[derive(clap::Subcommand)]
pub enum Commands {
#[command(name = "info")]
Info {
name: String,
#[arg(long, help = "查询仓库而非本地已安装")]
repo: bool,
},
#[command(name = "list")]
List {
name: String,
#[arg(long, help = "查询仓库")]
repo: bool,
#[arg(short = 'a', long, help = "显示包含公共目录的完整列表")]
all: bool,
},
#[command(name = "owns")]
Owns {
path: String,
#[arg(long, help = "在仓库中查找")]
repo: bool,
#[arg(
short = 'a',
long,
help = "展示全部结果,不限流 / Show all results without truncation"
)]
all: bool,
},
#[command(name = "deps")]
Deps {
name: String,
#[arg(long, help = "查询仓库")]
repo: bool,
},
#[command(name = "rdeps")]
RDeps {
name: String,
#[arg(
long,
help = "仅查询仓库中的反向依赖",
conflicts_with = "installed_only"
)]
repo: bool,
#[arg(long, help = "仅显示本地已安装的反向依赖")]
installed_only: bool,
#[arg(
short = 'a',
long,
help = "展示全部结果,不限流 / Show all results without truncation"
)]
all: bool,
},
#[command(name = "search")]
Search {
pattern: String,
#[arg(long, help = "使用正则表达式匹配 / Use regex matching")]
regex: bool,
#[arg(
long,
help = "仅搜索包名和描述,跳过文件索引 / Search names and descriptions only, skip file index"
)]
names_only: bool,
#[arg(long, help = "仅搜索文件路径 / Search file paths only")]
files_only: bool,
#[arg(
short = 'a',
long = "all",
alias = "all-files",
help = "展示全部结果,不限流 / Show all results without truncation"
)]
all_files: bool,
#[arg(
long,
help = "每包最大文件结果条数(默认 5,0=不限) / Max file results per package (default 5, 0=unlimited)",
default_value_t = 5
)]
max_files: usize,
#[arg(
short = 'i',
long = "installed",
alias = "installed-only",
help = "仅显示本地已安装的包 / Show only locally installed packages"
)]
installed: bool,
#[arg(long, help = "搜索仓库 / Search repository")]
repo: bool,
},
#[command(name = "source")]
Source {
name: String,
#[arg(long, help = "查询仓库")]
repo: bool,
},
#[command(name = "changelog")]
Changelog {
name: String,
#[arg(long, help = "查询仓库")]
repo: bool,
},
#[command(name = "cache")]
Cache {
#[command(subcommand)]
cmd: CacheCmd,
},
}
#[derive(clap::Subcommand)]
pub enum CacheCmd {
#[command(name = "status")]
Status,
#[command(name = "update")]
Update,
#[command(name = "clean")]
Clean {
#[arg(default_value = "all")]
target: String,
#[arg(long, help = "跳过确认直接删除")]
yes: bool,
},
}