(8556048) Take a relation off with relate --clear, and bump to 0.32.0
`relate` only added. A `--blocked-by` pointed at the wrong ticket was on that ticket forever, refusing every move it made until the target was done or `-f` was passed again, and a target that was deleted did not clean up either: the board carried a dead edge that nothing could clear and every later read of the ticket paid for. `--clear <kind> <target>` takes one off. It is on `relate` rather than on `set` for the reason `RELATIONS` is out of `section_args`: a relation names a target that has to be resolved first, so one writer owns both directions, the way `chown` owns setting an owner and clearing one. It names the target and not just the kind, because a ticket can hold several relations of one kind and emptying all of them is not what anybody is asking for. That is also why it is not spelled the way `set --clear` is, which names a field and empties it whole. Both spellings of the kind are taken, `blocked-by` from the flag and `blocked by` from the label: both are in front of the reader, the flag being what recorded the relation and the label what `show` prints and the file stores, so refusing the printed form would trap anyone clearing a row they had just read. `RelationKind::flag` is a match rather than a `replace` on the label, so the flag, the `--clear` value and the completion list cannot drift. `find_relation` searches the ticket's own edges by id prefix before it searches the board, and that order is the feature rather than an optimisation: no search of the board reaches a target whose ticket is gone, so the stored-target tier is the only thing that can clear a dangling edge, which is the case most likely to need clearing. Two stored targets under one prefix name the candidates instead of guessing, as an ambiguous ticket search already does. An edge the ticket does not hold reports no change, and a target naming nothing at all is an error. The two are different facts: the first is the state the caller asked for, and the second is a typo that a no-op would swallow. The resolver's own reason is carried through, so an ambiguous search says it is ambiguous rather than being reported as nothing found. Recording and clearing the same relation in one call is refused, and the check runs on what was *asked* for and not on what would be written. A relation already in the file is not among the additions, so comparing against those would have let `--blocked-by X --clear blocked-by X` quietly remove it. Removals rewrite the section from what is left and additions are appended to that, in that order and in two passes: a call with no `--clear` then takes exactly the path it always took. The last edge leaves the placeholder, which is the line `append` treats as no content, so the next `relate` replaces it rather than writing underneath it. The two values are one flag, so clap cannot type them apart. `num_args = 2` is per occurrence, which makes an odd number a usage error and every chunk a full pair, and `cleared` parses the kind before the ticket is resolved. Nothing is logged, in either direction, since `relate` never has: a log recording only the destructive half would read as though the additions had never happened. `chowns_clear_is_completed_with_tickets_and_sets_is_not` found the first rule carrying `-l clear` and there are now three, on three commands, each taking something different. It is `each_clear_flag_is_completed_for_its_own_command`, scoped per command, and `relate --clear` offers the kinds rather than a board listing, since tickets where the kind goes would be candidates it refuses. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
7994d98913
commit
0f0767ac00
+76
@@ -2129,6 +2129,45 @@ impl RelationKind {
|
||||
RelationKind::RegressionOf,
|
||||
RelationKind::RelatesTo,
|
||||
];
|
||||
|
||||
/// How the kind is spelled at the command line: the flag that records it, without
|
||||
/// the leading hyphens.
|
||||
///
|
||||
/// A match rather than `label().replace(' ', "-")`, so the pairing is pinned and the
|
||||
/// completion list, the `--clear` value and the flag cannot drift apart.
|
||||
pub fn flag(self) -> &'static str {
|
||||
match self {
|
||||
RelationKind::BlockedBy => "blocked-by",
|
||||
RelationKind::RegressionOf => "regression-of",
|
||||
RelationKind::RelatesTo => "relates-to",
|
||||
}
|
||||
}
|
||||
|
||||
/// One kind from the value `relate --clear` names, or an error listing the three.
|
||||
///
|
||||
/// Both spellings are accepted, the flag's `blocked-by` and the label's `blocked by`,
|
||||
/// because both are in front of the reader: the flag is what recorded the relation and
|
||||
/// the label is what `show` prints in the block and what the file stores. Refusing the
|
||||
/// form the tool itself prints would be a trap for anyone clearing a row they just
|
||||
/// read. Case insensitive, the bargain the id and codename tiers already take.
|
||||
pub fn parse_value(value: &str) -> Result<Self> {
|
||||
let wanted = value.trim().to_lowercase().replace('-', " ");
|
||||
|
||||
RelationKind::ALL
|
||||
.into_iter()
|
||||
.find(|kind| kind.label() == wanted)
|
||||
.ok_or_else(|| {
|
||||
anyhow!(
|
||||
"'{}' is not a relation kind. The kinds are {}",
|
||||
value,
|
||||
RelationKind::ALL
|
||||
.iter()
|
||||
.map(|kind| kind.flag())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// One stored edge: a kind, and the full uuid of the ticket it points at.
|
||||
@@ -5579,6 +5618,43 @@ Plain line with **bold** and a [link](http://x.test/a).
|
||||
assert_eq!(seen.len(), 3, "{seen:?}");
|
||||
}
|
||||
|
||||
/// Every kind is reachable by the flag that records it and by the label `show` prints,
|
||||
/// in any case, and every kind has a flag of its own. Over `RelationKind::ALL` rather
|
||||
/// than the three names, so a kind added later has to be spellable too.
|
||||
#[test]
|
||||
fn a_kind_parses_from_the_flag_spelling_and_the_label_spelling() {
|
||||
let mut flags = std::collections::HashSet::new();
|
||||
|
||||
for kind in RelationKind::ALL {
|
||||
assert!(flags.insert(kind.flag()), "{kind:?} shares its flag with another kind");
|
||||
assert_eq!(kind.flag(), kind.label().replace(' ', "-"), "{kind:?}");
|
||||
|
||||
for spelling in [kind.flag().to_string(), kind.label().to_string()] {
|
||||
for cased in [spelling.to_lowercase(), spelling.to_uppercase()] {
|
||||
assert_eq!(
|
||||
RelationKind::parse_value(&cased).unwrap(),
|
||||
kind,
|
||||
"{cased:?} does not parse as {kind:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A value that is not a kind names the three, in the spelling the flags and the
|
||||
/// completions use rather than the spelling the file stores: a reader who has just
|
||||
/// been refused is about to retype the flag.
|
||||
#[test]
|
||||
fn a_value_that_is_not_a_kind_names_the_three() {
|
||||
let refused = RelationKind::parse_value("depends-on").expect_err("accepted");
|
||||
let message = refused.to_string();
|
||||
|
||||
assert!(message.contains("not a relation kind"), "{message}");
|
||||
for kind in RelationKind::ALL {
|
||||
assert!(message.contains(kind.flag()), "{kind:?} is not named: {message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Both directions of one kind carry the same mark, since the kind is what the mark
|
||||
/// says and the label is what says which way it points.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user