`cargo clippy --all-targets` was reporting 96 warnings, 14 of them in the binary. It is now clean from a cold cache, and the 211 tests still pass. `clippy --fix` took the mechanical ones: needless borrows, `map_or` that is `is_some_and`, `push_str` of a single character, manual `split_once`, and `&PathBuf` parameters in the test fixtures. It also moved the `handlers.rs` test module to the end of the file, which is what `items_after_test_module` was pointing at. Three by hand. `cmd_add` took nine parameters threaded from `main`, and now takes `AddArgs`, which is how `set`, `append` and `check` already pass theirs; the handler destructures it so the body reads as before, and `add --help` is unchanged. The collapsed `if` in `content_trim` needed reindenting, since `--fix` left its body at the old depth. And the two `split_once` rewrites read as `.split_once(..).map(|(_, value)| value)` rather than clippy's `.map(|x| x.1)`. The two eight-argument `create_ticket` test fixtures keep an `allow(too_many_arguments)` carrying the reason: the lint is right that twenty-five positional call sites read as a wall of strings, but replacing them with a named-field struct is a refactor and not a warning sweep. a34a316 tracks it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
274 lines
8.9 KiB
Rust
274 lines
8.9 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),
|
|
|
|
/// 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<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>,
|
|
}
|