use clap::Parser; use std::sync::LazyLock; use crate::util::{PRIORITY_RANGE, priority_legend}; /// clap wants a `&str` with a long enough lifetime, and the legend is built from /// the same ramp the listing uses rather than spelled out a second time. static PRIORITY_LEGEND: LazyLock = LazyLock::new(priority_legend); /// Reject a level outside the range at parse time, so no command has to. fn priority_level(raw: &str) -> Result { match raw.parse::() { Ok(level) if PRIORITY_RANGE.contains(&level) => Ok(level), _ => Err(format!( "priority must be a whole number from {} to {}", PRIORITY_RANGE.start(), PRIORITY_RANGE.end() )), } } /// What `--version` prints: the crate version and the commit it was built from. /// /// The sha is the part that matters. Two binaries built weeks apart both call /// themselves 0.1.0, so without it there is no way to tell whether the copy on /// PATH is the one carrying a given fix. const VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("WORKLANE_GIT_SHA"), ")"); #[derive(Parser)] #[command(name = "worklane")] #[command(about = "A CLI tool for managing project status")] #[command(version = VERSION)] #[command(propagate_version = true)] pub struct Cli { /// Absent opens the board view, the way a bare `frig` does. #[command(subcommand)] pub command: Option, } /// Reject an empty value at parse time, so it lands as a usage error rather than a /// runtime one. /// /// An empty value looks like a way to clear a field, and clearing is not supported /// yet. Refusing it keeps the gap visible and stops an accidentally empty variable /// from silently blanking a field. Only the scalars use this: for the multi-line /// sections an empty value is a paragraph break. fn non_empty(raw: &str) -> Result { if raw.trim().is_empty() { return Err("value cannot be empty, and clearing a field is not supported yet".to_string()); } Ok(raw.to_string()) } /// Arguments that carry prose, and therefore have to accept a value starting with /// a hyphen. /// /// Ticket text quotes flag names constantly, and without this a criterion reading /// "--print is supported" is parsed as a flag and the whole ticket is refused. The /// trade, spelled out in AGENTS.md: on these arguments a genuinely mistyped flag /// now lands as content instead of raising a usage error. That is the right way /// round for prose, and it is why `due`, `priority`, `tags`, `owner` and `status` /// are deliberately left without it. const PROSE: bool = true; #[derive(clap::Subcommand)] pub enum Command { /// Initialize worklane in the current project Init, /// Add a new ticket to the backlog Add(AddArgs), /// List tickets, optionally filtered by status #[command(after_help = PRIORITY_LEGEND.as_str())] Ls { /// Filter by status (backlog, committed, reviewing, done) status: Option, /// Only show tickets at this priority, 1 (most urgent) to 5 (least) #[arg(long, value_parser = priority_level)] priority: Option, }, /// Show a ticket by UUID or title Show { /// Ticket UUID or title to search for id: String, }, /// Move a ticket to a different status Mv { /// Ticket UUID or title ticket: String, /// Target status (backlog, committed, reviewing, done) #[arg(short, long)] status: String, /// Force move (allows backward or non-sequential moves) #[arg(short, long)] force: bool, }, /// Replace fields on an existing ticket Set(SetArgs), /// Add to a section of an existing ticket Append(AppendArgs), /// Open the board view Tui, /// Tick an acceptance criterion Check(CheckArgs), /// Untick an acceptance criterion Uncheck(CheckArgs), /// Add a comment to a ticket Comment { /// Ticket UUID or title ticket: String, /// Comment body (required) #[arg(allow_hyphen_values = PROSE)] body: String, /// Owner #[arg(short, long)] owner: Option, }, /// Install the agent skill that teaches an agent to use worklane InstallSkill { /// Overwrite an existing copy that has been modified #[arg(long)] force: bool, /// Write it to stdout instead of installing it #[arg(long)] print: bool, }, } /// `add` carries every field a new ticket can hold, so it is a struct rather than an /// inline variant: nine parameters at the call site is what `too_many_arguments` is /// for, and `set`, `append` and `check` already pass their arguments this way. /// /// No `ArgGroup`: `--title` is required on its own, and everything else is optional /// because a ticket with only a title is a valid thing to file. #[derive(clap::Args)] pub struct AddArgs { /// Ticket title #[arg(short, long, allow_hyphen_values = PROSE)] pub title: String, /// Ticket description. Use multiple flags to create multiline descriptions. #[arg(short, long, allow_hyphen_values = PROSE)] pub description: Vec, /// Acceptance criteria. Accepts multiple flags, each will be interpreted as a single criterium #[arg(short, long, allow_hyphen_values = PROSE)] pub acceptance: Vec, /// Implementation plan. Accepts multiple flags, each will be interpreted as a single step #[arg(short, long, allow_hyphen_values = PROSE)] pub plan: Vec, /// Tags (comma-separated) #[arg(short = 'g', long)] pub tags: Vec, /// Due date (YYYY-MM-DD) #[arg(long)] pub due: Option, /// Owner #[arg(short, long)] pub owner: Option, /// Priority, 1 (most urgent) to 5 (least). Left unset if omitted. #[arg(long, value_parser = priority_level)] pub priority: Option, } /// `set` replaces a field outright. Owner is deliberately absent: `chown` owns that /// field, and status is `mv`'s, so no field has two writers. /// /// The group makes at least one field mandatory, so a bare `worklane set ` is /// a usage error rather than a silent no-op. #[derive(clap::Args)] #[command(group( clap::ArgGroup::new("set_fields") .required(true) .multiple(true) .args(["title", "description", "acceptance", "plan", "tags", "due", "priority"]) ))] pub struct SetArgs { /// Ticket UUID or title pub ticket: String, /// Replace the ticket title, renaming the file to match #[arg(short, long, allow_hyphen_values = PROSE, value_parser = non_empty)] pub title: Option, /// Replace the description. Repeat the flag for more lines, empty for a paragraph break #[arg(short, long, allow_hyphen_values = PROSE)] pub description: Vec, /// Replace the acceptance criteria. Repeat the flag, one criterium per value #[arg(short, long, allow_hyphen_values = PROSE)] pub acceptance: Vec, /// Replace the implementation plan. Repeat the flag, one step per value #[arg(short, long, allow_hyphen_values = PROSE)] pub plan: Vec, /// Replace the tags #[arg(short = 'g', long, value_parser = non_empty)] pub tags: Vec, /// Replace the due date (YYYY-MM-DD) #[arg(long, value_parser = non_empty)] pub due: Option, /// Replace the priority, 1 (most urgent) to 5 (least) #[arg(long, value_parser = priority_level)] pub priority: Option, } /// `append` only offers the sections that hold multiple lines, since appending to a /// scalar has no meaning. #[derive(clap::Args)] #[command(group( clap::ArgGroup::new("append_fields") .required(true) .multiple(true) .args(["description", "acceptance", "plan"]) ))] pub struct AppendArgs { /// Ticket UUID or title pub ticket: String, /// Add a paragraph to the description. Repeat the flag for more lines within it #[arg(short, long, allow_hyphen_values = PROSE)] pub description: Vec, /// Add acceptance criteria. Repeat the flag, one criterium per value #[arg(short, long, allow_hyphen_values = PROSE)] pub acceptance: Vec, /// Add implementation plan steps, numbered on from the last. Repeat the flag #[arg(short, long, allow_hyphen_values = PROSE)] pub plan: Vec, } /// `check` and `uncheck` are separate commands rather than one verb with a flag, /// because the two read as opposites at the call site and neither needs the other's /// name to make sense. /// /// The criterion is optional: without it the criteria are listed and the index asked /// for, or, where there is no terminal to ask at, returned as an error carrying the /// same list. #[derive(clap::Args)] pub struct CheckArgs { /// Ticket UUID or title pub ticket: String, /// Criterion index as shown by `show`, or a substring of its text. Prompts if omitted pub criterion: Option, }