Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbd752afc9 | ||
|
|
298e00eb33 | ||
|
|
634a1f44c4 | ||
|
|
3e732535f8 |
Generated
+1
-1
@@ -1563,7 +1563,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.33.4"
|
||||
version = "0.33.8"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.33.4"
|
||||
version = "0.33.8"
|
||||
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 |
|
||||
@@ -33,7 +33,7 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
|
||||
| Variable | Effect |
|
||||
|----------|--------|
|
||||
| `WORKLANE_ACTOR` | Who every entry the CLI writes is attributed to: a comment, and the `status`, `owner` and `tags` entries `mv`, `chown` and `set --tags` record. Set it once, in the environment an agent runs in, and every call it makes is attributed to it instead of to the git user of whoever's machine it is on. `--actor` overrides it per call and `--actor-from-git` lifts the git user over it per call (the two flags are refused together), an empty value counts as unset, and with neither supplied the author is the git user and then `unknown`. Free text, checked against nothing |
|
||||
| `WORKLANE_ACTOR` | Who every entry the CLI writes is attributed to: a comment, and the `status`, `owner` and `tags` entries `mv`, `chown` and `set --tags` record. Set it once, in the environment an agent runs in, and every call it makes is attributed to it instead of to the git user of whoever's machine it is on. `--actor` overrides it per call and `--actor-from-git` lifts the git user over it per call (the two flags are refused together), an empty value counts as unset, and with neither supplied the author is the git user and then `unknown`. A command typed at the board's `:` prompt is attributed to the person instead, the git user and then `unknown`, never this variable: nothing but whoever is sitting at the board can type one. Free text, checked against nothing |
|
||||
| `NO_COLOR` | Set and non-empty turns colour off, whatever the value, per no-color.org. Colour is also off when output is not a terminal, and when `TERM` is `dumb` or empty |
|
||||
| `XDG_CONFIG_HOME` | Where `install-tool` looks for opencode's config root, `$XDG_CONFIG_HOME/opencode`, defaulting to `~/.config`. `install-skill` does not follow it: `~/.claude` is not an XDG path |
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
+7
-2
@@ -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
|
||||
@@ -417,8 +418,6 @@ is never needed. It cannot be combined with `--actor`, and a machine with no git
|
||||
configured has nobody to name: the entry reads `unknown` rather than falling back to your
|
||||
variable.
|
||||
|
||||
```
|
||||
worklane mv 1b78a24 --status done --actor "Ansho Rei"
|
||||
```
|
||||
worklane mv 1b78a24 --status done --actor "Ansho Rei"
|
||||
```
|
||||
@@ -431,6 +430,12 @@ recognise.
|
||||
On `chown`, `--actor` is not the user argument: `worklane chown alice 1b78a24` makes alice
|
||||
the ticket's owner, and `--actor` says who made that change.
|
||||
|
||||
**An entry made from the board is the person's, not yours.** A command typed at the
|
||||
board's `:` prompt is attributed to the git user of that machine whatever `WORKLANE_ACTOR`
|
||||
is set to, because nothing but the person sitting at the board can type one. So an entry
|
||||
can appear under a name no agent is configured with, and reading it as somebody else's
|
||||
agent is reading it wrong: that is the person whose board it is, acting for themselves.
|
||||
|
||||
## Shell completions
|
||||
|
||||
```
|
||||
|
||||
+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,9 @@ 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 is recognised by either spelling, `--status` and `-s` alike.** `long_name` translates the letter through the command that holds the flag, so every table above stays keyed on the long name and nothing here keeps a second list of the letters. The prompt read a flag by its two hyphens until then: `mv --status ` offered the five statuses and `mv -s ` offered nothing. **One letter, never a cluster** — `mv -fs done` would be the honest reading of the last letter, but `--title`, `--acceptance` and a comment body all take a leading hyphen on purpose, and a criterion typed as `-fixes the offset` must not be answered with statuses. `a_short_flag_answers_what_its_long_spelling_answers` walks every option with both spellings on every command and nested command, so an option given a letter tomorrow is covered the day it is given one
|
||||
- **The fish rules name the letter too, `-s g -l tags`.** The same hole on the other half: `append -g <TAB>` offered nothing where `append --tags <TAB>` offered the board's tags, because the dynamic rules were rendered with `-l` alone. `fish_option` reads the letter off the definition per command, so a rule for an option with none is what it always was. Clap's own generated half already emitted both spellings, which is why only the dynamic rules were short
|
||||
- **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
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ Who an entry is attributed to, and what the log does and does not record.
|
||||
## Who Wrote an Entry
|
||||
- **Identity is supplied, not detected.** Every option that needs no cooperation fails: a harness variable such as `CLAUDECODE` names the tool rather than the instance and breaks across versions, walking the parent process is platform specific and also only names the harness, and a terminal check separates interactive from not, which a human piping output is too. So the actor is `WORKLANE_ACTOR`, set once per session, with `--actor` as the per-call override
|
||||
- **Precedence: flag, then `WORKLANE_ACTOR`, then `get_git_user()`, then `unknown`.** With `--actor-from-git` and no explicit value the git user is lifted *above* the variable rather than added beneath it — the flag says attribute this to the human, and a machine with no git user configured reads `unknown` instead of quietly attributing back to the agent. An explicit `--actor` wins outright either way. `resolve_actor` is the only caller of `get_git_user` for an entry's author, and every entry the CLI writes goes through it. The halves are separate pure functions, `session_actor` (the variable alone now) and `entry_actor`, tested without touching the process environment for the reason `colors_wanted` is split that way
|
||||
- **A command typed at the board is the person's, not the session's.** `dispatch` takes an `Attribution`, `Session` from `main` and `Person` from the command prompt, and `Person` asks for `--actor-from-git`'s lift without the flag: nothing but the reader can type that line, and a person who exported `WORKLANE_ACTOR` where their own shell picks it up — the obvious way to configure it for the agents on that machine — would otherwise watch their own `mv` recorded as the agent's. An explicit `--actor` still wins there, which is how the reader puts somebody else's name on their own keystrokes, and with no git user configured the entry reads `unknown` rather than falling back to the variable, for the reason the flag does. `entry_actor` takes it beside `from_git` and the two are one branch, since `--actor-from-git` typed at the prompt asks for what the prompt does anyway
|
||||
- **The attribution is a parameter of `dispatch`, not a field the prompt writes into the parsed arguments.** Rewriting what clap produced would need an arm per entry-writing command, and the command added after it would be attributed to the agent until somebody noticed. A parameter is one edit for both callers, and `no_handler_decides_its_own_attribution` reads `src` for a handler naming an `Attribution` of its own, which the compiler cannot catch because it compiles
|
||||
- **The variable half is cached in a `OnceLock` and the git user in another**, the way `should_use_colors` is: neither input can change mid-run, and the git user costs a subprocess. Two caches rather than one is the whole point: baking the git user into the session's answer would make `--actor-from-git` read whatever the run's *first* call produced, since with the variable set that call never fetched git at all. `entry_actor` takes the git user as a closure so the subprocess is not run when something ahead of it already answered
|
||||
- **The two flags are refused together at parse time**, clap `conflicts_with`: both answer who the entry is attributed to, and last-wins would be a silent answer to a contradictory call. `every_actor_command_takes_actor_from_git` walks the clap definition so the pair travels together onto any command that grows an `--actor`
|
||||
- An **empty `WORKLANE_ACTOR` counts as unset**, the convention `colors_wanted` follows for `NO_COLOR`, so a wrapper script can clear an inherited one. Whitespace counts the same, since a shell quoting a missing value writes one
|
||||
|
||||
@@ -24,6 +24,7 @@ The three input modes on the board and the key that copies an id off it.
|
||||
- **`refused` is cleared by an edit and not by a movement.** The message is about the line, and moving the cursor does not change the line. `Prompt::key` clears it in the three arms that write to the line
|
||||
- **A line that ends inside a quote never reaches clap.** That is what `Unclosed` is for: a grammar complaint about a sentence nobody finished describes the wrong thing. Enter on an empty line, or one of nothing but separators, closes the prompt with nothing said, the way `esc` does — the bare form of the CLI opens a board and there is one on the screen
|
||||
- **Enter runs it, through `main.rs`'s `dispatch` and never through a handler this file names.** That match is the one mapping from a parsed command to the function that performs it: `main` calls it with its own stdout and the working directory, `Board::run` calls it with a buffer and the selected tab's root. A second copy inside `tui.rs` would drift the first time a command was added, and it would drift *silently*, since both halves go on compiling. The match is exhaustive so a new verb cannot fall into an `_` arm and do nothing, and `main_and_the_prompt_run_one_dispatch_table` reads both files as text to pin it. Only `tui` is matched outside the table, in `main`, because the board is that table's caller rather than an entry in it; reached from the prompt it is refused in those words
|
||||
- **What it writes is attributed to the person at the board**, through the same `dispatch` parameter, because a line nothing but the reader can type is the reader's action. The rule and its precedence are in [history.md](history.md), which owns attribution; what belongs here is that the board is the one caller that asks for it
|
||||
- **`from_arg_matches` on the same matches gives `run` the typed values.** One parse, two readings: `command_name` walks the subcommands to name what resolved and `from_arg_matches` reconstructs the `Cli`. A `match` over every `Command` variant to get one or the other would be a second list of every verb the CLI has
|
||||
- **The handler's own words are what the board reports, word for word.** Those messages are written for a person already, and a second set kept here would go stale the first time one of them changed. The sink is a buffer, so the words come back as text and the board styles them; it is plain for the same reason `Detail` holds spans, since a ratatui paragraph prints an escape rather than obeying it. An error never goes through a sink at all — `color_text` asks the *process* about its stdout, which under the board answers yes about a terminal the message is not going to — so `error_lines` runs `without_escapes` over it and puts each cause on a line of its own
|
||||
- **A warning goes through the sink's second stream, and never through `eprintln!`.** `Sink` carries two writers because the CLI's two streams are two: `Sink::std` hands the answer to stdout and an aside to stderr, and a shell has to go on reading the same line on the same stream. Under the board neither is a stream at all — stderr is the alternate screen with the columns on it — so `Sink::buffer` *holds* its warnings and `Board::run` reads them back with `Sink::warnings` and puts them above the answer, on both outcomes: a `mv` that warns about a dangling blocker and is then refused by a real one wrote the aside first, and it is the half that says why the refusal names one blocker and the ticket records two. That is c680e24: one `eprintln!` in `check_blockers` outlived fa5662a because a helper had no sink to reach, and ratatui does not repaint a cell it believes is unchanged, so the fragment stayed on the columns until something else redrew them. `no_handler_or_helper_reaches_a_print_macro` walks `src` for the next one, each file cut at its test module, so a print site in a module added tomorrow is caught the day it is added
|
||||
@@ -32,6 +33,10 @@ The three input modes on the board and the key that copies an id off it.
|
||||
- **The selection is restored by uuid across that reload, never by index.** `mv` puts the card in another column, `set --title` renames its file, and a filter can drop it out of view entirely, so the slot is not the ticket. `Board::reselect` has three answers: the card is in a drawn column and the selection goes to it; it is on the board but in a column the rotation is hiding, which is where `--status done` lands by default, so the notice says where it went and which key shows it; or the filter no longer holds it, which is said too, since a card vanishing from under the highlight reads as a bug in the board
|
||||
- **The merge tab is refused, for now.** It is the one tab that is not a board — its cards came from several `.worklane` directories and it is none of them — so `Board::current_project` answers `None` there and the command is refused rather than landing on whichever project came first. Routing by the card a command names is ebc5755. The project is resolved by index and not by the tab's name, which is a label two projects can share: e1d79c3 is exactly that, and a write routed by name would be that bug with a file changing at the end of it
|
||||
- **`Notice` holds as many lines as the command used, and `Board::notice_on_row` decides where they go.** One line with nothing else holding the row draws on the footer, where a copy's notice has always drawn. Anything else — several lines, or any answer at all while the prompt is still open on an error — draws as a box at the foot of the columns, cut to what the columns leave with the dropped count on its last row. A box rather than more rows of footer, and that is the whole reason it is an overlay: a footer that grew and shrank as notices came and went would reflow the columns on every keypress, moving every card the reader is looking at. `draw` and `draw_footer` both ask `notice_on_row`, so the two cannot come to disagree and draw the message twice or not at all
|
||||
- **The command's own usage line takes the keys' slot as soon as the verb resolves.** The reader knows the grammar approximately — that `mv` takes a status, not whether it is a positional or a flag, and that `set` has a flag per section, not whether the criteria one is `--acceptance` or `--criteria` — which is what a shell answers as the line is typed and the board answered with nothing. `usage_of` walks the typed verb against the clap definition and renders *its* usage, so a flag added to a command is described here the day it is added; a table of synopses kept beside it would be a second grammar going stale silently, since nothing but a reader typing that verb would see the two disagree. The `Usage: ` label is dropped, being a block name in a help page of several where this is one line beside the line it describes
|
||||
- **`esc` and `enter` are what the row gives up for it.** Two keys a reader learns once, against a synopsis that is different for every verb. A refusal still wins over both while it is up, being what was just said about the line that is still on the row, and `refusal` is the half that says what is *wrong* where this says what would have been right
|
||||
- **A verb that resolves to nothing draws nothing, and complains about nothing.** The line is half typed most of the time the row is looked at, so an error about `com` is noise where a reader is still typing. A group's child is walked when the second word names one, so `campaign set` describes `set`; while that second word is half typed the group's own `campaign <COMMAND>` stands, which is what has been typed so far
|
||||
- **Grey, and cut with an ellipsis rather than wrapped.** Grey is the chrome colour and says the same thing the suggestion's does: this is not in your line. The footer is one row, and a second one would reflow the columns every time a verb resolved — the reason a notice of several lines is a box. There is always at least the keys' width to cut into, because that width comes off the row before the line is windowed, so the usage never takes a cell from what is being typed
|
||||
- **What a refused line shows is clap's own message with the usage block cut off**, which is also what drops the `--help` line after it. `--help` is the exception: it parses as an error of the kind that means *print this* and what it would print is a page, so it is caught and answered in a row's worth of words, or clap's help lands on the alternate screen the way an unsunk `println!` would. `--version` goes through the ordinary path, because what it prints is one line by construction. `ColorChoice::Never` on the command, so nothing that reaches the row carries an escape
|
||||
- **The keys' width comes off the row before the line is windowed**, so a long command does not push them off the end; a message takes the row from the keys instead, since the reader has just been told something and `esc` and `enter` still do what they did. `prompt_window` anchors the window on the cursor's right edge, which costs the text *after* the cursor on a long line: keeping both ends needs a scroll offset in state, and the draw is where the width is known and the state is not writable
|
||||
- `: command` is named in every footer state, because the key works in every one of them, and the prompt's own key is drawn as `↵ run`
|
||||
|
||||
+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
|
||||
|
||||
+170
-9
@@ -111,6 +111,36 @@ pub const TAG_NESTED_COMMANDS: [(&str, &str); 1] = [("tags", "set")];
|
||||
/// every target.
|
||||
pub const RELATION_KIND_FLAGS: [(&str, &str); 1] = [("relate", "clear")];
|
||||
|
||||
/// The long name of the flag a typed word spells, or nothing where it is not a flag.
|
||||
///
|
||||
/// `--status` is its own name and `-s` is clap's to translate, off the command that holds
|
||||
/// the flag: a table of the shorts kept here would be a second list of every option the
|
||||
/// tool has, and it would go wrong the first time one was given a letter.
|
||||
///
|
||||
/// **One letter, never a cluster.** `mv -fs done` is force and status and it is `status`
|
||||
/// that takes the word after it, so the last letter of a cluster would be the honest
|
||||
/// answer — but `--title`, `--description`, `--acceptance`, `--plan` and a comment body all
|
||||
/// take a leading hyphen on purpose, and reading `-fixes the offset` as a cluster would
|
||||
/// offer statuses inside a criterion. A clustered short is rare on a board where the line
|
||||
/// is typed a word at a time; a hyphen-leading prose value is a documented feature.
|
||||
fn long_name(arg: &str, holder: Option<&clap::Command>) -> Option<String> {
|
||||
if let Some(long) = arg.strip_prefix("--") {
|
||||
return (!long.is_empty()).then(|| long.to_string());
|
||||
}
|
||||
|
||||
let mut letters = arg.strip_prefix('-')?.chars();
|
||||
let short = match (letters.next(), letters.next()) {
|
||||
(Some(letter), None) => letter,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
holder?
|
||||
.get_arguments()
|
||||
.find(|option| option.get_short() == Some(short))
|
||||
.and_then(|option| option.get_long())
|
||||
.map(str::to_string)
|
||||
}
|
||||
|
||||
/// What an argument of a typed line names, where worklane can answer what goes there.
|
||||
///
|
||||
/// The board's command prompt completes against this: the tables above say *what* the
|
||||
@@ -167,9 +197,21 @@ 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("--")) {
|
||||
// value is half typed or has not been started. Spelled long or short: `-s` is the same
|
||||
// flag as `--status` and the row has to answer both, which is what `long_name` is for.
|
||||
if let Some(flag) = args.get(index - 1).and_then(|arg| long_name(arg, holder)) {
|
||||
let flag = flag.as_str();
|
||||
if TICKET_FLAGS.contains(&(verb, flag)) {
|
||||
return Some(Argument::Ticket);
|
||||
}
|
||||
@@ -187,7 +229,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);
|
||||
}
|
||||
|
||||
@@ -269,8 +313,9 @@ fn fish_dynamic() -> String {
|
||||
let ticket_flags = TICKET_FLAGS
|
||||
.iter()
|
||||
.map(|(command, flag)| {
|
||||
let option = fish_option(command, flag);
|
||||
format!(
|
||||
"complete -c worklane -n '__worklane_command_is {command}' -l {flag} \\\n \
|
||||
"complete -c worklane -n '__worklane_command_is {command}' {option} \\\n \
|
||||
-x -a '(worklane ls --ids)'"
|
||||
)
|
||||
})
|
||||
@@ -287,12 +332,13 @@ fn fish_dynamic() -> String {
|
||||
.map(|(parent, child)| format!("__worklane_nested_arg_of {parent} {child}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("; or ");
|
||||
let campaign_flags = flag_list(&CAMPAIGN_FLAGS);
|
||||
let campaign_flags = flag_list("ls", &CAMPAIGN_FLAGS);
|
||||
let tag_flags = TAG_FLAGS
|
||||
.iter()
|
||||
.map(|(command, flag)| {
|
||||
let option = fish_option(command, flag);
|
||||
format!(
|
||||
"complete -c worklane -n '__worklane_command_is {command}' -l {flag} \\\n \
|
||||
"complete -c worklane -n '__worklane_command_is {command}' {option} \\\n \
|
||||
-x -a '(worklane tags | cut -f1,3)'"
|
||||
)
|
||||
})
|
||||
@@ -430,15 +476,40 @@ complete -c worklane -n '__worklane_first_arg_of install-skill' -a '{skills}' -d
|
||||
)
|
||||
}
|
||||
|
||||
/// Option names as fish wants them on a `complete` line, `-l one -l two`.
|
||||
fn flag_list(flags: &[&str]) -> String {
|
||||
/// Option names as fish wants them on a `complete` line, `-s o -l one -l two`, for the
|
||||
/// options of one command.
|
||||
fn flag_list(command: &str, flags: &[&str]) -> String {
|
||||
flags
|
||||
.iter()
|
||||
.map(|flag| format!("-l {flag}"))
|
||||
.map(|flag| fish_option(command, flag))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
/// One option as fish names it: its long name, and its letter where clap gave it one.
|
||||
///
|
||||
/// `-s g -l tags` rather than `-l tags` alone, or `append -g <TAB>` offers nothing where
|
||||
/// `append --tags <TAB>` offers the board's tags — the same hole the board's own prompt had
|
||||
/// until `long_name`, and the reason one table answers both halves is that neither may
|
||||
/// answer a spelling the other does not. The letter is read off the definition and never
|
||||
/// written here, so an option given one tomorrow is offered under it the day it is given.
|
||||
fn fish_option(command: &str, flag: &str) -> String {
|
||||
let cli = crate::command::Cli::command();
|
||||
let short = cli
|
||||
.find_subcommand(command)
|
||||
.and_then(|command| {
|
||||
command
|
||||
.get_arguments()
|
||||
.find(|option| option.get_long() == Some(flag))
|
||||
})
|
||||
.and_then(|option| option.get_short());
|
||||
|
||||
match short {
|
||||
Some(letter) => format!("-s {letter} -l {flag}"),
|
||||
None => format!("-l {flag}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The names a `ValueEnum` accepts, for a fish `-a` list.
|
||||
///
|
||||
/// Read off the enum rather than written out, so a status or a shell added to either one
|
||||
@@ -762,6 +833,96 @@ mod tests {
|
||||
assert!(shells.contains(&"fish".to_string()), "{shells:?}");
|
||||
}
|
||||
|
||||
/// The fish half names an option by its letter too, wherever clap gave it one, so a
|
||||
/// dynamic rule answers both spellings the way the prompt does.
|
||||
#[test]
|
||||
fn a_fish_rule_names_the_option_by_its_letter_as_well() {
|
||||
let script = fish_dynamic();
|
||||
|
||||
// `append --tags` is the one flag in these tables with a letter, and it is the
|
||||
// whole reason the rule is rendered rather than written: `-g` offered nothing.
|
||||
assert!(
|
||||
script.contains("-s g -l tags"),
|
||||
"the tags rule does not name its letter:\n{script}"
|
||||
);
|
||||
|
||||
// And one without stays as it was, rather than gaining an empty `-s`.
|
||||
assert!(script.contains("-l campaign"), "{script}");
|
||||
assert!(!script.contains("-s "), "an option with no letter got one:\n{script}");
|
||||
|
||||
// Read off the definition, never written here.
|
||||
assert_eq!(fish_option("append", "tags"), "-s g -l tags");
|
||||
assert_eq!(fish_option("ls", "tag"), "-l tag");
|
||||
assert_eq!(fish_option("ls", "nosuchflag"), "-l nosuchflag");
|
||||
}
|
||||
|
||||
/// A flag spelled short answers exactly what the same flag spelled long answers, on
|
||||
/// every command and every option that has both.
|
||||
///
|
||||
/// Walked off the clap definition rather than listed, so an option given a letter
|
||||
/// tomorrow is covered the day it is given one. `-s` was the report: `mv --status `
|
||||
/// offered the five statuses and `mv -s ` offered nothing, because the row read a flag
|
||||
/// by its two hyphens. A boolean's two spellings agree as well, both answering nothing,
|
||||
/// which is the same statement about a value that is not there.
|
||||
#[test]
|
||||
fn a_short_flag_answers_what_its_long_spelling_answers() {
|
||||
let cli = crate::command::Cli::command();
|
||||
let mut seen = 0;
|
||||
|
||||
for command in cli.get_subcommands() {
|
||||
let children: Vec<(String, &clap::Command)> = command
|
||||
.get_subcommands()
|
||||
.map(|child| (format!("{} {}", command.get_name(), child.get_name()), child))
|
||||
.collect();
|
||||
|
||||
for (line, holder) in
|
||||
std::iter::once((command.get_name().to_string(), command)).chain(children)
|
||||
{
|
||||
for option in holder.get_arguments() {
|
||||
let (Some(short), Some(long)) = (option.get_short(), option.get_long()) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
seen += 1;
|
||||
assert_eq!(
|
||||
at_cursor(&format!("{line} -{short} ")),
|
||||
at_cursor(&format!("{line} --{long} ")),
|
||||
"`-{short}` and `--{long}` answer differently on `{line}`"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(seen > 20, "only {seen} options had both spellings, which is too few");
|
||||
}
|
||||
|
||||
/// The two the report named, spelled out, so the walk above cannot pass by finding
|
||||
/// nothing on either spelling.
|
||||
#[test]
|
||||
fn a_short_flag_reaches_the_values_and_the_board() {
|
||||
let listed: Vec<String> = Status::ALL.iter().map(|s| s.as_str().to_string()).collect();
|
||||
assert_eq!(values("mv -s "), Some(listed), "`-s` offers no statuses");
|
||||
assert_eq!(values("mv -s bac"), values("mv --status bac"), "half typed");
|
||||
|
||||
// A tag, which comes off the board rather than out of the enum.
|
||||
assert_eq!(at_cursor("append -g "), Some(Argument::Tag { declared: false }));
|
||||
|
||||
// And a cluster is deliberately not read, because `--title`, `--acceptance` and a
|
||||
// comment body all take a leading hyphen: a value spelled `-fixes the offset` must
|
||||
// not be read as `-s` and answered with statuses.
|
||||
assert_eq!(at_cursor("mv -fs "), None);
|
||||
assert_eq!(at_cursor("comment 1b78a24 -fs "), None);
|
||||
}
|
||||
|
||||
/// 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]
|
||||
|
||||
+234
-29
@@ -611,7 +611,7 @@ fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str, sink: &mut Sin
|
||||
/// A status is a [`Status`] rather than a string, so an unknown one is clap's to refuse
|
||||
/// and nothing here has to check. What is left is the order of the flow, which is
|
||||
/// `Status::ALL`.
|
||||
pub fn cmd_mv(args: &MvArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
pub fn cmd_mv(args: &MvArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> {
|
||||
let MvArgs {
|
||||
ticket: ticket_id,
|
||||
status: target,
|
||||
@@ -758,7 +758,7 @@ pub fn cmd_mv(args: &MvArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
&parse_ticket_field(&resolved, "ID"),
|
||||
Kind::Status,
|
||||
&change(¤t_status, target_status),
|
||||
&resolve_actor(actor.as_deref(), *actor_from_git),
|
||||
&resolve_actor(actor.as_deref(), *actor_from_git, by),
|
||||
&reason,
|
||||
)?;
|
||||
|
||||
@@ -778,6 +778,7 @@ pub fn cmd_comment(
|
||||
actor: &Option<String>,
|
||||
actor_from_git: bool,
|
||||
start: &Path,
|
||||
by: Attribution,
|
||||
sink: &mut Sink,
|
||||
) -> Result<()> {
|
||||
if body.is_empty() {
|
||||
@@ -797,7 +798,7 @@ pub fn cmd_comment(
|
||||
&ticket_uuid,
|
||||
Kind::Comment,
|
||||
body,
|
||||
&resolve_actor(actor.as_deref(), actor_from_git),
|
||||
&resolve_actor(actor.as_deref(), actor_from_git, by),
|
||||
"",
|
||||
)?;
|
||||
|
||||
@@ -976,7 +977,7 @@ fn report_in(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_set(args: &SetArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
pub fn cmd_set(args: &SetArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> {
|
||||
if let Some(field) = args.contested() {
|
||||
let name = field.name();
|
||||
return Err(anyhow!(
|
||||
@@ -1058,7 +1059,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
&parse_ticket_field(&original, "Tags"),
|
||||
&parse_ticket_field(&content, "Tags"),
|
||||
),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git, by),
|
||||
"",
|
||||
)?;
|
||||
}
|
||||
@@ -1089,7 +1090,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
/// for a ticket it is filing, which is a default for something new; an owner taken away
|
||||
/// says nobody owns this, and putting the person running the command there instead would
|
||||
/// hand them a ticket they were giving up.
|
||||
pub fn cmd_chown(args: &ChownArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
pub fn cmd_chown(args: &ChownArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> {
|
||||
let (ticket_id, user) = args.target().ok_or_else(|| {
|
||||
anyhow!("chown takes a user and a ticket, or --clear with the ticket alone")
|
||||
})?;
|
||||
@@ -1117,7 +1118,7 @@ pub fn cmd_chown(args: &ChownArgs, start: &Path, sink: &mut Sink) -> Result<()>
|
||||
&parse_ticket_field(&original, "Owner"),
|
||||
&parse_ticket_field(&content, "Owner"),
|
||||
),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git, by),
|
||||
"",
|
||||
)?;
|
||||
|
||||
@@ -1129,7 +1130,7 @@ pub fn cmd_chown(args: &ChownArgs, start: &Path, sink: &mut Sink) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_append(args: &AppendArgs, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
pub fn cmd_append(args: &AppendArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
let (status, title, original) = resolve_ticket(&args.ticket, &worklane_dir)?;
|
||||
let uuid = parse_ticket_field(&original, "ID");
|
||||
@@ -1180,7 +1181,7 @@ pub fn cmd_append(args: &AppendArgs, start: &Path, sink: &mut Sink) -> Result<()
|
||||
&parse_ticket_field(&original, "Tags"),
|
||||
&parse_ticket_field(&content, "Tags"),
|
||||
),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git, by),
|
||||
"",
|
||||
)?;
|
||||
}
|
||||
@@ -1485,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(());
|
||||
@@ -1510,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,
|
||||
))?;
|
||||
}
|
||||
@@ -1544,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.
|
||||
///
|
||||
@@ -1885,6 +1989,7 @@ pub fn cmd_assign(
|
||||
actor: &Option<String>,
|
||||
actor_from_git: bool,
|
||||
start: &Path,
|
||||
by: Attribution,
|
||||
sink: &mut Sink,
|
||||
) -> Result<()> {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
@@ -1923,7 +2028,7 @@ pub fn cmd_assign(
|
||||
&uuid,
|
||||
Kind::Campaign,
|
||||
&change(&before, campaign.name()),
|
||||
&resolve_actor(actor.as_deref(), actor_from_git),
|
||||
&resolve_actor(actor.as_deref(), actor_from_git, by),
|
||||
"",
|
||||
)?;
|
||||
|
||||
@@ -2294,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]
|
||||
@@ -2387,7 +2554,7 @@ mod sink_tests {
|
||||
let mut sink = Sink::buffer(&mut buf);
|
||||
// A dangling uuid is a bookkeeping fault rather than a dependency, so the
|
||||
// move happens and the warning is the whole of what is said about it.
|
||||
cmd_mv(&args, &root, &mut sink).unwrap();
|
||||
cmd_mv(&args, &root, Attribution::Session, &mut sink).unwrap();
|
||||
sink.warnings()
|
||||
};
|
||||
|
||||
@@ -2475,6 +2642,44 @@ mod sink_tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// A handler takes the attribution `dispatch` was given and never decides one of its
|
||||
/// own.
|
||||
///
|
||||
/// That parameter is what makes a command added tomorrow attributed correctly from
|
||||
/// both callers at once. A handler naming `Attribution::Session` outright would be
|
||||
/// the person's own keystrokes recorded as the agent's again, and it would compile,
|
||||
/// so the compiler cannot be the thing that catches it.
|
||||
#[test]
|
||||
fn no_handler_decides_its_own_attribution() {
|
||||
let mut deciding: Vec<String> = Vec::new();
|
||||
for entry in fs::read_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/src")).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.extension().and_then(|ext| ext.to_str()) != Some("rs") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let source = fs::read_to_string(&path).unwrap();
|
||||
let name = path.file_name().unwrap().to_string_lossy().to_string();
|
||||
deciding.extend(
|
||||
body_of(&source)
|
||||
.map(str::trim)
|
||||
.filter(|line| !line.starts_with("//"))
|
||||
// The definition itself, which is where the parameter is named.
|
||||
.filter(|line| {
|
||||
line.contains("resolve_actor(") && !line.contains("fn resolve_actor(")
|
||||
})
|
||||
.filter(|line| !line.ends_with(", by)") && !line.ends_with(", by),"))
|
||||
.map(|line| format!("{name}: {line}")),
|
||||
);
|
||||
}
|
||||
|
||||
assert!(
|
||||
deciding.is_empty(),
|
||||
"a handler passes the attribution it was dispatched with, `by`, so a line \
|
||||
typed at the board stays the person's:\n{deciding:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A file's lines up to its test module, which in this crate is the only inline
|
||||
/// `mod` at column 0. A file's own assertions are allowed to name a macro the file
|
||||
/// may not call, this test's own body first among them.
|
||||
|
||||
+17
-10
@@ -62,7 +62,9 @@ fn main() -> Result<()> {
|
||||
// it opens the board above the working directory.
|
||||
None => run_tui(&[], &start),
|
||||
Some(Command::Tui { paths }) => run_tui(&paths, &start),
|
||||
Some(command) => dispatch(&command, &start, &mut sink),
|
||||
// Every call `main` dispatches came from a shell or a script, so the session's
|
||||
// own chain answers: `WORKLANE_ACTOR` first, which is what it is set for.
|
||||
Some(command) => dispatch(&command, &start, Attribution::Session, &mut sink),
|
||||
};
|
||||
|
||||
// The board (and every handler) own their own writing, so flush what the last one
|
||||
@@ -84,7 +86,12 @@ fn main() -> Result<()> {
|
||||
/// A command added to [`Command`] therefore lands here once and is runnable from both.
|
||||
/// The match is exhaustive for exactly that reason: there is no `_` arm for a new verb to
|
||||
/// fall into and do nothing.
|
||||
pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
///
|
||||
/// `by` is who the call is being made by, and it is a parameter here rather than a field
|
||||
/// the prompt writes into the parsed arguments: an entry-writing command added tomorrow
|
||||
/// is attributed correctly from both callers without an arm anywhere rewriting what clap
|
||||
/// produced. `main` is the session, the prompt is the person at the board.
|
||||
pub fn dispatch(command: &Command, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> {
|
||||
match command {
|
||||
// Reachable only from the prompt, since `main` takes this arm before it gets
|
||||
// here. A board is not something a board can open.
|
||||
@@ -99,11 +106,11 @@ pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()>
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_show(id, &worklane_dir, sink)
|
||||
}
|
||||
Command::Mv(args) => cmd_mv(args, start, sink),
|
||||
Command::Set(args) => cmd_set(args, start, sink),
|
||||
Command::Append(args) => cmd_append(args, start, sink),
|
||||
Command::Mv(args) => cmd_mv(args, start, by, sink),
|
||||
Command::Set(args) => cmd_set(args, start, by, sink),
|
||||
Command::Append(args) => cmd_append(args, start, by, sink),
|
||||
Command::Relate(args) => cmd_relate(args, start, sink),
|
||||
Command::Chown(args) => cmd_chown(args, start, sink),
|
||||
Command::Chown(args) => cmd_chown(args, start, by, sink),
|
||||
Command::Check(args) => cmd_check(args, true, start, sink),
|
||||
Command::Uncheck(args) => cmd_check(args, false, start, sink),
|
||||
Command::Comment {
|
||||
@@ -111,12 +118,12 @@ pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()>
|
||||
body,
|
||||
actor,
|
||||
actor_from_git,
|
||||
} => cmd_comment(ticket, body, actor, *actor_from_git, start, sink),
|
||||
} => 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),
|
||||
@@ -130,7 +137,7 @@ pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()>
|
||||
ticket,
|
||||
actor,
|
||||
actor_from_git,
|
||||
} => cmd_assign(campaign, ticket, actor, *actor_from_git, start, sink),
|
||||
} => cmd_assign(campaign, ticket, actor, *actor_from_git, start, by, sink),
|
||||
// The bare form and `ls` are one arm: `worklane tags` was the listing before the
|
||||
// group existed and the fish completion still calls it that way, so the two
|
||||
// spellings cannot be allowed to drift into two behaviours.
|
||||
|
||||
+304
-11
@@ -980,12 +980,57 @@ fn command_name(matches: &clap::ArgMatches) -> Option<String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The usage line clap renders for the command the typed line names, or nothing while the
|
||||
/// verb names none.
|
||||
///
|
||||
/// **Clap's own rendering, off the definition the parse uses**, so a flag added to a
|
||||
/// command is described here the day it is added. A table of synopses kept beside it would
|
||||
/// be a second grammar, and it would go stale silently: nothing but a reader typing that
|
||||
/// verb would ever see the two disagree.
|
||||
///
|
||||
/// A verb that resolves to nothing answers `None`. The line is half typed most of the time
|
||||
/// it is looked at, and a complaint about `com` is noise on a row the reader is typing on;
|
||||
/// `refusal` is where a line that was actually entered is answered.
|
||||
///
|
||||
/// A group's child is walked when the second word names one, so `campaign set` describes
|
||||
/// `set` and not `campaign`. While that second word is still half typed the group's own
|
||||
/// usage stands, which is the honest answer: `campaign <COMMAND>` is what has been typed
|
||||
/// so far.
|
||||
///
|
||||
/// The `Usage: ` label is dropped and the rest is kept verbatim. The label names the block
|
||||
/// in a help page of several; this row is one line beside the line it describes, and the
|
||||
/// cells are worth more than the word.
|
||||
fn usage_of(args: &[String]) -> Option<String> {
|
||||
// Colour off for the same reason the parse turns it off: what this row draws is a
|
||||
// ratatui span, and an escape inside one is printed rather than obeyed.
|
||||
let cli = <Cli as clap::CommandFactory>::command().color(clap::ColorChoice::Never);
|
||||
let command = cli.find_subcommand(args.first()?)?;
|
||||
|
||||
// The child by exact name, which is what clap will resolve too. A half-typed one
|
||||
// matches nothing and leaves the group's usage on the row.
|
||||
let command = match args.get(1).and_then(|word| command.find_subcommand(word)) {
|
||||
Some(child) => child,
|
||||
None => command,
|
||||
};
|
||||
|
||||
let usage = command.clone().render_usage().to_string();
|
||||
Some(
|
||||
usage
|
||||
.strip_prefix("Usage: ")
|
||||
.unwrap_or(&usage)
|
||||
.trim()
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
/// The one line the row carries for a line clap would not take.
|
||||
///
|
||||
/// Clap's own message, because the grammar is clap's: a complaint written here would
|
||||
/// describe a rule this file does not own. What is dropped is the usage block and the
|
||||
/// `--help` line after it, which are a paragraph — the synopsis is d7e493e's, and until
|
||||
/// then the row says what is wrong rather than what would have been right.
|
||||
/// `--help` line after it, which are a paragraph: this row says what is wrong, and
|
||||
/// `usage_of` is what says what would have been right, on the same row for as long as the
|
||||
/// verb resolves. A refusal wins the slot while it is up, being what was just said about
|
||||
/// the line that is still there.
|
||||
///
|
||||
/// `--help` is the exception. It parses as an error of the kind that means *print this*,
|
||||
/// and what it would print is a page: caught here, or clap's help lands on the alternate
|
||||
@@ -2520,6 +2565,19 @@ impl Board {
|
||||
.map(str::to_string)
|
||||
}
|
||||
|
||||
/// The usage line of the command the prompt's line names, for the row to draw in place
|
||||
/// of the keys.
|
||||
///
|
||||
/// Derived on every draw and held nowhere, the way `completion` is: what is on the row
|
||||
/// is a function of what is in the line, so the two cannot come to disagree and there
|
||||
/// is no state to clear when the line is edited. The walk is over the clap definition
|
||||
/// alone and reads nothing off the board, since a keypress must not go to disk.
|
||||
fn usage(&self) -> Option<String> {
|
||||
let prompt = self.prompt.as_ref()?;
|
||||
let split = split_line(&prompt.line, prompt.cursor);
|
||||
usage_of(&split.args)
|
||||
}
|
||||
|
||||
/// `tab`: take what every candidate agrees on, and then step through them one press at
|
||||
/// a time.
|
||||
///
|
||||
@@ -2744,7 +2802,12 @@ impl Board {
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
let (outcome, warned) = {
|
||||
let mut sink = Sink::buffer(&mut buffer);
|
||||
let outcome = crate::dispatch(command, &root, &mut sink).and_then(|()| sink.flush());
|
||||
// The person's, not the session's. Nothing but the reader can type this line,
|
||||
// so `WORKLANE_ACTOR` — set where the agents on this machine pick it up, and
|
||||
// inherited by the shell that opened the board — does not describe whoever
|
||||
// pressed enter.
|
||||
let outcome = crate::dispatch(command, &root, Attribution::Person, &mut sink)
|
||||
.and_then(|()| sink.flush());
|
||||
// Read on both outcomes and reported on both: a `mv` that warns about a
|
||||
// dangling blocker and is then refused by a real one wrote the warning
|
||||
// first, and dropping it there would lose the half that says why the
|
||||
@@ -4761,7 +4824,13 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
// and is asked first: an input cannot be covered, and it is the newest of the three
|
||||
// things that can hold the row. Only one of the two prompts can be open at a time.
|
||||
if let Some(prompt) = &board.prompt {
|
||||
draw_prompt(frame, prompt, board.suggestion().as_deref(), area);
|
||||
draw_prompt(
|
||||
frame,
|
||||
prompt,
|
||||
board.suggestion().as_deref(),
|
||||
board.usage().as_deref(),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4974,7 +5043,26 @@ const PROMPT_OPENING: &str = " :";
|
||||
/// of the field rather than a field of its own, so a long command loses the offer instead
|
||||
/// of pushing the keys off the row. The terminal cursor sits on its first cell, which is
|
||||
/// where the cursor already was: what is under a cursor is still what will be typed over.
|
||||
fn draw_prompt(frame: &mut Frame, prompt: &Prompt, suggestion: Option<&str>, area: Rect) {
|
||||
///
|
||||
/// **The usage line takes the keys' slot as soon as the verb resolves.** The reader knows
|
||||
/// the grammar approximately — that `mv` takes a status, not whether it is a positional or
|
||||
/// a flag — and in a shell fish answers that as the line is typed. `esc` and `enter` are
|
||||
/// what the row gives up for it: they are two keys a reader learns once, and the synopsis
|
||||
/// is the thing that is different for every verb. A refusal still wins over both, being
|
||||
/// what was just said about the line that is still on the row.
|
||||
///
|
||||
/// It is grey, the chrome colour: it is not in the line, nothing here is a value, and the
|
||||
/// reader has to tell it from what they typed at a glance. Cut to what the row leaves with
|
||||
/// an ellipsis, never wrapped: the footer is one line, and a second row would reflow the
|
||||
/// columns every time a verb resolved. There is always at least the keys' width for it,
|
||||
/// since that width was taken off the row before the line was windowed.
|
||||
fn draw_prompt(
|
||||
frame: &mut Frame,
|
||||
prompt: &Prompt,
|
||||
suggestion: Option<&str>,
|
||||
usage: Option<&str>,
|
||||
area: Rect,
|
||||
) {
|
||||
let keys = key_hints(&[("↵", "run"), ("esc", "cancel")]);
|
||||
let spent: usize = PROMPT_OPENING.chars().count()
|
||||
+ KEY_GAP.chars().count()
|
||||
@@ -4989,6 +5077,7 @@ fn draw_prompt(frame: &mut Frame, prompt: &Prompt, suggestion: Option<&str>, are
|
||||
let (visible, at) = prompt_window(&prompt.line, prompt.cursor, room);
|
||||
|
||||
let mut spans = vec![Span::raw(format!("{PROMPT_OPENING}{visible}"))];
|
||||
let mut drawn = PROMPT_OPENING.chars().count() + visible.chars().count();
|
||||
|
||||
// Only ever drawn where the cursor is at the end of the line, which is what `visible`
|
||||
// then ends at, so this follows the cursor rather than landing in front of the tail of
|
||||
@@ -4997,16 +5086,30 @@ fn draw_prompt(frame: &mut Frame, prompt: &Prompt, suggestion: Option<&str>, are
|
||||
let left = room.saturating_sub(visible.chars().count());
|
||||
let shown: String = rest.chars().take(left).collect();
|
||||
if !shown.is_empty() {
|
||||
drawn += shown.chars().count();
|
||||
spans.push(Span::styled(shown, Style::default().fg(Color::Grey.into())));
|
||||
}
|
||||
}
|
||||
|
||||
match &prompt.refused {
|
||||
Some(message) => spans.push(Span::styled(
|
||||
match (&prompt.refused, usage) {
|
||||
(Some(message), _) => spans.push(Span::styled(
|
||||
format!("{KEY_GAP}{message}"),
|
||||
Style::default().fg(Color::BrightRed.into()),
|
||||
)),
|
||||
None => {
|
||||
(None, Some(usage)) => {
|
||||
// What the row leaves after the line and the gap. Nothing at all on a terminal
|
||||
// too narrow to hold a cell of it, the bargain the suggestion already takes.
|
||||
let left = (area.width as usize).saturating_sub(drawn + KEY_GAP.chars().count());
|
||||
if left > 0 {
|
||||
let shown = match usage.chars().count() <= left {
|
||||
true => usage.to_string(),
|
||||
false => with_ellipsis(usage, left),
|
||||
};
|
||||
spans.push(Span::raw(KEY_GAP));
|
||||
spans.push(Span::styled(shown, Style::default().fg(Color::Grey.into())));
|
||||
}
|
||||
}
|
||||
(None, None) => {
|
||||
spans.push(Span::raw(KEY_GAP));
|
||||
spans.extend(keys);
|
||||
}
|
||||
@@ -8194,6 +8297,132 @@ approach";
|
||||
assert_eq!(at.y, SCREEN.height - 1, "the cursor left the prompt row");
|
||||
}
|
||||
|
||||
/// The grammar, where the key list was, as soon as the verb resolves: the reader knows
|
||||
/// `mv` takes a status and not whether it is a positional or a flag, which is what a
|
||||
/// shell answers as the line is typed and the board answered with nothing.
|
||||
#[test]
|
||||
fn the_row_shows_the_usage_of_the_command_being_typed() {
|
||||
let dir = searchable();
|
||||
let mut board = one_board(&dir);
|
||||
board.open_prompt();
|
||||
|
||||
// Nothing typed yet, so there is no command to describe and the keys have the slot.
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("esc cancel"), "{row}");
|
||||
|
||||
type_line(&mut board, "mv ");
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(
|
||||
row.contains("mv [OPTIONS] --status <STATUS> <TICKET>"),
|
||||
"the usage is not on the row: {row}"
|
||||
);
|
||||
assert!(
|
||||
!row.contains("esc cancel"),
|
||||
"the keys and the usage both took the slot: {row}"
|
||||
);
|
||||
|
||||
// And it is the grammar of the verb in the line, not of the one typed before it.
|
||||
type_line(&mut board, "1111111");
|
||||
board.prompt_key(ctrl('w'), SCREEN);
|
||||
for _ in 0.."mv ".len() {
|
||||
board.prompt_key(typed(KeyCode::Backspace), SCREEN);
|
||||
}
|
||||
type_line(&mut board, "comment ");
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("comment"), "{row}");
|
||||
assert!(!row.contains("--status"), "the previous verb's usage stayed: {row}");
|
||||
|
||||
// Closing the prompt gives the board's own key list back.
|
||||
board.prompt_key(typed(KeyCode::Esc), SCREEN);
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("quit"), "the key list did not come back: {row}");
|
||||
assert!(!row.contains("--status"), "the usage outlived the prompt: {row}");
|
||||
}
|
||||
|
||||
/// The resolve step on its own: what a verb names, what a group's child names, and what
|
||||
/// a word that names nothing yet does.
|
||||
///
|
||||
/// The values are clap's own rendering off the definition the parse uses, which is why
|
||||
/// this asserts on flags rather than on a synopsis written out here: a table of those
|
||||
/// kept beside the command would go stale the first time a flag was added, and silently,
|
||||
/// since nothing but a reader typing that verb would ever see the two disagree.
|
||||
#[test]
|
||||
fn a_usage_is_clap_s_own_and_a_nested_command_describes_itself() {
|
||||
let usage = |line: &str| {
|
||||
let words: Vec<String> = line.split_whitespace().map(str::to_string).collect();
|
||||
usage_of(&words)
|
||||
};
|
||||
|
||||
let mv = usage("mv").expect("mv names a command");
|
||||
assert!(mv.starts_with("mv "), "the label survived: {mv}");
|
||||
assert!(mv.contains("--status <STATUS>"), "{mv}");
|
||||
assert!(mv.contains("<TICKET>"), "{mv}");
|
||||
|
||||
// The question the ticket is about: which flag the criteria section is under.
|
||||
assert!(usage("set").is_some_and(|set| set.contains("--acceptance")));
|
||||
|
||||
// A group's child describes itself rather than its parent, once both words are
|
||||
// there. `campaign set` takes a campaign; `campaign` alone takes a command.
|
||||
let group = usage("campaign").expect("campaign names a command");
|
||||
assert!(group.contains("<COMMAND>"), "{group}");
|
||||
let child = usage("campaign set").expect("campaign set names a command");
|
||||
assert!(child.contains("<CAMPAIGN>"), "{child}");
|
||||
assert!(!child.contains("<COMMAND>"), "the parent's usage was drawn: {child}");
|
||||
|
||||
// A second word that names no child leaves the group's own usage up, which is what
|
||||
// has been typed so far.
|
||||
assert_eq!(usage("campaign se"), Some(group.clone()));
|
||||
|
||||
// And a verb that names nothing has nothing to say about it.
|
||||
assert_eq!(usage("com"), None);
|
||||
assert_eq!(usage(""), None);
|
||||
assert_eq!(usage_of(&[]), None);
|
||||
}
|
||||
|
||||
/// A line half typed is the state the row is looked at in, so a verb that resolves to
|
||||
/// nothing draws nothing and complains about nothing.
|
||||
#[test]
|
||||
fn a_half_typed_verb_shows_no_usage_and_no_complaint() {
|
||||
let dir = searchable();
|
||||
let mut board = one_board(&dir);
|
||||
board.open_prompt();
|
||||
type_line(&mut board, "com");
|
||||
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("esc cancel"), "the keys lost the slot: {row}");
|
||||
assert!(refused(&board).is_none(), "a half typed verb was refused");
|
||||
assert!(!row.contains("Usage"), "a label reached the row: {row}");
|
||||
}
|
||||
|
||||
/// The footer is one row, whatever the usage is: a second row would reflow the columns
|
||||
/// every time a verb resolved, which is the same reason a notice of several lines is a
|
||||
/// box rather than more footer.
|
||||
#[test]
|
||||
fn a_usage_wider_than_the_row_is_cut_and_leaves_the_columns_alone() {
|
||||
let dir = searchable();
|
||||
let mut board = one_board(&dir);
|
||||
|
||||
// `set` has the longest synopsis in the tool, a flag per section and one per scalar.
|
||||
let narrow = 60;
|
||||
let before = render(&board, narrow, SCREEN.height);
|
||||
|
||||
board.open_prompt();
|
||||
type_line(&mut board, "set ");
|
||||
let after = render(&board, narrow, SCREEN.height);
|
||||
|
||||
assert_eq!(before.len(), after.len(), "the row count changed");
|
||||
assert_eq!(
|
||||
before[..before.len() - 1],
|
||||
after[..after.len() - 1],
|
||||
"the columns moved to make room for the usage"
|
||||
);
|
||||
|
||||
let row = after.last().expect("no rows rendered");
|
||||
assert!(row.chars().count() <= narrow as usize, "the row ran over: {row}");
|
||||
assert!(row.contains('…'), "a usage too wide for the row was not cut: {row}");
|
||||
assert!(row.contains(" :set "), "the line lost its cells to the usage: {row}");
|
||||
}
|
||||
|
||||
/// The line is edited where the cursor is, not at its end, which is the difference
|
||||
/// between a command line and the search prompt's append-only query.
|
||||
#[test]
|
||||
@@ -8422,6 +8651,57 @@ approach";
|
||||
);
|
||||
}
|
||||
|
||||
/// An entry the prompt writes is the reader's own, whatever `WORKLANE_ACTOR` says.
|
||||
///
|
||||
/// The variable is set in the environment an agent runs in, and a person configuring
|
||||
/// it for the agents on their machine exports it where their own shell picks it up
|
||||
/// too — so the shell that opened this board carries it, and without the attribution
|
||||
/// parameter this entry would name the agent.
|
||||
///
|
||||
/// Read against `get_git_user` rather than a literal, since the name depends on the
|
||||
/// machine the suite runs on. With no git user configured there is nobody to name and
|
||||
/// the entry reads `unknown`, which is the same rule and not a fallback to the
|
||||
/// variable.
|
||||
#[test]
|
||||
fn an_entry_written_from_the_prompt_names_the_person() {
|
||||
let (root, mut board) = runnable();
|
||||
let dir = root.join(".worklane");
|
||||
|
||||
run_line(&mut board, "comment 1111111 \"typed at the board\"");
|
||||
assert!(board.prompt.is_none(), "the line was refused: {:?}", refused(&board));
|
||||
|
||||
let log = read_history(&dir, "11111111-0000-4000-8000-000000000000").unwrap();
|
||||
let entry = log
|
||||
.iter()
|
||||
.find(|entry| entry.body == "typed at the board")
|
||||
.expect("the comment was not written");
|
||||
assert_eq!(
|
||||
entry.author,
|
||||
get_git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string()),
|
||||
"the board attributed the reader's own line to somebody else"
|
||||
);
|
||||
|
||||
// And `--actor` still wins, which is how the reader puts somebody else's name on
|
||||
// their own keystrokes.
|
||||
run_line(&mut board, "comment 1111111 \"for alice\" --actor alice");
|
||||
let log = read_history(&dir, "11111111-0000-4000-8000-000000000000").unwrap();
|
||||
let entry = log
|
||||
.iter()
|
||||
.find(|entry| entry.body == "for alice")
|
||||
.expect("the second comment was not written");
|
||||
assert_eq!(entry.author, "alice", "the flag lost to the board's own attribution");
|
||||
|
||||
// The two flags together are clap's refusal, reached here because the prompt
|
||||
// parses against the same definition the shell does rather than a grammar of its
|
||||
// own. A line it refuses keeps the prompt open with the line intact.
|
||||
run_line(&mut board, "comment 1111111 both --actor alice --actor-from-git");
|
||||
assert!(
|
||||
refused(&board).is_some_and(|said| said.contains("cannot be used with")),
|
||||
"the contradictory pair was taken: {:?}",
|
||||
refused(&board)
|
||||
);
|
||||
}
|
||||
|
||||
/// What the handler said is what the board reports, word for word: those messages are
|
||||
/// already written for a person, and a second set kept on the board would go stale the
|
||||
/// first time one of them changed.
|
||||
@@ -8441,7 +8721,7 @@ approach";
|
||||
.unwrap();
|
||||
{
|
||||
let mut sink = Sink::buffer(&mut buffer);
|
||||
crate::dispatch(&command, &root, &mut sink).unwrap();
|
||||
crate::dispatch(&command, &root, Attribution::Session, &mut sink).unwrap();
|
||||
sink.flush().unwrap();
|
||||
}
|
||||
let said = String::from_utf8(buffer).unwrap().trim_end().to_string();
|
||||
@@ -8786,8 +9066,8 @@ approach";
|
||||
|
||||
// What the board calls instead.
|
||||
assert!(
|
||||
here.contains("crate::dispatch(command, &root, &mut sink)"),
|
||||
"the board does not go through the table"
|
||||
here.contains("crate::dispatch(command, &root, Attribution::Person, &mut sink)"),
|
||||
"the board does not go through the table, or it does not attribute to the person"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8913,8 +9193,21 @@ approach";
|
||||
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(!row.contains(":mv"), "the head of the line held the row: {row}");
|
||||
// The slot at the end of the row keeps its width whatever is typed into the line,
|
||||
// which is what taking it off the row before windowing is for. `mv` resolves, so
|
||||
// what holds it is the usage; a verb that resolves to nothing leaves the keys.
|
||||
assert!(row.contains("mv [OPTIONS]"), "a long line pushed the usage off: {row}");
|
||||
|
||||
board.dismiss(SCREEN);
|
||||
board.open_prompt();
|
||||
type_line(&mut board, &format!("nosuchverb {}", "a".repeat(200)));
|
||||
let row = footer(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("esc cancel"), "a long line pushed the keys off: {row}");
|
||||
|
||||
board.dismiss(SCREEN);
|
||||
board.open_prompt();
|
||||
type_line(&mut board, &format!("mv {}", "a".repeat(200)));
|
||||
|
||||
let mut terminal = Terminal::new(TestBackend::new(SCREEN.width, SCREEN.height)).unwrap();
|
||||
terminal.draw(|frame| draw(frame, &board)).unwrap();
|
||||
assert!(
|
||||
|
||||
+144
-19
@@ -649,6 +649,32 @@ pub const ACTOR_ENV: &str = "WORKLANE_ACTOR";
|
||||
/// The author written when nothing names one.
|
||||
pub const UNKNOWN_ACTOR: &str = "unknown";
|
||||
|
||||
/// Who is making the call, which decides whether [`ACTOR_ENV`] describes them.
|
||||
///
|
||||
/// The variable is set once in the environment an agent runs in, so every call that agent
|
||||
/// makes carries its name, which is exactly what a board several agents write to needs. A
|
||||
/// line typed at the command prompt is not one of those calls: nothing but the reader can
|
||||
/// type it, and a person who exported the variable where their own shell picks it up —
|
||||
/// the obvious way to configure it for the agents on that machine — would otherwise watch
|
||||
/// their own `mv` recorded as the agent's.
|
||||
///
|
||||
/// So the board attributes to the person, which is `--actor-from-git`'s precedence
|
||||
/// applied by default rather than asked for. It is a parameter of [`dispatch`] and not a
|
||||
/// field on the parsed arguments, so a command that grows an `--actor` tomorrow is
|
||||
/// attributed correctly from both callers without an arm anywhere rewriting what clap
|
||||
/// produced.
|
||||
///
|
||||
/// [`dispatch`]: crate::dispatch
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Attribution {
|
||||
/// The process's own session: the variable, then the git user. Every call from a
|
||||
/// shell or a script, which is every call `main` dispatches.
|
||||
Session,
|
||||
/// The person at the board: the git user, and [`UNKNOWN_ACTOR`] where none is
|
||||
/// configured, never the variable.
|
||||
Person,
|
||||
}
|
||||
|
||||
/// The actor for the whole run, from the variable alone.
|
||||
///
|
||||
/// Split out from the caching wrapper for the reason `colors_wanted` is: a threaded test
|
||||
@@ -675,11 +701,18 @@ fn session_actor(env: Option<&str>) -> Option<String> {
|
||||
/// has nobody to name, which reads [`UNKNOWN_ACTOR`] rather than quietly attributing
|
||||
/// back to the agent. Without it, today's chain: the variable, then the git user.
|
||||
///
|
||||
/// [`Attribution::Person`] asks for that same lift without the flag, because a line typed
|
||||
/// at the board is the reader's own action and there is nothing to say. The two are one
|
||||
/// branch rather than two: a `--actor-from-git` typed at the prompt asks for what the
|
||||
/// prompt does anyway, and an explicit `--actor` outranks both, which is how the reader
|
||||
/// puts somebody else's name on their own keystrokes.
|
||||
///
|
||||
/// `git_user` is a closure in both branches so the subprocess it costs is not run when
|
||||
/// something ahead of it already answered.
|
||||
fn entry_actor(
|
||||
flag: Option<&str>,
|
||||
from_git: bool,
|
||||
by: Attribution,
|
||||
session: Option<&str>,
|
||||
git_user: impl FnOnce() -> Option<String>,
|
||||
) -> String {
|
||||
@@ -687,7 +720,7 @@ fn entry_actor(
|
||||
return name.to_string();
|
||||
}
|
||||
|
||||
if from_git {
|
||||
if from_git || matches!(by, Attribution::Person) {
|
||||
return git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string());
|
||||
}
|
||||
|
||||
@@ -698,13 +731,14 @@ fn entry_actor(
|
||||
git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string())
|
||||
}
|
||||
|
||||
/// Who to attribute an entry to, from the flags the call carried.
|
||||
/// Who to attribute an entry to, from the flags the call carried and who is calling.
|
||||
///
|
||||
/// Precedence: flag, then — unless `from_git` lifted it — `WORKLANE_ACTOR`, then the git
|
||||
/// user, then `unknown`. Every entry the CLI writes goes through here, so a board
|
||||
/// several agents write to says which of them wrote what instead of attributing all of
|
||||
/// it to one human.
|
||||
pub fn resolve_actor(flag: Option<&str>, from_git: bool) -> String {
|
||||
/// Precedence: flag, then — unless `from_git` or [`Attribution::Person`] lifted it —
|
||||
/// `WORKLANE_ACTOR`, then the git user, then `unknown`. Every entry the CLI writes goes
|
||||
/// through here, so a board several agents write to says which of them wrote what
|
||||
/// instead of attributing all of it to one human, and a line the person typed at the
|
||||
/// board is theirs rather than whichever agent's variable their shell exports.
|
||||
pub fn resolve_actor(flag: Option<&str>, from_git: bool, by: Attribution) -> String {
|
||||
// Each half is decided once, the way should_use_colors is: neither input can change
|
||||
// mid-run, and the git user costs a subprocess. They are two caches rather than one,
|
||||
// because baking the git user into the session's answer would leave `--actor-from-git`
|
||||
@@ -718,7 +752,7 @@ pub fn resolve_actor(flag: Option<&str>, from_git: bool) -> String {
|
||||
session_actor(env.as_deref())
|
||||
});
|
||||
|
||||
entry_actor(flag, from_git, session.as_deref(), || {
|
||||
entry_actor(flag, from_git, by, session.as_deref(), || {
|
||||
GIT_USER.get_or_init(get_git_user).clone()
|
||||
})
|
||||
}
|
||||
@@ -4015,14 +4049,17 @@ mod tests {
|
||||
fn the_variable_names_the_actor() {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(entry_actor(None, false, session.as_deref(), git_user), "claude");
|
||||
assert_eq!(
|
||||
entry_actor(None, false, Attribution::Session, session.as_deref(), git_user),
|
||||
"claude"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_flag_overrides_the_variable() {
|
||||
let session = session_actor(Some("claude"));
|
||||
assert_eq!(
|
||||
entry_actor(Some("opencode"), false, session.as_deref(), || None),
|
||||
entry_actor(Some("opencode"), false, Attribution::Session, session.as_deref(), || None),
|
||||
"opencode"
|
||||
);
|
||||
}
|
||||
@@ -4032,7 +4069,13 @@ mod tests {
|
||||
fn the_git_user_is_the_fallback() {
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(None, false, session_actor(None).as_deref(), git_user),
|
||||
entry_actor(
|
||||
None,
|
||||
false,
|
||||
Attribution::Session,
|
||||
session_actor(None).as_deref(),
|
||||
git_user
|
||||
),
|
||||
"Ansho Rei"
|
||||
);
|
||||
}
|
||||
@@ -4045,7 +4088,10 @@ mod tests {
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
for raw in ["", " "] {
|
||||
let session = session_actor(Some(raw));
|
||||
assert_eq!(entry_actor(None, false, session.as_deref(), git_user), "Ansho Rei");
|
||||
assert_eq!(
|
||||
entry_actor(None, false, Attribution::Session, session.as_deref(), git_user),
|
||||
"Ansho Rei"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4053,9 +4099,15 @@ mod tests {
|
||||
#[test]
|
||||
fn nothing_at_all_is_unknown() {
|
||||
let session = session_actor(None);
|
||||
assert_eq!(entry_actor(None, false, session.as_deref(), || None), UNKNOWN_ACTOR);
|
||||
assert_eq!(
|
||||
entry_actor(None, false, Attribution::Session, session.as_deref(), || None),
|
||||
UNKNOWN_ACTOR
|
||||
);
|
||||
// An empty flag falls through rather than writing a blank author
|
||||
assert_eq!(entry_actor(Some(""), false, None, || None), UNKNOWN_ACTOR);
|
||||
assert_eq!(
|
||||
entry_actor(Some(""), false, Attribution::Session, None, || None),
|
||||
UNKNOWN_ACTOR
|
||||
);
|
||||
}
|
||||
|
||||
/// Free text, validated against nothing, the way the `chown` user is.
|
||||
@@ -4063,7 +4115,7 @@ mod tests {
|
||||
fn an_actor_is_free_text() {
|
||||
let session = session_actor(Some("claude-code, session 3 (opus)"));
|
||||
assert_eq!(
|
||||
entry_actor(None, false, session.as_deref(), || None),
|
||||
entry_actor(None, false, Attribution::Session, session.as_deref(), || None),
|
||||
"claude-code, session 3 (opus)"
|
||||
);
|
||||
}
|
||||
@@ -4074,7 +4126,10 @@ mod tests {
|
||||
fn from_git_lifts_the_git_user_over_the_variable() {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(entry_actor(None, true, session.as_deref(), git_user), "Ansho Rei");
|
||||
assert_eq!(
|
||||
entry_actor(None, true, Attribution::Session, session.as_deref(), git_user),
|
||||
"Ansho Rei"
|
||||
);
|
||||
}
|
||||
|
||||
/// An explicit `--actor` still wins outright beside the lift: it names somebody
|
||||
@@ -4084,7 +4139,7 @@ mod tests {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(Some("opencode"), true, session.as_deref(), git_user),
|
||||
entry_actor(Some("opencode"), true, Attribution::Session, session.as_deref(), git_user),
|
||||
"opencode"
|
||||
);
|
||||
}
|
||||
@@ -4094,7 +4149,10 @@ mod tests {
|
||||
#[test]
|
||||
fn from_git_with_no_git_user_is_unknown_not_the_variable() {
|
||||
let session = session_actor(Some("claude"));
|
||||
assert_eq!(entry_actor(None, true, session.as_deref(), || None), UNKNOWN_ACTOR);
|
||||
assert_eq!(
|
||||
entry_actor(None, true, Attribution::Session, session.as_deref(), || None),
|
||||
UNKNOWN_ACTOR
|
||||
);
|
||||
}
|
||||
|
||||
/// An empty variable still counts as unset with the lift on, which here means the
|
||||
@@ -4103,11 +4161,78 @@ mod tests {
|
||||
fn from_git_leaves_the_empty_variable_unset() {
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(None, true, session_actor(Some("")).as_deref(), git_user),
|
||||
entry_actor(
|
||||
None,
|
||||
true,
|
||||
Attribution::Session,
|
||||
session_actor(Some("")).as_deref(),
|
||||
git_user
|
||||
),
|
||||
"Ansho Rei"
|
||||
);
|
||||
}
|
||||
|
||||
/// The board's own case, and the reason this parameter exists: the person who
|
||||
/// exported `WORKLANE_ACTOR` for the agents on their machine types a command at the
|
||||
/// prompt, and the entry is theirs. No flag was given and none should have to be.
|
||||
#[test]
|
||||
fn a_line_typed_at_the_board_is_the_persons() {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(None, false, Attribution::Person, session.as_deref(), git_user),
|
||||
"Ansho Rei"
|
||||
);
|
||||
}
|
||||
|
||||
/// `--actor` still wins there, which is how the reader puts somebody else's name on
|
||||
/// their own keystrokes.
|
||||
#[test]
|
||||
fn the_flag_wins_over_the_board_too() {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(Some("alice"), false, Attribution::Person, session.as_deref(), git_user),
|
||||
"alice"
|
||||
);
|
||||
}
|
||||
|
||||
/// And the lift is not a fallback here either. A machine with no git user configured
|
||||
/// has nobody to name, and writing the variable's value would be the agent's name on
|
||||
/// the person's move, which is the whole thing this avoids.
|
||||
#[test]
|
||||
fn the_board_with_no_git_user_is_unknown_not_the_variable() {
|
||||
let session = session_actor(Some("claude"));
|
||||
assert_eq!(
|
||||
entry_actor(None, false, Attribution::Person, session.as_deref(), || None),
|
||||
UNKNOWN_ACTOR
|
||||
);
|
||||
}
|
||||
|
||||
/// `--actor-from-git` typed at the prompt asks for what the prompt does anyway, so
|
||||
/// the two together are the one lift rather than two that could disagree.
|
||||
#[test]
|
||||
fn from_git_at_the_board_is_the_same_lift() {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(None, true, Attribution::Person, session.as_deref(), git_user),
|
||||
"Ansho Rei"
|
||||
);
|
||||
}
|
||||
|
||||
/// The session's own chain is untouched: the same command typed in a shell is still
|
||||
/// the variable's, which is what keeps a board several agents write to legible.
|
||||
#[test]
|
||||
fn the_session_keeps_the_variable_over_the_git_user() {
|
||||
let session = session_actor(Some("claude"));
|
||||
let git_user = || Some("Ansho Rei".to_string());
|
||||
assert_eq!(
|
||||
entry_actor(None, false, Attribution::Session, session.as_deref(), git_user),
|
||||
"claude"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unset_values_are_dimmed_and_set_ones_are_not() {
|
||||
// Both paths, now that the colour decision is a parameter: with colour off the
|
||||
|
||||
+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