Accept embedded layer names in CLI selectors
Resolve scope and display selectors against both revisions before projection. Keep display-only selection on the large-file comparison path and list numeric choices for ambiguous names.
This commit is contained in:
parent
4ae689cd1c
commit
87683db7e8
2 changed files with 209 additions and 35 deletions
|
|
@ -68,6 +68,30 @@ pub fn parse_layer(value: &str) -> Result<Layer, String> {
|
|||
Ok((decimal(a)?, decimal(b)?))
|
||||
}
|
||||
|
||||
/// Find the unique numeric pair for an exact name across the supplied revisions.
|
||||
pub fn resolve_layer_name<'a>(
|
||||
name: &str,
|
||||
revisions: impl IntoIterator<Item = &'a BTreeMap<Layer, String>>,
|
||||
) -> Result<Layer, String> {
|
||||
let matches: BTreeSet<_> = revisions
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|(&pair, label)| (label == name).then_some(pair))
|
||||
.collect();
|
||||
match matches.len() {
|
||||
0 => Err(format!("unknown layer name {name:?}")),
|
||||
1 => Ok(*matches.first().unwrap()),
|
||||
_ => {
|
||||
let choices = matches
|
||||
.into_iter()
|
||||
.map(|(layer, datatype)| format!("{layer}/{datatype}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
Err(format!("ambiguous layer name {name:?} (choose {choices})"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn decimal(value: &str) -> Result<u16, String> {
|
||||
if value.is_empty() || !value.bytes().all(|b| b.is_ascii_digit()) {
|
||||
return Err("layer numbers must be unsigned decimal integers".to_string());
|
||||
|
|
|
|||
|
|
@ -184,6 +184,11 @@ impl<'a> RevisionPair<'a> {
|
|||
Comparison::collect(&self.old, &self.new, &self.reused_cells, true)
|
||||
}
|
||||
|
||||
/// Resolve a layer name from the embedded metadata in either revision.
|
||||
pub fn resolve_layer_name(&self, name: &str) -> Result<Layer, String> {
|
||||
names::resolve_layer_name(name, [&self.old.layer_names, &self.new.layer_names])
|
||||
}
|
||||
|
||||
pub fn compare_text(self) -> TextComparison {
|
||||
TextComparison::collect(&self.old, &self.new, &self.reused_cells)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue