Fixed when you a disambiguated name in first

Still should probably clean up the return values.

Also should look into how to exit early from the script
This commit is contained in:
2025-08-21 03:07:38 +01:00
parent 43a75c0b92
commit 6b5034c544
4 changed files with 28 additions and 5 deletions

View File

@@ -17,12 +17,16 @@ impl Termination for MtgCardExit {
MtgCardExit::EmptySearchString => ExitCode::from(101),
MtgCardExit::NoExactMatchCard => ExitCode::from(102),
MtgCardExit::DidYouMean => ExitCode::from(105),
MtgCardExit::ExactCardFound => ExitCode::from(200),
MtgCardExit::UpdateSuccess => ExitCode::from(201),
}
}
}
enum MtgCardExit {
Success,
UpdateSuccess,
ExactCardFound,
EmptySearchString,
NoExactMatchCard,
DidYouMean,
@@ -51,7 +55,7 @@ fn exact_search(search_strings: Vec<String>) -> MtgCardExit {
}
Some(c) => {
println!("{}", c);
MtgCardExit::Success
MtgCardExit::ExactCardFound
}
}
}
@@ -76,7 +80,7 @@ fn main() -> MtgCardExit {
path.push(update);
// FIXME - if you pass a bad file or something, it just deletes the db
update_db_with_file(path);
return MtgCardExit::Success;
return MtgCardExit::UpdateSuccess;
}
if args.search_text.is_empty() {
dbg!("You need to put some card text to search");
@@ -109,9 +113,11 @@ fn main() -> MtgCardExit {
}
return MtgCardExit::DidYouMean;
} else if matching_cards.len() == 1 {
let card = get_card_by_name(&matching_cards[0].name, GetNameType::LowercaseName).unwrap();
// FIXME - theres a bug in here - try searching Nalf
let card = get_card_by_name(&matching_cards[0].name, GetNameType::Name).unwrap();
println!("{}", card);
return MtgCardExit::Success;
// TODO update this to be more meaningful
return MtgCardExit::ExactCardFound;
} else {
for card in matching_cards {
println!(
@@ -121,6 +127,7 @@ fn main() -> MtgCardExit {
.name
);
}
// TODO update this to be more meaningful
return MtgCardExit::Success;
}
}