Nothing could change a ticket after it was created. mv wrote status, comment appended a file, and that was the whole set of mutations, so correcting a typo or adding a criterion meant hand editing the markdown. Two commands rather than the one vague "edit" the ticket described. set replaces a field, append adds to a section, so the verb carries the meaning instead of a prefix on seven flag names, and append only offers the three sections that hold multiple lines. Owner is absent from both, it belongs to the chown command filed alongside this, and status stays mv's. One field, one writer. Sections are a table, DESCRIPTION, ACCEPTANCE and PLAN, each carrying a heading, a label, the placeholder add writes when empty, and a kind. Both commands walk it, so a section added later is one entry rather than edits in two places. Everything is targeted line surgery and never a regenerated file, which is what keeps a ticked criterion ticked and a handwritten section intact when an unrelated field changes. Appending to a numbered section continues from the count already there rather than renumbering above it, so a handwritten line survives exactly as written. Appending to an empty section replaces the placeholder instead of following it. An empty value is a paragraph break for a section and a usage error for a scalar, since it looks like a way to clear a field and clearing is not supported yet. No-op detection compares the whole file before and after each edit, so a field set to the value it already holds is reported unchanged and nothing is written. Two things came out of building it. move_ticket_file's staged write is extracted as write_then_replace, now the only way any ticket file is written. And the file is located by uuid rather than by title: titles are not unique, add allows duplicates on purpose, and the old title scan meant mv <uuid-of-second> moved the first ticket sharing its title. Reproduced, fixed, and pinned by a test. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
78 lines
2.3 KiB
Rust
78 lines
2.3 KiB
Rust
use anyhow::Result;
|
|
use clap::Parser;
|
|
|
|
mod command;
|
|
mod handlers;
|
|
mod util;
|
|
|
|
use command::*;
|
|
use handlers::*;
|
|
use util::*;
|
|
|
|
/// Die quietly when stdout is closed early, the way every other Unix tool does.
|
|
///
|
|
/// Rust sets `SIGPIPE` to `SIG_IGN` at startup, which turns a closed pipe into an
|
|
/// io error that `println!` panics on. So `worklane ls | head -3` printed a panic
|
|
/// and a backtrace instead of three lines, which is both alarming and easy to
|
|
/// mistake for a real fault. Restoring the default handler makes `| head` behave.
|
|
///
|
|
/// The cost is that a truncated pipe now kills the process with signal 13 rather
|
|
/// than returning a code, so `pipefail` sees 141 instead of 101. That is what
|
|
/// `head` and `sort` do, and it is recorded in the README.
|
|
fn quiet_broken_pipe() {
|
|
// SAFETY: setting a signal disposition to the default is always valid, and
|
|
// this runs before any thread is spawned.
|
|
unsafe {
|
|
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
|
|
}
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
// Before any output, so no write can beat it to a closed pipe.
|
|
quiet_broken_pipe();
|
|
|
|
let cli = Cli::parse();
|
|
|
|
let start = std::env::current_dir()?;
|
|
|
|
match cli.command {
|
|
Command::Init => cmd_init(&start),
|
|
Command::Add {
|
|
title,
|
|
description,
|
|
acceptance,
|
|
plan,
|
|
tags,
|
|
due,
|
|
owner,
|
|
priority,
|
|
} => cmd_add(
|
|
&title,
|
|
&description,
|
|
&acceptance,
|
|
&plan,
|
|
&tags,
|
|
&due,
|
|
&owner,
|
|
priority,
|
|
&start,
|
|
),
|
|
Command::Ls { status, priority } => {
|
|
let worklane_dir = find_worklane_dir(&start)?;
|
|
cmd_ls(&status, priority, &worklane_dir)
|
|
}
|
|
Command::Show { id } => {
|
|
let worklane_dir = find_worklane_dir(&start)?;
|
|
cmd_show(&id, &worklane_dir)
|
|
}
|
|
Command::Mv {
|
|
ticket,
|
|
status,
|
|
force,
|
|
} => cmd_mv(&ticket, &status, force, &start),
|
|
Command::Set(args) => cmd_set(&args, &start),
|
|
Command::Append(args) => cmd_append(&args, &start),
|
|
Command::Comment { ticket, body, owner } => cmd_comment(&ticket, &body, &owner, &start),
|
|
}
|
|
}
|