(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
+22
-1
@@ -167,6 +167,16 @@ pub fn argument_at(args: &[String], index: usize) -> Option<Argument> {
|
||||
let verb = args.first().map(String::as_str)?;
|
||||
let group = cli.find_subcommand(verb);
|
||||
|
||||
// The command a flag belongs to, which is the *nested* one where a group's child
|
||||
// carries it: `--state` is `campaign ls`'s and clap holds it on `ls`, not on
|
||||
// `campaign`. Falls back to the group itself, which is where every other flag is, and
|
||||
// to nothing for a line whose second word names no subcommand — `mv 1b78a24 --status`
|
||||
// reaches `mv`'s own arguments as it always did.
|
||||
let holder = args
|
||||
.get(1)
|
||||
.and_then(|child| group.and_then(|group| group.find_subcommand(child)))
|
||||
.or(group);
|
||||
|
||||
// A flag's value is the argument after it, which is where the flag sits whether the
|
||||
// value is half typed or has not been started.
|
||||
if let Some(flag) = args.get(index - 1).and_then(|arg| arg.strip_prefix("--")) {
|
||||
@@ -187,7 +197,9 @@ pub fn argument_at(args: &[String], index: usize) -> Option<Argument> {
|
||||
// And everything else the flag could take, which is whatever clap knows: `--status`
|
||||
// and `set --clear` are both `ValueEnum`s, so their values are already written down
|
||||
// once, in the enum.
|
||||
let arg = group?.get_arguments().find(|arg| arg.get_long() == Some(flag))?;
|
||||
let arg = holder?
|
||||
.get_arguments()
|
||||
.find(|arg| arg.get_long() == Some(flag))?;
|
||||
return fixed(arg);
|
||||
}
|
||||
|
||||
@@ -762,6 +774,15 @@ mod tests {
|
||||
assert!(shells.contains(&"fish".to_string()), "{shells:?}");
|
||||
}
|
||||
|
||||
/// The flag on a nested command is answered the same way, from the enum: nothing here
|
||||
/// knows what a campaign's states are, and the values reach the prompt and fish alike
|
||||
/// the day a fourth one is added to `CampaignState`.
|
||||
#[test]
|
||||
fn campaign_ls_state_is_offered_the_enums_own_values() {
|
||||
let states = values("campaign ls --state ").expect("--state takes a state");
|
||||
assert_eq!(states, vec!["open", "done", "empty"], "{states:?}");
|
||||
}
|
||||
|
||||
/// `relate --clear` takes the kind and then the target, which is the one argument clap
|
||||
/// cannot answer for: possible values on the flag would refuse every target.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user