use crate::lens;
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
pub enum Format {
#[default]
Text,
Json,
}
impl Format {
pub(super) fn is_json(self) -> bool {
self == Self::Json
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
pub enum Depth {
#[default]
Rule,
Why,
All,
}
impl From<Depth> for lens::Depth {
fn from(d: Depth) -> Self {
match d {
Depth::Rule => Self::Rule,
Depth::Why => Self::Why,
Depth::All => Self::All,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)]
pub enum Verdict {
Kept,
Reverted,
Failed,
}
impl Verdict {
pub(super) fn is_kept(self) -> bool {
self == Self::Kept
}
}
#[derive(Args, Debug, Default)]
pub struct FormatArg {
#[arg(long, value_enum, default_value_t)]
pub format: Format,
}
#[derive(Args, Debug, Default)]
pub struct At {
pub at: Option<String>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)]
pub enum Shell {
Bash,
Zsh,
Fish,
Elvish,
Powershell,
}
impl From<Shell> for clap_complete::Shell {
fn from(s: Shell) -> Self {
match s {
Shell::Bash => Self::Bash,
Shell::Zsh => Self::Zsh,
Shell::Fish => Self::Fish,
Shell::Elvish => Self::Elvish,
Shell::Powershell => Self::PowerShell,
}
}
}
#[derive(Parser, Debug)]
#[command(
name = "sherd",
version,
about = "federated SPEC.md for small-context local models",
long_about = None,
override_help = super::USAGE,
)]
pub struct Cli {
#[arg(short, long, global = true)]
pub verbose: bool,
#[command(subcommand)]
pub cmd: Option<Cmd>,
}
#[derive(Subcommand, Debug)]
pub enum Cmd {
Init {
dir: Option<String>,
#[arg(long)]
stdout: bool,
},
Budget {
dir: Option<String>,
#[command(flatten)]
format: FormatArg,
},
Lens {
dir: String,
#[arg(long, value_enum, default_value_t)]
depth: Depth,
},
Fed { dir: Option<String> },
Check {
dir: Option<String>,
#[command(flatten)]
format: FormatArg,
},
Debt {
#[command(flatten)]
at: At,
#[arg(long, conflicts_with = "record")]
check: bool,
#[arg(long)]
record: bool,
},
Coverage {
#[command(flatten)]
at: At,
#[arg(long, conflicts_with = "record")]
check: bool,
#[arg(long)]
record: bool,
},
Validate {
#[command(flatten)]
at: At,
#[command(flatten)]
format: FormatArg,
},
Split {
dir: Option<String>,
#[arg(long)]
apply: bool,
},
Seam { dir: Option<String> },
Wave {
dir: Option<String>,
#[command(flatten)]
format: FormatArg,
},
Adopt {
dir: String,
#[arg(long, value_name = "FILE")]
map: Option<String>,
#[arg(long)]
check: bool,
},
Sync {
dir: Option<String>,
#[arg(long)]
check: bool,
},
Route {
query: String,
#[command(flatten)]
at: At,
},
Review {
rev: Option<String>,
#[command(flatten)]
at: At,
},
Slice {
#[command(flatten)]
at: At,
#[arg(long, conflicts_with = "list")]
check: bool,
#[arg(long)]
list: bool,
},
Outcome {
node: String,
#[arg(value_enum)]
verdict: Verdict,
#[command(flatten)]
at: At,
},
Graph {
#[arg(long, group = "form")]
tree: bool,
#[arg(long, group = "form")]
table: bool,
#[arg(long, group = "form")]
dot: bool,
#[arg(long, group = "form")]
mermaid: bool,
#[command(flatten)]
at: At,
},
Plan {
#[command(flatten)]
at: At,
#[command(flatten)]
format: FormatArg,
#[arg(long, conflicts_with = "milestone")]
triage: bool,
#[arg(long, value_name = "M")]
milestone: Option<String>,
},
Apply {
#[command(flatten)]
at: At,
#[arg(long)]
land: bool,
#[arg(long)]
push: bool,
},
Land {
#[command(flatten)]
at: At,
#[arg(long)]
push: bool,
},
Ask { dir: String, question: String },
Tdd {
dir: String,
invariant: String,
task: String,
},
Oneshot {
dir: String,
invariant: String,
task: String,
},
Completions {
#[arg(value_enum)]
shell: Shell,
},
Man,
}
#[must_use]
pub(super) fn command() -> clap::Command {
Cli::command()
}
#[cfg(test)]
#[path = "tests/parse.rs"]
mod tests;