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:
@@ -90,7 +90,11 @@ Fingers crossed that all compiled and stuff... then copy the bin
|
|||||||
cp build/rofi ~/bin
|
cp build/rofi ~/bin
|
||||||
```
|
```
|
||||||
|
|
||||||
## TODO & Features That Could be Good
|
## FIXME, TODO & Features That Could be Good
|
||||||
|
* Remove the non-card cards. Examples I've come across are:
|
||||||
|
** Planes: Black Lotus Lounge
|
||||||
|
** Art Cards: https://scryfall.com/card/altr/15/%C3%A9owyn-fearless-knight-%C3%A9owyn-fearless-knight?utm_source=api
|
||||||
|
* Allow exiting the script early (i.e. I hit CTRL+g just exits everything)
|
||||||
* Misspelled cards, if only 1 hit that makes sense, could just work
|
* Misspelled cards, if only 1 hit that makes sense, could just work
|
||||||
* Display the actual card image (probably won't do this)
|
* Display the actual card image (probably won't do this)
|
||||||
* Some kind of auto-magic direct link between the return codes set out in `main.r`s and the `rofi` scripts. Currently I need to manually make sure they're the same between the `rust` code and the `sh` code.
|
* Some kind of auto-magic direct link between the return codes set out in `main.r`s and the `rofi` scripts. Currently I need to manually make sure they're the same between the `rust` code and the `sh` code.
|
||||||
|
|||||||
@@ -7,6 +7,16 @@ CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_de
|
|||||||
RETURN=$?
|
RETURN=$?
|
||||||
echo $RETURN
|
echo $RETURN
|
||||||
|
|
||||||
|
#######################
|
||||||
|
## Exact card found - just print the card
|
||||||
|
#######################
|
||||||
|
if [ $RETURN -eq 200 ]; then
|
||||||
|
|
||||||
|
rofi -e "$CARDS"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
## Cards to select from
|
## Cards to select from
|
||||||
#######################
|
#######################
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ pub fn get_card_by_name(name: &str, name_type: GetNameType) -> Option<DbCard> {
|
|||||||
FROM cards WHERE lowercase_name = (?1)"
|
FROM cards WHERE lowercase_name = (?1)"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
dbg!(name);
|
||||||
|
dbg!(&sql);
|
||||||
let mut stmt = conn.prepare(sql).unwrap();
|
let mut stmt = conn.prepare(sql).unwrap();
|
||||||
let mut rows = stmt.query([name]).unwrap();
|
let mut rows = stmt.query([name]).unwrap();
|
||||||
match rows.next().unwrap() {
|
match rows.next().unwrap() {
|
||||||
|
|||||||
@@ -17,12 +17,16 @@ impl Termination for MtgCardExit {
|
|||||||
MtgCardExit::EmptySearchString => ExitCode::from(101),
|
MtgCardExit::EmptySearchString => ExitCode::from(101),
|
||||||
MtgCardExit::NoExactMatchCard => ExitCode::from(102),
|
MtgCardExit::NoExactMatchCard => ExitCode::from(102),
|
||||||
MtgCardExit::DidYouMean => ExitCode::from(105),
|
MtgCardExit::DidYouMean => ExitCode::from(105),
|
||||||
|
MtgCardExit::ExactCardFound => ExitCode::from(200),
|
||||||
|
MtgCardExit::UpdateSuccess => ExitCode::from(201),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MtgCardExit {
|
enum MtgCardExit {
|
||||||
Success,
|
Success,
|
||||||
|
UpdateSuccess,
|
||||||
|
ExactCardFound,
|
||||||
EmptySearchString,
|
EmptySearchString,
|
||||||
NoExactMatchCard,
|
NoExactMatchCard,
|
||||||
DidYouMean,
|
DidYouMean,
|
||||||
@@ -51,7 +55,7 @@ fn exact_search(search_strings: Vec<String>) -> MtgCardExit {
|
|||||||
}
|
}
|
||||||
Some(c) => {
|
Some(c) => {
|
||||||
println!("{}", c);
|
println!("{}", c);
|
||||||
MtgCardExit::Success
|
MtgCardExit::ExactCardFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +80,7 @@ fn main() -> MtgCardExit {
|
|||||||
path.push(update);
|
path.push(update);
|
||||||
// FIXME - if you pass a bad file or something, it just deletes the db
|
// FIXME - if you pass a bad file or something, it just deletes the db
|
||||||
update_db_with_file(path);
|
update_db_with_file(path);
|
||||||
return MtgCardExit::Success;
|
return MtgCardExit::UpdateSuccess;
|
||||||
}
|
}
|
||||||
if args.search_text.is_empty() {
|
if args.search_text.is_empty() {
|
||||||
dbg!("You need to put some card text to search");
|
dbg!("You need to put some card text to search");
|
||||||
@@ -109,9 +113,11 @@ fn main() -> MtgCardExit {
|
|||||||
}
|
}
|
||||||
return MtgCardExit::DidYouMean;
|
return MtgCardExit::DidYouMean;
|
||||||
} else if matching_cards.len() == 1 {
|
} 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);
|
println!("{}", card);
|
||||||
return MtgCardExit::Success;
|
// TODO update this to be more meaningful
|
||||||
|
return MtgCardExit::ExactCardFound;
|
||||||
} else {
|
} else {
|
||||||
for card in matching_cards {
|
for card in matching_cards {
|
||||||
println!(
|
println!(
|
||||||
@@ -121,6 +127,7 @@ fn main() -> MtgCardExit {
|
|||||||
.name
|
.name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// TODO update this to be more meaningful
|
||||||
return MtgCardExit::Success;
|
return MtgCardExit::Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user