Fix validator lookup by title.

We want the lookup to yield a result when there's only a single
  validator; and no title is provided. So that users can simply do
  'aiken address' in their project if it's unambiguous. The validator's
  name is only required to disambiguate between multiple validators.

  I also noticed that the order of arguments in with_validator was
  wrong. Somehow.
This commit is contained in:
KtorZ 2023-02-16 10:28:11 +01:00
parent 20841962f6
commit 3204322da6
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
5 changed files with 6 additions and 5 deletions

View File

@ -714,6 +714,7 @@ impl<'comments> Formatter<'comments> {
let document = match expr { let document = match expr {
UntypedExpr::ByteArray { bytes, .. } => self.bytearray(bytes), UntypedExpr::ByteArray { bytes, .. } => self.bytearray(bytes),
UntypedExpr::If { UntypedExpr::If {
branches, branches,
final_else, final_else,

View File

@ -820,6 +820,7 @@ impl<'a> CodeGenerator<'a> {
} }
}; };
#[allow(clippy::bool_to_int_with_if)]
let minus_tail = if has_tail { 1 } else { 0 }; let minus_tail = if has_tail { 1 } else { 0 };
if current_clause_index as i64 - minus_tail == prev_index { if current_clause_index as i64 - minus_tail == prev_index {

View File

@ -61,8 +61,7 @@ where
let mut validator = None; let mut validator = None;
for v in self.validators.iter() { for v in self.validators.iter() {
let match_title = title.map(|t| v.title.contains(t)).unwrap_or(false); let match_title = Some(&v.title) == title.or(Some(&v.title));
if match_title { if match_title {
validator = Some(if validator.is_none() { validator = Some(if validator.is_none() {
LookupResult::One(v) LookupResult::One(v)
@ -78,8 +77,8 @@ where
pub fn with_validator<F, A, E>( pub fn with_validator<F, A, E>(
&self, &self,
title: Option<&String>, title: Option<&String>,
when_missing: fn(Vec<String>) -> E,
when_too_many: fn(Vec<String>) -> E, when_too_many: fn(Vec<String>) -> E,
when_missing: fn(Vec<String>) -> E,
action: F, action: F,
) -> Result<A, E> ) -> Result<A, E>
where where

View File

@ -45,7 +45,7 @@ pub fn exec(
validator validator
.as_ref() .as_ref()
.map(|v| format!(".{v}")) .map(|v| format!(".{v}"))
.unwrap_or("".to_string()) .unwrap_or_default()
) )
}); });

View File

@ -46,7 +46,7 @@ pub fn exec(
validator validator
.as_ref() .as_ref()
.map(|v| format!(".{v}")) .map(|v| format!(".{v}"))
.unwrap_or("".to_string()) .unwrap_or_default()
) )
}); });