(07ac4e1) Filter campaign ls by state, and lay its listing out as a table, and bump to 0.33.6
campaign ls printed every campaign and offered no way to narrow it, and the row was assembled by hand, so a long title pushed the standing out of line with the row above it and the created date the file already carries was not shown at all. --state takes open, done or empty and matches against Standing::state(), so the derived value keeps one definition: a campaign reads [open] in the listing if and only if --state open lists it. --state rather than --status, which names one of the five ticket statuses everywhere else and would invite --state backlog here. empty is the third value because an empty campaign derives None deliberately, and 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 names the value back, since a silent listing reads as the other empty case. The filter reaches --ids as well, the way ls --ids keeps its own, and is the only thing that makes that path count members: an unfiltered completion is as cheap as it was. The columns are measured on the raw values and padded before anything is painted, the rule metadata_cells follows. 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 one most rows pad into and some leave empty, and what a reader lines up is where a name ends and its progress begins. A flag's possible values now come off the command that holds the flag, so campaign ls --state reaches ls's own arguments rather than campaign's. The prompt offered nothing there while fish offered the three values, which made a liar of the rule that a ValueEnum added anywhere is typeable on the board the day it is added. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
3e732535f8
commit
634a1f44c4
+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