Skip to content

Commit 31ad6aa

Browse files
committed
added option to search link
1 parent 21b48d1 commit 31ad6aa

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "abhyas"
3-
version = "1.0.1"
3+
version = "1.1.0"
44
edition = "2021"
55
authors = ["Harshal Jadhav <bestt1315@gmail.com>"]
66
homepage = "https://github.com/halshar/abhyas"

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Abhyas is a Rust command-line application for managing and interacting with a da
44

55
### Features
66

7-
- **Add Links**: Add new links to the database.
8-
- **Show Options**: View and interact with available options.
7+
- **Get Link**: Get random link from the database.
8+
- **Add Link**: Add new links to the database.
9+
- **Search Link**: Search link from the database.
10+
- **Other**: View and interact with other available options.
911
- **Insert Links from File**: Add links from a specified file to the database.
1012

1113
### Requirements

src/cli.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use inquire::{required, validator::Validation, Select, Text};
77
enum MainMenuOptions {
88
GetLink,
99
AddLink,
10+
SearchLink,
1011
Other,
1112
Exit,
1213
}
@@ -29,7 +30,7 @@ enum OtherOptions {
2930
}
3031

3132
pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
32-
let options = vec!["Get Link", "Add Link", "Other", "Exit"];
33+
let options = vec!["Get Link", "Add Link", "Search Link", "Other", "Exit"];
3334

3435
let user_option = match Select::new("select your option", options).prompt() {
3536
Ok(val) => val,
@@ -51,6 +52,7 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
5152
let selected_item = match user_option {
5253
"Get Link" => MainMenuOptions::GetLink,
5354
"Add Link" => MainMenuOptions::AddLink,
55+
"Search Link" => MainMenuOptions::SearchLink,
5456
"Other" => MainMenuOptions::Other,
5557
"Exit" => MainMenuOptions::Exit,
5658
_ => unreachable!(),
@@ -59,6 +61,7 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
5961
match selected_item {
6062
MainMenuOptions::GetLink => get_link_options(&db)?,
6163
MainMenuOptions::AddLink => add_link_options(&db)?,
64+
MainMenuOptions::SearchLink => search_link_options(&db)?,
6265
MainMenuOptions::Other => show_other_options(&db)?,
6366
MainMenuOptions::Exit => return Err(CustomErrors::Exit),
6467
}
@@ -176,6 +179,23 @@ fn single_link_options(db: &Db, link: &str) -> Result<(), CustomErrors> {
176179
Ok(())
177180
}
178181

182+
fn search_link_options(db: &Db) -> Result<(), CustomErrors> {
183+
let links = db.get_links()?;
184+
185+
let link = match Select::new("select link or type keywords", links).prompt() {
186+
Ok(val) => val,
187+
Err(_) => {
188+
return Err(CustomErrors::Others(
189+
"Error: Something went wrong while searching links".to_owned(),
190+
))
191+
}
192+
};
193+
194+
single_link_options(db, &link)?;
195+
196+
Ok(())
197+
}
198+
179199
fn show_other_options(db: &Db) -> Result<(), CustomErrors> {
180200
let options = vec![
181201
"Show All Links?",

0 commit comments

Comments
 (0)