(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
+26
-4
@@ -858,14 +858,15 @@ impl ChownArgs {
|
||||
}
|
||||
}
|
||||
|
||||
/// `append` only offers the sections that hold multiple lines, since appending to a
|
||||
/// scalar has no meaning.
|
||||
/// `append` offers the fields something can be added to without disturbing what is
|
||||
/// already in them: the three sections that hold multiple lines, and Tags, which is a
|
||||
/// list. Appending to a scalar has no meaning, so there is no `--priority` or `--due`.
|
||||
#[derive(clap::Args)]
|
||||
#[command(group(
|
||||
clap::ArgGroup::new("append_fields")
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
.args(["description", "acceptance", "plan"])
|
||||
.args(["description", "acceptance", "plan", "tags"])
|
||||
))]
|
||||
pub struct AppendArgs {
|
||||
/// Ticket UUID or title
|
||||
@@ -882,6 +883,24 @@ pub struct AppendArgs {
|
||||
/// Add implementation plan steps, numbered on from the last. Repeat the flag
|
||||
#[arg(short, long, allow_hyphen_values = PROSE)]
|
||||
pub plan: Vec<String>,
|
||||
|
||||
/// Add tags, keeping the ones the ticket already carries. Repeat the flag, or
|
||||
/// separate them with commas
|
||||
///
|
||||
/// `non_empty` rather than the `clearable` that `set --tags` takes. That message
|
||||
/// names `--clear`, and this command has none: emptying the field is
|
||||
/// `set --clear tags`, so pointing at a flag that is not here would send the caller
|
||||
/// looking for it on `append`.
|
||||
#[arg(short = 'g', long, value_parser = non_empty)]
|
||||
pub tags: Vec<String>,
|
||||
|
||||
/// Only reaches the entry `--tags` writes, since that is the one field of this
|
||||
/// command's that is logged, exactly as on `set`
|
||||
#[arg(long, help = ACTOR_HELP)]
|
||||
pub actor: Option<String>,
|
||||
|
||||
#[arg(long, conflicts_with = "actor", help = ACTOR_FROM_GIT_HELP)]
|
||||
pub actor_from_git: bool,
|
||||
}
|
||||
|
||||
/// `relate` is the only writer of the Relations section, the way `chown` is the only
|
||||
@@ -1080,6 +1099,9 @@ mod tests {
|
||||
|
||||
// A guard on the walker itself: if it stopped finding commands, every assertion
|
||||
// above would pass by never running.
|
||||
assert_eq!(seen, 5, "expected comment, mv, chown, set and assign to carry --actor");
|
||||
assert_eq!(
|
||||
seen, 6,
|
||||
"expected comment, mv, chown, set, append and assign to carry --actor"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+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}");
|
||||
|
||||
@@ -1135,12 +1135,83 @@ pub fn cmd_append(args: &AppendArgs, start: &Path, sink: &mut Sink) -> Result<()
|
||||
changed.push(section.label);
|
||||
}
|
||||
|
||||
// Through `apply`, unlike the sections above: appending a section always adds
|
||||
// something, and appending a tag the ticket already carries is the no-op this flag
|
||||
// exists to make free.
|
||||
if !args.tags.is_empty() {
|
||||
let next =
|
||||
set_metadata_field(&content, "Tags", &appended_tags(&content, &args.tags)?, &title)?;
|
||||
apply(&mut content, &mut changed, "tags", next);
|
||||
}
|
||||
|
||||
// The only way to reach here with nothing to write is a `--tags` the ticket already
|
||||
// satisfied, since every other field on this command adds or refuses. Reported in the
|
||||
// words `set` uses for the same answer.
|
||||
if changed.is_empty() {
|
||||
report(sink, &[], &title, "Appended to")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
save_ticket(&worklane_dir, &status, &uuid, &title, None, &content)?;
|
||||
|
||||
// Tags are logged wherever they change, so the one command that adds to them without
|
||||
// replacing them logs too. Same shape as `set`'s, down to the before and after being
|
||||
// read off the field rather than off the flag: what the entry records is where the
|
||||
// field went, not what this call asked for.
|
||||
if changed.contains(&"tags") {
|
||||
write_entry(
|
||||
&worklane_dir,
|
||||
&uuid,
|
||||
Kind::Tags,
|
||||
&change(
|
||||
&parse_ticket_field(&original, "Tags"),
|
||||
&parse_ticket_field(&content, "Tags"),
|
||||
),
|
||||
&resolve_actor(args.actor.as_deref(), args.actor_from_git),
|
||||
"",
|
||||
)?;
|
||||
}
|
||||
|
||||
report(sink, &changed, &title, "Appended to")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The ticket's tags with the call's merged onto the end, or the refusal for a call that
|
||||
/// named none.
|
||||
///
|
||||
/// A tag the ticket already carries is not added a second time, which is the whole
|
||||
/// difference from `set --tags`: appending means the caller does not have to know what is
|
||||
/// there already, so naming one that is reports no change rather than doubling it. New
|
||||
/// ones go on the end in the order they were given rather than sorted, so the field goes
|
||||
/// on reading as what was added when.
|
||||
///
|
||||
/// The 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, which is what `tag_value`
|
||||
/// refuses outright for the vocabulary; here it is split instead, because `set --tags`
|
||||
/// takes the comma form on this same field and refusing it on its counterpart would be a
|
||||
/// trap.
|
||||
///
|
||||
/// A call whose every value comes out blank is refused rather than written, the way
|
||||
/// [`appended_items`] refuses one: `--tags ","` names nothing, and writing the field back
|
||||
/// unchanged would report an append that never happened. Emptying the field is
|
||||
/// `set --clear tags`.
|
||||
fn appended_tags(content: &str, values: &[String]) -> Result<String> {
|
||||
let added: Vec<String> = values.iter().flat_map(|value| split_tags(value)).collect();
|
||||
if added.is_empty() {
|
||||
return Err(anyhow!("Nothing to append to the tags: every value given was blank"));
|
||||
}
|
||||
|
||||
let mut tags = parse_tags(content);
|
||||
for tag in added {
|
||||
if !tags.contains(&tag) {
|
||||
tags.push(tag);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(tags.join(", "))
|
||||
}
|
||||
|
||||
/// Record a relation from one ticket to another.
|
||||
///
|
||||
/// One side is written and the inverse is derived wherever it is shown. `blocked by`
|
||||
|
||||
+10
@@ -1608,6 +1608,16 @@ pub fn parse_tags(content: &str) -> Vec<String> {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
split_tags(&value)
|
||||
}
|
||||
|
||||
/// The tags in one comma-separated value, trimmed and without the empty ones.
|
||||
///
|
||||
/// Split out of [`parse_tags`] because a value typed on the command line is separated the
|
||||
/// same way the stored field is: `append --tags "bug, tui"` names two tags, and merging
|
||||
/// that into what a ticket already carries has to see two or it stores the pair as one
|
||||
/// tag and adds it again on the next call.
|
||||
pub fn split_tags(value: &str) -> Vec<String> {
|
||||
value
|
||||
.split(',')
|
||||
.map(str::trim)
|
||||
|
||||
Reference in New Issue
Block a user