(a1a5d69) Add tags to a ticket with append --tags, keeping the ones it carries, and bump to 0.32.18
`set --tags` writes the whole field, so adding one tag to a ticket that
already carries some meant reading it first and retyping every one of
them. 30a2b34 wrote that down in the skill as the way to do it; this is
the flag that makes it unnecessary.
The merge is idempotent and ordered. A tag the ticket already carries is
reported as no change rather than added twice, which is the point of the
flag: the caller does not have to know what is there. A new one goes on
the end in the order it was given rather than sorting the field under
whoever last touched it. Values are split on commas the way the stored
field is, so `--tags "bug, tui"` names two tags and matches the two a
ticket carrying them already holds; without that the pair would land as
a single tag nothing can filter by and would not match itself on the
next call. `split_tags` is that rule, lifted out of `parse_tags` so the
argument and the field are separated by the same code.
It writes the same `Kind::Tags` entry `set --tags` writes, so `--actor`
and `--actor-from-git` come with it. Tags are logged wherever they move,
and the one command that adds to them without replacing them would
otherwise be the one tag change the log missed. The before and after are
read off the field rather than off the flag, so an append of `beta` onto
`alpha` reads as the pair and not as what the call asked for.
`non_empty` rather than the `clearable` that `set --tags` takes: that
message names `--clear`, and `append` has none, so it would send the
caller looking here for a flag that is `set`'s. A value that is only
separators reaches the handler and is refused there, in the words
`appended_items` refuses an all-blank section with. Emptying the field
stays `set --clear tags`.
`TAG_FLAGS` becomes pairs of command and flag, because `ls --tag` and
`append --tags` are spelled differently and one rule naming both options
would tell fish that each command accepts the other's. `add --tags` and
`set --tags` deliberately get no value rule and are recorded in the
test's `TAG_LIST_FLAGS` instead: they take the whole list, so the token
at the cursor is `bug,tui` and fish replaces a token entire, throwing
away what is already typed. The honesty test now walks `tag` and `tags`
both, so the next tag argument has to say which of the two it is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b4534eb86d
commit
7470255a22
+51
-11
@@ -64,12 +64,22 @@ pub const CAMPAIGN_NESTED_COMMANDS: [(&str, &str); 3] = [
|
||||
/// Options whose value is a campaign.
|
||||
pub const CAMPAIGN_FLAGS: [&str; 1] = ["campaign"];
|
||||
|
||||
/// Options whose value is a tag.
|
||||
/// Options whose value is a tag, as the command that takes it and the flag's long name.
|
||||
///
|
||||
/// Its own list rather than a line in the block below, because the values come from a
|
||||
/// different command: a tag is not an object with an id, so `worklane tags` answers this
|
||||
/// one where `ls --ids` answers the tickets.
|
||||
pub const TAG_FLAGS: [&str; 1] = ["tag"];
|
||||
///
|
||||
/// Pairs rather than the flat list the other flag lists are, because the two spellings
|
||||
/// differ: `ls --tag` filters on one and `append --tags` adds them, so a single rule
|
||||
/// naming both options would tell fish that each command takes the other's flag. One
|
||||
/// rule per pair instead.
|
||||
///
|
||||
/// `add --tags` and `set --tags` are deliberately absent. Both take the *whole* list, so
|
||||
/// the token being completed is `bug,tui` and fish replaces a token entire: offering one
|
||||
/// tag there would throw away the ones already typed. `append --tags` is the one where
|
||||
/// naming a single tag is the ordinary call.
|
||||
pub const TAG_FLAGS: [(&str, &str); 2] = [("ls", "tag"), ("append", "tags")];
|
||||
|
||||
/// Nested commands whose first argument is a tag the board already has.
|
||||
///
|
||||
@@ -110,7 +120,16 @@ fn fish_dynamic() -> String {
|
||||
.collect::<Vec<_>>()
|
||||
.join("; or ");
|
||||
let campaign_flags = flag_list(&CAMPAIGN_FLAGS);
|
||||
let tag_flags = flag_list(&TAG_FLAGS);
|
||||
let tag_flags = TAG_FLAGS
|
||||
.iter()
|
||||
.map(|(command, flag)| {
|
||||
format!(
|
||||
"complete -c worklane -n '__worklane_command_is {command}' -l {flag} \\\n \
|
||||
-x -a '(worklane tags | cut -f1,3)'"
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let tag_nested = TAG_NESTED_COMMANDS
|
||||
.iter()
|
||||
.map(|(parent, child)| format!("__worklane_nested_arg_of {parent} {child}"))
|
||||
@@ -218,8 +237,10 @@ complete -c worklane -n '__worklane_command_is ls' {campaign_flags} \
|
||||
# What is left is the annotation, and a tag the board carries but has never declared has
|
||||
# none: it is offered with no description at all, which is the near-duplicate the file was
|
||||
# added to catch. The count used to be the description and said the same thing more weakly.
|
||||
complete -c worklane -n '__worklane_command_is ls' {tag_flags} \
|
||||
-x -a '(worklane tags | cut -f1,3)'
|
||||
#
|
||||
# One rule per command, from `TAG_FLAGS`: `ls --tag` and `append --tags` are spelled
|
||||
# differently, so a single rule naming both options would offer each under the other.
|
||||
{tag_flags}
|
||||
|
||||
# And `tags set` names one that is already declared, so it reads the same listing. `tags
|
||||
# add` has no rule on purpose: it takes a tag the board does not have, so the candidates
|
||||
@@ -410,14 +431,28 @@ mod tests {
|
||||
/// about what the fish block is missing, which is a test's question.
|
||||
const TAG_NEW_COMMANDS: [(&str, &str); 1] = [("tags", "add")];
|
||||
|
||||
/// Options taking a whole comma-separated list of tags rather than one.
|
||||
///
|
||||
/// `add --tags` and `set --tags` write the field entire, so what is being typed at the
|
||||
/// cursor is `bug,tui` and fish replaces a token whole: a rule offering one tag there
|
||||
/// would throw away the ones already in the token. `append --tags` adds to what is
|
||||
/// there, so a single tag is the ordinary value and it earns a rule. Recorded rather
|
||||
/// than skipped, for the reason `TAG_NEW_COMMANDS` is: the next `--tags` has to say
|
||||
/// which of the two it is.
|
||||
const TAG_LIST_FLAGS: [(&str, &str); 2] = [("add", "tags"), ("set", "tags")];
|
||||
|
||||
/// Tags have their own list because their values come from `worklane tags` rather than
|
||||
/// from a listing of objects, so a second tag-taking option would need that rule and
|
||||
/// not the campaign one.
|
||||
///
|
||||
/// Both spellings are walked, `tag` and `tags`: they are the same object under two
|
||||
/// argument names, and looking at only the singular is how `set --tags` went years
|
||||
/// without anybody deciding whether it wanted a rule.
|
||||
#[test]
|
||||
fn no_tag_taking_option_is_missing() {
|
||||
let mut seen = 0;
|
||||
for (path, arg) in every_argument() {
|
||||
if arg.get_id().as_str() != "tag" {
|
||||
if !matches!(arg.get_id().as_str(), "tag" | "tags") {
|
||||
continue;
|
||||
}
|
||||
seen += 1;
|
||||
@@ -440,13 +475,18 @@ mod tests {
|
||||
continue;
|
||||
};
|
||||
|
||||
let pair = (name.as_str(), long);
|
||||
assert!(
|
||||
TAG_FLAGS.contains(&long),
|
||||
"`worklane {name} --{long}` takes a tag but is not in TAG_FLAGS"
|
||||
TAG_FLAGS.contains(&pair) || TAG_LIST_FLAGS.contains(&pair),
|
||||
"`worklane {name} --{long}` takes a tag, so it belongs in TAG_FLAGS if one \
|
||||
tag is the ordinary value and TAG_LIST_FLAGS if the value is the whole list"
|
||||
);
|
||||
}
|
||||
|
||||
assert_eq!(seen, 3, "expected ls --tag, tags add and tags set");
|
||||
assert_eq!(
|
||||
seen, 6,
|
||||
"expected ls --tag, tags add, tags set, add --tags, set --tags and append --tags"
|
||||
);
|
||||
}
|
||||
|
||||
/// **Every rule naming an option has to say which command it belongs to.** A bare
|
||||
@@ -589,8 +629,8 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
reading.len(),
|
||||
2,
|
||||
"expected the ls --tag rule and the tags set one: {reading:?}"
|
||||
3,
|
||||
"expected the ls --tag rule, the append --tags one and the tags set one: {reading:?}"
|
||||
);
|
||||
for line in reading {
|
||||
assert!(line.contains("(worklane tags | cut -f1,3)"), "{line}");
|
||||
|
||||
Reference in New Issue
Block a user