Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
634a1f44c4 |
Generated
+1
-1
@@ -1563,7 +1563,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.33.5"
|
||||
version = "0.33.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.33.5"
|
||||
version = "0.33.6"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -21,7 +21,7 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
| `worklane campaign add` | Files a campaign in `.worklane/campaigns/` with `--title`, `--description`, `--codename` and `--owner`. A campaign has no status: its state is derived, open until every member is done. `--codename` is one word to call it by, `v1` or `beaver`, which is what the board draws on every card in it and what every command that takes a campaign will also resolve it by |
|
||||
| `worklane campaign set <campaign>` | Replaces `--title`, which renames the file keeping the uuid, `--description` and `--codename`. At least one required. The way a campaign filed before codenames existed gets one, and the way a description filed with a typo in it gets fixed. Replacing a codename the campaign already has needs `--force`, since that is the word it is referred to by everywhere; setting the one it already has is a no-op either way. A description needs no `--force`: it is prose written to be revised. No `--clear` and no `--owner` |
|
||||
| `worklane campaign append <campaign>` | Adds a paragraph to a campaign's description with `--description`, which is required. The other half of `campaign set --description`, so adding a line to a description does not mean retyping the rest of it. Repeat the flag for more lines within the one paragraph. Its own subcommand rather than the top-level `append`, which resolves a ticket |
|
||||
| `worklane campaign ls` | Lists the campaigns as their short id, their codename, their title, how many members are done, and the state that count derives: `[open]` until every member is done and `[done]` after. A campaign nothing has been filed against reads `no members` and carries no state, being neither. `--ids` prints one per line as the id, a tab and the title, unstyled and without the counts, which read every ticket on the board, for a script or a completion |
|
||||
| `worklane campaign ls` | Lists the campaigns as a table: when each was created, its short id, its codename, its title, how many members are done, and the state that count derives: `[open]` until every member is done and `[done]` after. A campaign nothing has been filed against reads `no members` and carries no state, being neither. The columns are padded to the widest value in each, so the rows line up whatever the titles are, and the codename is measured with the title rather than given a column of its own, since a campaign filed without one spends nothing on it. `--state` lists only the campaigns in one state, `open`, `done` or `empty` for one nothing has been filed against, and says so by name when nothing matches. `--ids` prints one per line as the id, a tab and the title, unstyled and without the counts, which read every ticket on the board, for a script or a completion; `--state` applies there too, and is the only thing that makes that path count members |
|
||||
| `worklane campaign show <campaign>` | Shows a campaign and its members grouped by status, done included, since what is finished against what is left is the question a campaign asks |
|
||||
| `worklane assign <campaign> <ticket>` | Puts a ticket in a campaign, the only command that writes the Campaign field. Campaign first and ticket second, after `chown`. A ticket is in at most one, so assigning one that already belongs somewhere moves it |
|
||||
| `worklane tags` | Lists the tags the board carries as the tag, a tab and how many tickets carry it, one per line, unstyled and alphabetical. Case sensitive like `ls --tag`, so `bug` and `Bug` list separately and land next to each other. Every status, done included. The one command that answers what tags exist rather than what carries a tag already known |
|
||||
|
||||
@@ -168,6 +168,7 @@ fields; a goal is a campaign.
|
||||
|
||||
```
|
||||
worklane campaign ls
|
||||
worklane campaign ls --state empty # filed against nothing, which is the one to ask about
|
||||
worklane campaign show v1
|
||||
worklane campaign add --title "..." --codename v1 --description "..."
|
||||
worklane campaign set v1 --title "..." # or --description or --codename, on one already filed
|
||||
@@ -183,6 +184,12 @@ tui is usable on a narrow terminal" is a campaign. "The tui tickets" is a tag.
|
||||
them in a container says nothing that the tag did not already say.
|
||||
- **Check what exists first.** `campaign ls` before proposing a new one, or you will
|
||||
propose a second container for a goal that already has one.
|
||||
- **`--state empty` finds the containers nothing was ever filed against.** A campaign with
|
||||
no members is neither open nor done, so it is invisible to `--state open` and reads as
|
||||
just another row in the full listing. Either the tickets for that goal exist and were
|
||||
never assigned to it, which is an `assign` away, or the goal is one nobody is working,
|
||||
which is worth saying out loud. A campaign cannot be discarded, so an empty one stays on
|
||||
the board until it has members.
|
||||
- **A ticket is in at most one campaign**, and `assign` moves it rather than adding a
|
||||
second. So two proposed campaigns that overlap are really one proposal to take members
|
||||
out of the other, and it has to say so.
|
||||
|
||||
@@ -302,6 +302,7 @@ there is no such thing as a done campaign holding an open ticket.
|
||||
worklane campaign add --title "First public release" --codename v1 \
|
||||
--description "Everything that has to ship before the tag."
|
||||
worklane campaign ls # every campaign, its codename, how far it has got
|
||||
worklane campaign ls --state open # only the ones with work left: open, done, empty
|
||||
worklane campaign ls --ids # id and title, tab separated, like ls --ids
|
||||
worklane campaign show v1 # its body, then its members by status
|
||||
worklane campaign set v1 --title "..." # replace the title, description or codename
|
||||
|
||||
+8
-1
@@ -726,8 +726,14 @@ export const campaign_append = tool({
|
||||
|
||||
export const campaign_ls = tool({
|
||||
description:
|
||||
"List campaigns with how far each has got: id, codename or title, owner, and done members against total. Open until every member is done or discarded.",
|
||||
"List campaigns with how far each has got: created, id, codename or title, and done members against total. Open until every member is done or discarded.",
|
||||
args: {
|
||||
state: tool.schema
|
||||
.enum(["open", "done", "empty"])
|
||||
.describe(
|
||||
"Only campaigns in this state. A campaign with no members is neither open nor done, which is what 'empty' reaches.",
|
||||
)
|
||||
.optional(),
|
||||
ids: tool.schema
|
||||
.boolean()
|
||||
.describe("Print only id and title, tab separated, one per line, for parsing.")
|
||||
@@ -735,6 +741,7 @@ export const campaign_ls = tool({
|
||||
},
|
||||
async execute(args: Record<string, any>, context: ToolContext) {
|
||||
const cmd = ["campaign", "ls"];
|
||||
if (args.state) cmd.push("--state", String(args.state));
|
||||
if (args.ids) cmd.push("--ids");
|
||||
try {
|
||||
return await run(cmd, context);
|
||||
|
||||
@@ -14,6 +14,11 @@ The container that groups tickets across the flow, and why its state is derived.
|
||||
- **`Resolved` carries what `content_trim` cannot render from the file.** The relations block and the campaign cell both come from elsewhere on the board. A struct rather than two more parameters, so the next such field is one entry here instead of an edit at every call site
|
||||
- `campaign show` lists **done** members, unlike `ls`, which leaves the done column out of its listing. What is finished against what is left is the whole question a campaign asks, so hiding half the answer is not an option. `ls --campaign` is the other way round: it is the ordinary board filtered, and keeps every rule `ls` already has
|
||||
- `campaign ls` scans the status directories **once per campaign** to count members. That is a scan per row rather than one walk reused, and it is deliberate: the map-from-uuid version is worth writing when a board has enough campaigns to notice
|
||||
- **`campaign ls --state` filters on `Standing::state()`, never on the counters.** The derived value has one definition, so a campaign reads `[open]` in the listing if and only if `--state open` lists it. `--state` and not `--status`: the word names one of the five ticket statuses everywhere else in the tool, and a campaign sits in no status directory. The third value is `empty`, matching the `None` an empty campaign derives, because a filter that could not reach those would leave "what has been filed and forgotten" answerable only by reading the whole listing. A filter that matches nothing says so and repeats the value back, since a silent listing reads as the other empty case, a board with no campaigns on it
|
||||
- **The filter reaches `--ids` as well, and is the only thing that makes that path count members.** `ls --ids` keeps its own filters, so this one keeps its. An unfiltered completion is as cheap as it was: `kept` returns true without reading a ticket when there is no filter to answer
|
||||
- **The listing is a table, measured on the raw values and padded before anything is painted**, the rule `metadata_cells` follows. A column sized on a painted value counts its escape sequences towards its width, which is what tilts a table when colour is on and leaves it straight when it is off — the one combination an integration test running through a pipe can never see, which is why `the_campaign_table_stands_in_the_same_columns_coloured_or_not` renders both ways in one process and compares them with the escapes taken back off
|
||||
- **The codename is measured with the title rather than given a column of its own.** A campaign filed without one spends nothing on it, so a column for it would be a column most rows pad into and some rows leave empty. What a reader lines up is where one campaign's name ends and its progress begins, which is one field: the name is the codename and the title together
|
||||
- **The created stamp is `format_created_at`'s, the same form `ls` prints**, rather than a second spelling of a date. An unparseable one is empty there and the column goes, exactly as it does for a ticket
|
||||
- **The TUI got a card label and a frame, not a campaign tab.** 61879a4 decided it. A tab would have had to answer what its columns are, and a campaign groups *across* the flow rather than within one status, so the honest answer is the four statuses filtered — which is a filter on the board it already has rather than a fifth tab. So: a label on the card, a frame above the columns while one is selected, and `c` for the picker. The cost the earlier decision balked at, a campaigns read per reload, is paid once per project in `columns_of` and is what names the label; see [The Board View](tui-board.md)
|
||||
- **A campaign is named by its codename on the board, and by its short id when it has none.** The uuid does not fit on a card and the title is a sentence, which is the gap `Codename` fills. `campaign_label` builds it in one place, as a `Cell`, so the CLI paints it and the board makes a span of it; the mark is `CAMPAIGN_MARK`, `~`, beside `#` for a tag
|
||||
- **`campaign set` and `campaign append` are the only writers of a filed campaign's fields.** d637288 decided the command: a `set` rather than a flag on something narrower, because the file has more than one editable thing and the moment somebody wants to fix a typo in a title there would be a second command to design. `set` carries `--title`, which renames the file the way `set --title` does, `--description` and `--codename`; `append` carries `--description` alone. `campaign add` writing a field at creation is not a second writer, exactly as `add --title` and `set --title` coexist
|
||||
|
||||
@@ -18,6 +18,7 @@ The generated half, the fish half, and what keeps the two honest.
|
||||
- **A `ValueEnum` is never listed twice, and `argument_at` is why the fish half's two hand-written value lists are the only ones.** clap emits the possible values of an *option*, so `mv --status` and `set --clear` need nothing here and the board reads them off the same definition with `Arg::get_possible_values`. The `ls` status and the `completions` shell are positionals, which the fish generator emits nothing for, so those two are written into the block from the enums — and the board reaches them through `get_positionals`, which needs no `Command::build` the way `get_index` would
|
||||
- **`RELATION_KIND_FLAGS` is the one position clap cannot answer for.** `relate --clear` takes a kind and then a target, two values of different kinds under one flag, so possible values on it would refuse every target. Both renderers therefore say so themselves: the fish rule lists `RelationKind::ALL` and the table names the pair
|
||||
- **`ls --ids` is the machine-readable listing**, and one of the three outputs in the tree meant to be parsed: the short id, a tab, the title, unstyled. Two fields because fish reads what follows a tab as the description and a script reads `cut -f1`. It includes done, which the decorated listing leaves out, because a completion has to be able to name a finished ticket, and it skips a missing status directory rather than refusing, because an error printed over a shell prompt is worse than no candidates. The filters still apply, and an unknown `--campaign` is still refused
|
||||
- **A flag's possible values are read off the command that *holds* the flag, nested or not.** `argument_at` resolves the group's child when the second word names one, so `campaign ls --state` reaches `ls`'s own arguments rather than `campaign`'s, which carry no such flag. Without that the prompt offered nothing where fish offered the three values, and the promise that a `ValueEnum` added anywhere is typeable on the board the day it is added held only for a top-level command
|
||||
- **`campaign ls --ids` is the same flag and the same two fields for the other object**, and it deliberately skips the member counting the decorated listing does: `members()` reads every ticket on the board, and the caller here is a shell filling in candidates on a keypress. It also prints nothing on an empty board, where the decorated listing prints a sentence, because a sentence offered as a candidate is worse than no candidates
|
||||
- **`worklane tags` is the third, and it is a command rather than a mode on `ls`.** Two reasons: `ls --tag <tag>` answers what carries a tag and cannot answer what tags exist, which is the question a grooming sweep starts from, and a `--tags` beside a `--tag` is one letter from a filter that means something else. Alphabetical and case sensitive, matching the filter, so `bug` and `Bug` list separately and land next to each other, which is where a near-duplicate is spotted. Every status, done included: a tag that has fallen out of use is still part of what the vocabulary has been. `assets/PLAN.md` used to tell the agent to count tags with a `show` per ticket, and now points here
|
||||
|
||||
|
||||
+55
-1
@@ -238,6 +238,13 @@ pub fn members(worklane_dir: &Path, uuid: &str) -> Result<Vec<(&'static str, Vec
|
||||
Ok(grouped)
|
||||
}
|
||||
|
||||
/// A campaign with work outstanding, beside [`DONE`] for one with none left.
|
||||
///
|
||||
/// Not a [`Status`]: no ticket is ever in it and no directory is named for it. It is the
|
||||
/// campaign's own two-word vocabulary, and it is a const because the listing prints it,
|
||||
/// [`Standing::state`] derives it and [`CampaignState`] filters on it.
|
||||
pub const OPEN: &str = "open";
|
||||
|
||||
/// How far a campaign has got: members done against members held.
|
||||
///
|
||||
/// `Copy` because the board carries one on every `CampaignRow`, settled at reload: two
|
||||
@@ -282,7 +289,54 @@ impl Standing {
|
||||
match (self.total, self.done == self.total) {
|
||||
(0, _) => None,
|
||||
(_, true) => Some(DONE),
|
||||
(_, false) => Some("open"),
|
||||
(_, false) => Some(OPEN),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The state a campaign is in, as `campaign ls --state` accepts it.
|
||||
///
|
||||
/// A `ValueEnum` for the reason [`Status`] is one: an unknown value is clap's to refuse
|
||||
/// at parse time with the three listed, no handler has to check, and every shell that
|
||||
/// completes possible values gets them for free.
|
||||
///
|
||||
/// `--state` and not `--status`, which names one of the five ticket statuses everywhere
|
||||
/// else in the tool. A campaign sits in no status directory, and borrowing the word for
|
||||
/// a different vocabulary is how a reader comes to type `--status backlog` here.
|
||||
///
|
||||
/// `Empty` is the third value because [`Standing::state`] answers `None` for a campaign
|
||||
/// nothing has been filed against, deliberately, and a filter that could not reach those
|
||||
/// would leave the one question a grooming sweep asks — what has been filed and forgotten
|
||||
/// — answerable only by reading the whole listing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
|
||||
pub enum CampaignState {
|
||||
/// Holds members, and at least one of them is not finished
|
||||
Open,
|
||||
/// Holds members, and every one of them is done or discarded
|
||||
Done,
|
||||
/// Holds no members at all, so it is neither open nor done
|
||||
Empty,
|
||||
}
|
||||
|
||||
impl CampaignState {
|
||||
/// The value as it is typed, which is what a message naming the filter repeats back.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Open => OPEN,
|
||||
Self::Done => DONE,
|
||||
Self::Empty => "empty",
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a campaign in this standing is the one the filter asked for.
|
||||
///
|
||||
/// Matched against [`Standing::state`] rather than against the counters, so the
|
||||
/// derived value has one definition: a campaign reads `[open]` in the listing if and
|
||||
/// only if `--state open` lists it.
|
||||
pub fn holds(self, standing: &Standing) -> bool {
|
||||
match self {
|
||||
Self::Empty => standing.state().is_none(),
|
||||
wanted => standing.state() == Some(wanted.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::sync::LazyLock;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
use crate::campaign::CampaignState;
|
||||
use crate::util::{Clearable, PRIORITY_RANGE, RelationKind, Status, priority_legend};
|
||||
|
||||
/// clap wants a `&str` with a long enough lifetime, and the legend is built from
|
||||
@@ -430,6 +431,17 @@ pub enum CampaignCommand {
|
||||
/// candidate list on a keypress
|
||||
#[arg(long)]
|
||||
ids: bool,
|
||||
|
||||
/// Only campaigns in this state: open, done, or empty for one nothing has been
|
||||
/// filed against
|
||||
///
|
||||
/// A campaign's state is derived from its members, so this is a match against the
|
||||
/// value the listing already computes and shows in brackets. `--state` rather than
|
||||
/// `--status`, which names one of the five ticket statuses everywhere else; a
|
||||
/// campaign sits in no status directory. It applies to `--ids` as well, where the
|
||||
/// member counts it needs are read only because a filter was given
|
||||
#[arg(long, value_name = "STATE")]
|
||||
state: Option<CampaignState>,
|
||||
},
|
||||
|
||||
/// Show a campaign and its members grouped by status
|
||||
|
||||
+22
-1
@@ -167,6 +167,16 @@ pub fn argument_at(args: &[String], index: usize) -> Option<Argument> {
|
||||
let verb = args.first().map(String::as_str)?;
|
||||
let group = cli.find_subcommand(verb);
|
||||
|
||||
// The command a flag belongs to, which is the *nested* one where a group's child
|
||||
// carries it: `--state` is `campaign ls`'s and clap holds it on `ls`, not on
|
||||
// `campaign`. Falls back to the group itself, which is where every other flag is, and
|
||||
// to nothing for a line whose second word names no subcommand — `mv 1b78a24 --status`
|
||||
// reaches `mv`'s own arguments as it always did.
|
||||
let holder = args
|
||||
.get(1)
|
||||
.and_then(|child| group.and_then(|group| group.find_subcommand(child)))
|
||||
.or(group);
|
||||
|
||||
// A flag's value is the argument after it, which is where the flag sits whether the
|
||||
// value is half typed or has not been started.
|
||||
if let Some(flag) = args.get(index - 1).and_then(|arg| arg.strip_prefix("--")) {
|
||||
@@ -187,7 +197,9 @@ pub fn argument_at(args: &[String], index: usize) -> Option<Argument> {
|
||||
// And everything else the flag could take, which is whatever clap knows: `--status`
|
||||
// and `set --clear` are both `ValueEnum`s, so their values are already written down
|
||||
// once, in the enum.
|
||||
let arg = group?.get_arguments().find(|arg| arg.get_long() == Some(flag))?;
|
||||
let arg = holder?
|
||||
.get_arguments()
|
||||
.find(|arg| arg.get_long() == Some(flag))?;
|
||||
return fixed(arg);
|
||||
}
|
||||
|
||||
@@ -762,6 +774,15 @@ mod tests {
|
||||
assert!(shells.contains(&"fish".to_string()), "{shells:?}");
|
||||
}
|
||||
|
||||
/// The flag on a nested command is answered the same way, from the enum: nothing here
|
||||
/// knows what a campaign's states are, and the values reach the prompt and fish alike
|
||||
/// the day a fourth one is added to `CampaignState`.
|
||||
#[test]
|
||||
fn campaign_ls_state_is_offered_the_enums_own_values() {
|
||||
let states = values("campaign ls --state ").expect("--state takes a state");
|
||||
assert_eq!(states, vec!["open", "done", "empty"], "{states:?}");
|
||||
}
|
||||
|
||||
/// `relate --clear` takes the kind and then the target, which is the one argument clap
|
||||
/// cannot answer for: possible values on the flag would refuse every target.
|
||||
#[test]
|
||||
|
||||
+183
-18
@@ -1486,21 +1486,43 @@ pub fn cmd_campaign_add(args: &CampaignAddArgs, start: &Path, sink: &mut Sink) -
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// List the campaigns with how far each has got.
|
||||
/// List the campaigns with how far each has got, as a table.
|
||||
///
|
||||
/// The counts come from one pass over the status directories per campaign. That is a
|
||||
/// scan per row rather than one scan reused, and it is deliberate: the alternative is a
|
||||
/// map from campaign uuid to counts built in a single walk, which is worth writing when
|
||||
/// a board has enough campaigns to notice and is premature now.
|
||||
pub fn cmd_campaign_ls(worklane_dir: &Path, ids: bool, sink: &mut Sink) -> Result<()> {
|
||||
///
|
||||
/// **The columns are measured on the raw values and padded before anything is styled**,
|
||||
/// the rule `metadata_cells` follows: a padded coloured value counts its escape
|
||||
/// sequences towards its width, which tilts a table when colour is on and not when it is
|
||||
/// off.
|
||||
///
|
||||
/// The codename is measured with the title rather than given a column of its own. A
|
||||
/// campaign filed without one spends nothing on it, so a column for it would be a column
|
||||
/// most rows pad into and some rows leave empty; what a reader is lining up is where one
|
||||
/// campaign's name ends and its progress begins.
|
||||
pub fn cmd_campaign_ls(
|
||||
worklane_dir: &Path,
|
||||
ids: bool,
|
||||
state: Option<CampaignState>,
|
||||
sink: &mut Sink,
|
||||
) -> Result<()> {
|
||||
let index = CampaignIndex::load(worklane_dir)?;
|
||||
let colored = sink.use_color;
|
||||
|
||||
// Ahead of the empty check, which prints prose: a completion must offer nothing
|
||||
// rather than offer a sentence, the same bargain `list_ids` takes with a missing
|
||||
// status directory.
|
||||
//
|
||||
// The filter reaches here too, the way `ls --ids` keeps its own filters. The counts
|
||||
// it needs are what `--ids` exists to avoid reading, so they are read only when a
|
||||
// filter was given: an unfiltered completion is as cheap as it was.
|
||||
if ids {
|
||||
for campaign in index.iter() {
|
||||
if !kept(worklane_dir, &campaign.uuid, state)? {
|
||||
continue;
|
||||
}
|
||||
sink.writeln(&format!("{}\t{}", short_id(&campaign.uuid), campaign.title))?;
|
||||
}
|
||||
return Ok(());
|
||||
@@ -1511,33 +1533,85 @@ pub fn cmd_campaign_ls(worklane_dir: &Path, ids: bool, sink: &mut Sink) -> Resul
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
sink.writeln("Campaigns:\n")?;
|
||||
|
||||
// Built whole before anything is written, because no column can be sized until every
|
||||
// row has been seen. `CampaignRow` holds the raw values, so the widths are measured
|
||||
// on what a reader sees rather than on what an escape sequence costs.
|
||||
let mut rows: Vec<CampaignRow> = Vec::new();
|
||||
for campaign in index.iter() {
|
||||
let standing = Standing::of(&members(worklane_dir, &campaign.uuid)?);
|
||||
let state = match standing.state() {
|
||||
Some(state) => format!(" [{}]", paint(state, Color::Orange, colored)),
|
||||
None => String::new(),
|
||||
};
|
||||
if state.is_some_and(|wanted| !wanted.holds(&standing)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The codename between the id and the title, in the colour the board draws it in
|
||||
// and with the same mark: the answer to "which campaign is this" is one word, and
|
||||
// it should be the same word wherever it is read. A campaign filed without one
|
||||
// spends nothing on it, the way an untagged card spends no row.
|
||||
let codename = match campaign.codename.is_some() {
|
||||
true => {
|
||||
let label = campaign_label(&campaign.uuid, campaign.codename.as_deref());
|
||||
format!("{} ", paint_cells(&[label], colored))
|
||||
}
|
||||
let name = match campaign.codename.is_some() {
|
||||
true => vec![
|
||||
campaign_label(&campaign.uuid, campaign.codename.as_deref()),
|
||||
Cell::plain(format!(" {}", campaign.title)),
|
||||
],
|
||||
false => vec![Cell::plain(&campaign.title)],
|
||||
};
|
||||
|
||||
rows.push(CampaignRow {
|
||||
created: format_created_at(&parse_ticket_field(&campaign.content, "Created At")),
|
||||
id: short_id(&campaign.uuid).to_string(),
|
||||
width: name.iter().map(|cell| cell.text.chars().count()).sum(),
|
||||
name,
|
||||
label: standing.label(),
|
||||
state: standing.state(),
|
||||
});
|
||||
}
|
||||
|
||||
// A filter that matches nothing says so, naming what was asked for: a listing that
|
||||
// went silent reads as a board with no campaigns on it, which is the other message.
|
||||
if rows.is_empty() {
|
||||
let wanted = state.map(CampaignState::as_str).unwrap_or_default();
|
||||
sink.writeln(&format!("No campaigns matching `--state {wanted}`."))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
sink.writeln("Campaigns:\n")?;
|
||||
|
||||
let name_width = rows.iter().map(|row| row.width).max().unwrap_or(0);
|
||||
let label_width = rows
|
||||
.iter()
|
||||
.map(|row| row.label.chars().count())
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
// Every stamp is the same width, so the column is either there or it is not: a
|
||||
// campaign whose Created At cannot be parsed drops it, the way a ticket's does.
|
||||
let dated = rows.iter().any(|row| !row.created.is_empty());
|
||||
let created_width = rows
|
||||
.iter()
|
||||
.map(|row| row.created.chars().count())
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
for row in &rows {
|
||||
let created = match dated {
|
||||
true => format!(
|
||||
"{}{} ",
|
||||
paint(&row.created, Color::Cyan, colored),
|
||||
" ".repeat(created_width - row.created.chars().count()),
|
||||
),
|
||||
false => String::new(),
|
||||
};
|
||||
let state = match row.state {
|
||||
Some(state) => format!(" [{}]", paint(state, Color::Orange, colored)),
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
sink.writeln(&format!(
|
||||
" ({}) {}{} | {}{}",
|
||||
paint(short_id(&campaign.uuid), Color::Red, colored),
|
||||
codename,
|
||||
campaign.title,
|
||||
standing.label(),
|
||||
" {}({}) {}{} | {}{}{}",
|
||||
created,
|
||||
paint(&row.id, Color::Red, colored),
|
||||
paint_cells(&row.name, colored),
|
||||
" ".repeat(name_width - row.width),
|
||||
row.label,
|
||||
" ".repeat(label_width - row.label.chars().count()),
|
||||
state,
|
||||
))?;
|
||||
}
|
||||
@@ -1545,6 +1619,35 @@ pub fn cmd_campaign_ls(worklane_dir: &Path, ids: bool, sink: &mut Sink) -> Resul
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// One row of the `campaign ls` table, as its raw values.
|
||||
///
|
||||
/// The widths are measured off these and the painting happens after, which is the whole
|
||||
/// reason the row is held rather than written as it is built: a column sized on a
|
||||
/// coloured string counts its escape sequences towards its width.
|
||||
struct CampaignRow {
|
||||
created: String,
|
||||
id: String,
|
||||
/// The codename and the title, as the cells they are drawn in.
|
||||
name: Vec<Cell>,
|
||||
/// The width of `name` in characters, which is what the column is sized on.
|
||||
width: usize,
|
||||
label: String,
|
||||
state: Option<&'static str>,
|
||||
}
|
||||
|
||||
/// Whether one campaign survives the `--state` filter, reading its members only when
|
||||
/// there is a filter to answer.
|
||||
///
|
||||
/// The counts cost a pass over the status directories, and `--ids` is called on a
|
||||
/// keypress by a shell filling in a candidate list.
|
||||
fn kept(worklane_dir: &Path, uuid: &str, state: Option<CampaignState>) -> Result<bool> {
|
||||
let Some(wanted) = state else {
|
||||
return Ok(true);
|
||||
};
|
||||
|
||||
Ok(wanted.holds(&Standing::of(&members(worklane_dir, uuid)?)))
|
||||
}
|
||||
|
||||
/// Every tag on the board: the ones the tickets carry, the ones the file declares, and
|
||||
/// what each declared one means.
|
||||
///
|
||||
@@ -2296,6 +2399,68 @@ mod sink_tests {
|
||||
root
|
||||
}
|
||||
|
||||
/// A campaign file as `campaign add` writes one, for a listing test that needs two
|
||||
/// of them with titles of different lengths.
|
||||
fn campaign(dir: &Path, title: &str, codename: Option<&str>, uuid: &str) {
|
||||
let id = uuid::Uuid::parse_str(uuid).unwrap();
|
||||
let body = campaign_body(title, &[], codename, &id, None, "2026-08-21 02:10:17");
|
||||
fs::write(dir.join("campaigns").join(format!("{uuid}_{}.md", slug(title))), body).unwrap();
|
||||
}
|
||||
|
||||
/// The table is laid out on the raw values, so the columns stand in the same place
|
||||
/// whether the row is coloured or not.
|
||||
///
|
||||
/// Rendered both ways in one process and compared with the escapes taken back off,
|
||||
/// which is what `metadata_cells` is pinned by: a column measured on a painted value
|
||||
/// counts its escape sequences towards its width, and the listing then tilts when
|
||||
/// colour is on and stands straight when it is off, which is the one combination a
|
||||
/// piped test can never see.
|
||||
#[test]
|
||||
fn the_campaign_table_stands_in_the_same_columns_coloured_or_not() {
|
||||
let dir = temp_worklane();
|
||||
ticket(&dir, "backlog", "11111111-1111-4111-8111-111111111111");
|
||||
campaign(
|
||||
&dir,
|
||||
"A campaign nothing was filed against",
|
||||
None,
|
||||
"aa11bb22-0000-4000-8000-000000000000",
|
||||
);
|
||||
campaign(&dir, "Short", Some("v1"), "bb22cc33-0000-4000-8000-000000000000");
|
||||
|
||||
let mut plain = Vec::new();
|
||||
{
|
||||
let mut sink = Sink::new(Box::new(&mut plain), false);
|
||||
cmd_campaign_ls(&dir, false, None, &mut sink).unwrap();
|
||||
}
|
||||
let mut painted = Vec::new();
|
||||
{
|
||||
let mut sink = Sink::new(Box::new(&mut painted), true);
|
||||
cmd_campaign_ls(&dir, false, None, &mut sink).unwrap();
|
||||
}
|
||||
|
||||
let plain = String::from_utf8(plain).unwrap();
|
||||
let painted = String::from_utf8(painted).unwrap();
|
||||
assert!(painted.contains('\u{1b}'), "the coloured sink wrote no colour");
|
||||
assert_eq!(
|
||||
without_escapes(&painted),
|
||||
plain,
|
||||
"the columns moved when the values were painted"
|
||||
);
|
||||
|
||||
// And they are columns: the gutter before the member count sits at one offset on
|
||||
// every row, whatever the title before it was.
|
||||
let gutters: Vec<Option<usize>> = plain
|
||||
.lines()
|
||||
.filter(|line| line.contains(" | "))
|
||||
.map(|line| line.find(" | "))
|
||||
.collect();
|
||||
assert_eq!(gutters.len(), 2, "both campaigns should be listed:\n{plain}");
|
||||
assert!(
|
||||
gutters.iter().all(|at| *at == gutters[0]),
|
||||
"the gutter is ragged:\n{plain}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A handler writes through the sink it is handed, and a caller can read the bytes
|
||||
/// back without a terminal or a real stdout.
|
||||
#[test]
|
||||
|
||||
+2
-2
@@ -121,9 +121,9 @@ pub fn dispatch(command: &Command, start: &Path, by: Attribution, sink: &mut Sin
|
||||
} => cmd_comment(ticket, body, actor, *actor_from_git, start, by, sink),
|
||||
Command::Campaign { command } => match command {
|
||||
CampaignCommand::Add(args) => cmd_campaign_add(args, start, sink),
|
||||
CampaignCommand::Ls { ids } => {
|
||||
CampaignCommand::Ls { ids, state } => {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_campaign_ls(&worklane_dir, *ids, sink)
|
||||
cmd_campaign_ls(&worklane_dir, *ids, *state, sink)
|
||||
}
|
||||
CampaignCommand::Set(args) => cmd_campaign_set(args, start, sink),
|
||||
CampaignCommand::Append(args) => cmd_campaign_append(args, start, sink),
|
||||
|
||||
+149
-4
@@ -131,6 +131,21 @@ fn stderr(out: &std::process::Output) -> String {
|
||||
String::from_utf8_lossy(&out.stderr).to_string()
|
||||
}
|
||||
|
||||
/// A listing with its column padding collapsed, for an assertion about what a row says
|
||||
/// rather than about where its columns sit.
|
||||
///
|
||||
/// The alignment is the subject of `campaign_ls_lines_its_columns_up_whatever_the_titles_are`
|
||||
/// and of the colour test beside `cmd_campaign_ls`; every other test is about the words,
|
||||
/// and one that spelled the padding out would have to be edited whenever a fixture gained
|
||||
/// a longer title.
|
||||
fn squeezed(listing: &str) -> String {
|
||||
listing
|
||||
.lines()
|
||||
.map(|line| line.split_whitespace().collect::<Vec<_>>().join(" "))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn find(worklane: &Path, uuid: &str) -> PathBuf {
|
||||
for status in ["backlog", "committed", "reviewing", "done"] {
|
||||
for entry in fs::read_dir(worklane.join(status))
|
||||
@@ -433,7 +448,7 @@ fn campaign_ls_lists_campaigns_with_their_member_counts() {
|
||||
let out = run(&temp, &["campaign", "ls"]);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
|
||||
let listing = stdout(&out);
|
||||
let listing = squeezed(&stdout(&out));
|
||||
// One of the two members is in done, so the campaign is open and half finished.
|
||||
assert!(listing.contains("v1 release | 1/2 done [open]"), "{listing}");
|
||||
// Nothing has been filed against the other one.
|
||||
@@ -481,6 +496,136 @@ fn campaign_ls_ids_says_nothing_on_a_board_with_no_campaigns() {
|
||||
assert!(stdout(&run(&temp, &["campaign", "ls"])).contains("No campaigns yet"));
|
||||
}
|
||||
|
||||
/// The state filter, against the same three answers `Standing::state` gives: a campaign
|
||||
/// with work left, one with none, and one nothing has been filed against.
|
||||
#[test]
|
||||
fn campaign_ls_state_lists_only_the_campaigns_in_that_state() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let _worklane = board(&temp);
|
||||
|
||||
// v1 holds a backlog member and v2 holds a done one, so the two are open and done.
|
||||
run(&temp, &["assign", "v1 release", MEMBER]);
|
||||
run(&temp, &["assign", "v2 release", OTHER]);
|
||||
run(&temp, &["campaign", "add", "--title", "Nothing filed yet"]);
|
||||
|
||||
let open = squeezed(&stdout(&run(&temp, &["campaign", "ls", "--state", "open"])));
|
||||
assert!(open.contains("v1 release | 0/1 done [open]"), "{open}");
|
||||
assert!(!open.contains("v2 release"), "a done campaign was listed as open: {open}");
|
||||
assert!(!open.contains("Nothing filed yet"), "{open}");
|
||||
|
||||
let done = squeezed(&stdout(&run(&temp, &["campaign", "ls", "--state", "done"])));
|
||||
assert!(done.contains("v2 release | 1/1 done [done]"), "{done}");
|
||||
assert!(!done.contains("v1 release"), "{done}");
|
||||
|
||||
// The third value, which is what makes every campaign on the board reachable: a
|
||||
// memberless one is neither open nor done, deliberately, and it is the one a
|
||||
// grooming sweep is looking for.
|
||||
let empty = squeezed(&stdout(&run(&temp, &["campaign", "ls", "--state", "empty"])));
|
||||
assert!(empty.contains("Nothing filed yet | no members"), "{empty}");
|
||||
assert!(!empty.contains("v1 release"), "{empty}");
|
||||
assert!(!empty.contains("v2 release"), "{empty}");
|
||||
|
||||
// And it reaches the machine-readable listing the way `ls --ids` keeps its filters.
|
||||
let ids = stdout(&run(&temp, &["campaign", "ls", "--ids", "--state", "empty"]));
|
||||
assert_eq!(ids.lines().count(), 1, "{ids}");
|
||||
assert!(ids.contains("Nothing filed yet"), "{ids}");
|
||||
}
|
||||
|
||||
/// A value the enum does not hold is clap's to refuse, so nothing is read and the exit
|
||||
/// code is the usage error's.
|
||||
#[test]
|
||||
fn campaign_ls_refuses_a_state_that_is_not_one() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let _worklane = board(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "ls", "--state", "backlog"]);
|
||||
assert_eq!(out.status.code(), Some(2), "{}", stderr(&out));
|
||||
let said = stderr(&out);
|
||||
assert!(said.contains("open"), "{said}");
|
||||
assert!(said.contains("empty"), "{said}");
|
||||
}
|
||||
|
||||
/// A filter that matches nothing says so and names what was asked for. Going silent
|
||||
/// would read as the other empty case, a board with no campaigns on it, which has a
|
||||
/// message of its own.
|
||||
#[test]
|
||||
fn campaign_ls_says_when_the_filter_matched_nothing() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let _worklane = board(&temp);
|
||||
|
||||
let out = run(&temp, &["campaign", "ls", "--state", "done"]);
|
||||
assert!(out.status.success(), "{}", stderr(&out));
|
||||
let said = stdout(&out);
|
||||
assert!(said.contains("--state done"), "the filter is not named: {said}");
|
||||
assert!(!said.contains("No campaigns yet"), "the other empty case: {said}");
|
||||
|
||||
// The completion path stays silent, filtered or not.
|
||||
assert_eq!(stdout(&run(&temp, &["campaign", "ls", "--ids", "--state", "done"])), "");
|
||||
}
|
||||
|
||||
/// The columns line up whatever the titles are, which is what the padding is for. The
|
||||
/// fixture's two titles are the same length, so this one files a third with a long title
|
||||
/// and a codename: the row that pushes the column is the row that proves it moved for
|
||||
/// every other row too.
|
||||
#[test]
|
||||
fn campaign_ls_lines_its_columns_up_whatever_the_titles_are() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let _worklane = board(&temp);
|
||||
|
||||
run(
|
||||
&temp,
|
||||
&[
|
||||
"campaign",
|
||||
"add",
|
||||
"--title",
|
||||
"A campaign with a much longer title than the others",
|
||||
"--codename",
|
||||
"beaver",
|
||||
],
|
||||
);
|
||||
run(&temp, &["assign", "v1 release", MEMBER]);
|
||||
|
||||
let listing = stdout(&run(&temp, &["campaign", "ls"]));
|
||||
let rows: Vec<&str> = listing.lines().filter(|line| line.contains(" | ")).collect();
|
||||
assert_eq!(rows.len(), 3, "{listing}");
|
||||
|
||||
for column in [" (", " | "] {
|
||||
let offsets: Vec<Option<usize>> = rows.iter().map(|row| row.find(column)).collect();
|
||||
assert!(
|
||||
offsets.iter().all(|at| *at == offsets[0]),
|
||||
"`{column}` is ragged across the rows:\n{listing}"
|
||||
);
|
||||
}
|
||||
|
||||
// The state sits at one offset too, on the rows that have one: a campaign with no
|
||||
// members has nothing in brackets and pads to where the next row's bracket is.
|
||||
let states: Vec<Option<usize>> = rows
|
||||
.iter()
|
||||
.filter(|row| row.contains('['))
|
||||
.map(|row| row.find('['))
|
||||
.collect();
|
||||
assert!(!states.is_empty(), "no row carried a state: {listing}");
|
||||
assert!(
|
||||
states.iter().all(|at| *at == states[0]),
|
||||
"the state column is ragged:\n{listing}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The created stamp the campaign file already carries, in the form `ls` prints one in
|
||||
/// rather than a second spelling of a date.
|
||||
#[test]
|
||||
fn campaign_ls_shows_the_created_date() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let _worklane = board(&temp);
|
||||
|
||||
let listing = stdout(&run(&temp, &["campaign", "ls"]));
|
||||
assert!(listing.contains("26-08-21:02"), "no created stamp: {listing}");
|
||||
|
||||
// Not in the machine-readable listing, which is the id and the title and nothing else.
|
||||
let ids = stdout(&run(&temp, &["campaign", "ls", "--ids"]));
|
||||
assert!(!ids.contains("26-08-21"), "{ids}");
|
||||
}
|
||||
|
||||
/// A campaign is done when it holds members and every one of them is done. An empty one
|
||||
/// is neither, which is why it reads `no members` rather than `0/0 done`.
|
||||
#[test]
|
||||
@@ -490,7 +635,7 @@ fn a_campaign_whose_every_member_is_done_reads_done() {
|
||||
|
||||
run(&temp, &["assign", "v1 release", OTHER]);
|
||||
|
||||
let listing = stdout(&run(&temp, &["campaign", "ls"]));
|
||||
let listing = squeezed(&stdout(&run(&temp, &["campaign", "ls"])));
|
||||
assert!(listing.contains("v1 release | 1/1 done [done]"), "{listing}");
|
||||
}
|
||||
|
||||
@@ -1726,13 +1871,13 @@ fn a_discarded_member_counts_as_finished() {
|
||||
run(&temp, &["assign", "v1 release", OTHER]);
|
||||
|
||||
// Two members, one done and one in the backlog: open and half finished.
|
||||
let listing = stdout(&run(&temp, &["campaign", "ls"]));
|
||||
let listing = squeezed(&stdout(&run(&temp, &["campaign", "ls"])));
|
||||
assert!(listing.contains("v1 release | 1/2 done [open]"), "{listing}");
|
||||
|
||||
let discarded = run(&temp, &["mv", MEMBER, "--status", "discarded"]);
|
||||
assert!(discarded.status.success(), "{}", stderr(&discarded));
|
||||
|
||||
let listing = stdout(&run(&temp, &["campaign", "ls"]));
|
||||
let listing = squeezed(&stdout(&run(&temp, &["campaign", "ls"])));
|
||||
assert!(listing.contains("v1 release | 2/2 done [done]"), "{listing}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user