use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
use crate::explain::Format;
use crate::pulse::HeartbeatOpts;
#[derive(Parser, Debug)]
#[command(
name = "ct-okf",
version,
about = "Author, query, and index Open Knowledge Format bundles across a project's content roots.",
long_about = "ct-okf manages Open Knowledge Format (OKF) knowledge for a project (also reachable \
as `ct okf`). It works over the project's configured content roots and keeps a \
lazily-maintained full-text index so `ct okf search` is always current. Pick a \
subcommand: search/find query, roots/index/init configure, validate/links check, \
show/add/mv/set/log/gen-index/script author. See `ct-okf --explain` for \
agent-oriented documentation."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
#[arg(long, default_value = ".", global = true)]
pub base: PathBuf,
#[arg(long, global = true)]
pub name: Option<String>,
#[arg(long, global = true)]
pub hidden: bool,
#[arg(long, global = true)]
pub follow: bool,
#[arg(long, global = true)]
pub no_ignore: bool,
#[arg(long, global = true)]
pub json: bool,
#[arg(long, global = true)]
pub json_pretty: bool,
#[arg(long, global = true)]
pub quiet: bool,
#[arg(long, value_name = "SECS", global = true)]
pub timeout: Option<f64>,
#[command(flatten)]
pub heartbeat: HeartbeatOpts,
#[arg(long, value_enum, num_args = 0..=1, default_missing_value = "md")]
pub explain: Option<Format>,
}
#[derive(Subcommand, Debug)]
pub enum Command {
Search(SearchArgs),
Find(FindArgs),
Roots(RootsArgs),
Index(IndexArgs),
Init(InitArgs),
Validate(CheckArgs),
Links(CheckArgs),
Show(ShowArgs),
#[command(alias = "new")]
Add(AddArgs),
#[command(alias = "rename")]
Mv(MvArgs),
Set(SetArgs),
Log(LogArgs),
GenIndex(GenIndexArgs),
Script(ScriptArgs),
}
#[derive(Args, Debug, Default)]
pub struct Framing {
#[arg(long)]
pub question: Option<String>,
#[arg(long)]
pub expect: Option<String>,
#[arg(long, alias = "emit-stdout")]
pub emit: Option<String>,
#[arg(long)]
pub emit_stderr: Option<String>,
}
#[derive(Args, Debug)]
pub struct SearchArgs {
#[arg(value_name = "QUERY", required = true)]
pub query: Vec<String>,
#[arg(long, default_value_t = 20)]
pub limit: usize,
#[arg(long = "type", value_name = "TYPE")]
pub type_: Option<String>,
#[arg(long, value_delimiter = ',')]
pub tag: Vec<String>,
}
#[derive(Args, Debug)]
pub struct FindArgs {
#[arg(long = "type", value_name = "TYPE")]
pub type_: Option<String>,
#[arg(long, value_delimiter = ',')]
pub tag: Vec<String>,
}
#[derive(Args, Debug)]
pub struct RootsArgs {
#[command(subcommand)]
pub action: RootsCmd,
}
#[derive(Subcommand, Debug)]
pub enum RootsCmd {
List,
Add {
dir: PathBuf,
#[arg(long)]
marker: bool,
},
Rm {
dir: PathBuf,
},
Scan {
#[arg(long)]
write: bool,
},
}
#[derive(Args, Debug)]
pub struct IndexArgs {
#[command(subcommand)]
pub action: IndexCmd,
}
#[derive(Subcommand, Debug)]
pub enum IndexCmd {
Status,
Update,
Condense,
Rebuild,
}
#[derive(Args, Debug)]
pub struct InitArgs {
#[arg(long)]
pub marker: bool,
}
#[derive(Args, Debug)]
pub struct CheckArgs {
#[arg(long)]
pub strict: bool,
#[command(flatten)]
pub framing: Framing,
}
#[derive(Args, Debug)]
pub struct ShowArgs {
pub path: PathBuf,
}
#[derive(Args, Debug)]
pub struct AddArgs {
pub path: PathBuf,
#[arg(long = "type", value_name = "TYPE")]
pub type_: String,
#[arg(long)]
pub title: Option<String>,
#[arg(long)]
pub description: Option<String>,
#[arg(long, value_delimiter = ',')]
pub tag: Vec<String>,
}
#[derive(Args, Debug)]
pub struct MvArgs {
pub src: PathBuf,
pub dst: PathBuf,
}
#[derive(Args, Debug)]
pub struct SetArgs {
#[arg(value_name = "FIELD=VALUE")]
pub spec: String,
#[arg(long)]
pub file: PathBuf,
}
#[derive(Args, Debug)]
pub struct LogArgs {
#[arg(value_name = "MESSAGE")]
pub message: String,
#[arg(long = "kind", value_name = "LABEL")]
pub kind: Option<String>,
}
#[derive(Args, Debug)]
pub struct GenIndexArgs {
#[arg(long)]
pub scaffold: bool,
}
#[derive(Args, Debug)]
pub struct ScriptArgs {
pub path: PathBuf,
#[arg(long)]
pub dry_run: bool,
#[arg(long, value_name = "STR")]
pub fence: Option<String>,
}