The Owner field had no writer after `add`. It was folded into `set` in da03690 and comes out here as its own command, so no field is writable from two places, the same reasoning that keeps status in `mv` alone. `worklane chown alice 641e3d5`, user first, after Unix `chown`. That reverses the ticket-first order `mv`, `comment` and `show` use, deliberately: the name borrows the Unix association, so the argument order borrows it too. The swap is left to resolution rather than checked for. Given `chown 641e3d5 alice` the second argument has to resolve as a ticket, and a bare username does not, so the call fails on its own; a check on the first argument would only fire where resolution already refuses and would stay silent on the one case it cannot catch, a ticket whose title is the username. `cmd_chown` is therefore `set_metadata_field` plus `save_ticket`, with the whole-file no-op comparison `set` uses and the same `report()` line, so an owner set to the value it already holds is reported unchanged and nothing is written. Nothing new writes a file: the update goes through `write_then_replace`, scoped to the lines under `## Metadata`, so a description quoting `**Owner**:` is left as prose and a failure leaves the ticket whole. Tested for the change, the no-op, all three resolution tiers, a swapped call, an empty user, a ticket with no Owner field, and that the tick, the handwritten section and the filename all survive. The skill and the opencode tool carry it too, the tool with the argument order in its description, since that is the one place a model can get it wrong without failing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
298 lines
10 KiB
Rust
298 lines
10 KiB
Rust
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<String> = LazyLock::new(priority_legend);
|
|
|
|
/// Reject a level outside the range at parse time, so no command has to.
|
|
fn priority_level(raw: &str) -> Result<u8, String> {
|
|
match raw.parse::<u8>() {
|
|
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<Command>,
|
|
}
|
|
|
|
/// 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<String, String> {
|
|
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<String>,
|
|
|
|
/// Only show tickets at this priority, 1 (most urgent) to 5 (least)
|
|
#[arg(long, value_parser = priority_level)]
|
|
priority: Option<u8>,
|
|
},
|
|
|
|
/// 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),
|
|
|
|
/// Change the owner of a ticket
|
|
///
|
|
/// User first, ticket second, after Unix `chown`. That reverses the ticket-first
|
|
/// order `mv`, `comment` and `show` use, deliberately: the name borrows the Unix
|
|
/// association, so the argument order borrows it too.
|
|
///
|
|
/// A swap is caught by resolution rather than by a check of its own. Given
|
|
/// `chown 641e3d5 alice` the second argument has to resolve as a ticket, and a bare
|
|
/// username usually will not, so the call fails on its own. It is silently wrong
|
|
/// only when both arguments resolve, which needs a ticket whose title matches the
|
|
/// username.
|
|
Chown {
|
|
/// New owner. Free text, like `add --owner`, checked against nothing
|
|
#[arg(value_parser = non_empty)]
|
|
user: String,
|
|
|
|
/// Ticket UUID or title
|
|
ticket: String,
|
|
},
|
|
|
|
/// Open the board view
|
|
Tui {
|
|
/// Projects to monitor, each resolved to the first `.worklane` at or above it.
|
|
/// Several are shown as tabs. Defaults to the working directory
|
|
paths: Vec<std::path::PathBuf>,
|
|
},
|
|
|
|
/// 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<String>,
|
|
},
|
|
|
|
/// 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<String>,
|
|
|
|
/// Acceptance criteria. Accepts multiple flags, each will be interpreted as a single criterium
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub acceptance: Vec<String>,
|
|
|
|
/// Implementation plan. Accepts multiple flags, each will be interpreted as a single step
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub plan: Vec<String>,
|
|
|
|
/// Tags (comma-separated)
|
|
#[arg(short = 'g', long)]
|
|
pub tags: Vec<String>,
|
|
|
|
/// Due date (YYYY-MM-DD)
|
|
#[arg(long)]
|
|
pub due: Option<String>,
|
|
|
|
/// Owner
|
|
#[arg(short, long)]
|
|
pub owner: Option<String>,
|
|
|
|
/// Priority, 1 (most urgent) to 5 (least). Left unset if omitted.
|
|
#[arg(long, value_parser = priority_level)]
|
|
pub priority: Option<u8>,
|
|
}
|
|
|
|
/// `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 <ticket>` 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<String>,
|
|
|
|
/// Replace the description. Repeat the flag for more lines, empty for a paragraph break
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub description: Vec<String>,
|
|
|
|
/// Replace the acceptance criteria. Repeat the flag, one criterium per value
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub acceptance: Vec<String>,
|
|
|
|
/// Replace the implementation plan. Repeat the flag, one step per value
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub plan: Vec<String>,
|
|
|
|
/// Replace the tags
|
|
#[arg(short = 'g', long, value_parser = non_empty)]
|
|
pub tags: Vec<String>,
|
|
|
|
/// Replace the due date (YYYY-MM-DD)
|
|
#[arg(long, value_parser = non_empty)]
|
|
pub due: Option<String>,
|
|
|
|
/// Replace the priority, 1 (most urgent) to 5 (least)
|
|
#[arg(long, value_parser = priority_level)]
|
|
pub priority: Option<u8>,
|
|
}
|
|
|
|
/// `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<String>,
|
|
|
|
/// Add acceptance criteria. Repeat the flag, one criterium per value
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub acceptance: Vec<String>,
|
|
|
|
/// Add implementation plan steps, numbered on from the last. Repeat the flag
|
|
#[arg(short, long, allow_hyphen_values = PROSE)]
|
|
pub plan: Vec<String>,
|
|
}
|
|
|
|
/// `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<String>,
|
|
}
|