@@ -77,12 +77,12 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
7777 } ;
7878
7979 match selected_item {
80- MainMenuOptions :: Status => get_status ( & db) ?,
81- MainMenuOptions :: GetLink => get_link_options ( & db) ?,
82- MainMenuOptions :: AddLink => add_link_options ( & db) ?,
83- MainMenuOptions :: DeleteLink => delete_link_options ( & db) ?,
84- MainMenuOptions :: SearchLink => search_link_options ( & db) ?,
85- MainMenuOptions :: Other => show_other_options ( & db) ?,
80+ MainMenuOptions :: Status => get_status ( db) ?,
81+ MainMenuOptions :: GetLink => get_link_options ( db) ?,
82+ MainMenuOptions :: AddLink => add_link_options ( db) ?,
83+ MainMenuOptions :: DeleteLink => delete_link_options ( db) ?,
84+ MainMenuOptions :: SearchLink => search_link_options ( db) ?,
85+ MainMenuOptions :: Other => show_other_options ( db) ?,
8686 MainMenuOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
8787 }
8888
@@ -196,19 +196,16 @@ fn delete_link_options(db: &Db) -> Result<(), CustomErrors> {
196196 _ => unreachable ! ( ) ,
197197 } ;
198198
199- loop {
200- match selected_option {
201- DeleteOptions :: DeleteLink => {
202- match db. delete_link ( link) {
203- Ok ( _) => show_green ( "Successfully deleted the link" ) ,
204- Err ( e) => return Err ( e) ,
205- } ;
206- break ;
207- }
208- DeleteOptions :: MainMenu => break ,
209- DeleteOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
210- } ;
211- }
199+ match selected_option {
200+ DeleteOptions :: DeleteLink => {
201+ match db. delete_link ( link) {
202+ Ok ( _) => show_green ( "Successfully deleted the link" ) ,
203+ Err ( e) => return Err ( e) ,
204+ } ;
205+ }
206+ DeleteOptions :: MainMenu => ( ) ,
207+ DeleteOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
208+ } ;
212209
213210 Ok ( ( ) )
214211}
@@ -237,26 +234,22 @@ fn single_link_options(db: &Db, link: &str) -> Result<(), CustomErrors> {
237234 _ => unreachable ! ( ) ,
238235 } ;
239236
240- loop {
241- match selected_option {
242- GetLinkOptions :: MarkAsComplete => {
243- match db. mark_as_complete ( link) {
244- Ok ( _) => show_green ( "Successfully marked the link as completed" ) ,
245- Err ( e) => return Err ( e) ,
246- } ;
247- break ;
248- }
249- GetLinkOptions :: Skip => {
250- match db. skip_link ( link) {
251- Ok ( _) => show_green ( "Successfully skipped the link" ) ,
252- Err ( e) => return Err ( e) ,
253- } ;
254- break ;
255- }
256- GetLinkOptions :: MainMenu => break ,
257- GetLinkOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
258- } ;
259- }
237+ match selected_option {
238+ GetLinkOptions :: MarkAsComplete => {
239+ match db. mark_as_complete ( link) {
240+ Ok ( _) => show_green ( "Successfully marked the link as completed" ) ,
241+ Err ( e) => return Err ( e) ,
242+ } ;
243+ }
244+ GetLinkOptions :: Skip => {
245+ match db. skip_link ( link) {
246+ Ok ( _) => show_green ( "Successfully skipped the link" ) ,
247+ Err ( e) => return Err ( e) ,
248+ } ;
249+ }
250+ GetLinkOptions :: MainMenu => ( ) ,
251+ GetLinkOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
252+ } ;
260253
261254 Ok ( ( ) )
262255}
@@ -316,59 +309,46 @@ fn show_other_options(db: &Db) -> Result<(), CustomErrors> {
316309 _ => unreachable ! ( ) ,
317310 } ;
318311
319- loop {
320- match selected_option {
321- OtherOptions :: ShowAllLinks => match db. get_all_links ( ) {
322- Ok ( val) => {
323- match val {
324- Some ( all_links) => pretty_print ( & all_links) ,
325- None => show_red ( "No Links present in the database :(" ) ,
326- }
327- break ;
328- }
329- Err ( e) => return Err ( e) ,
312+ match selected_option {
313+ OtherOptions :: ShowAllLinks => match db. get_all_links ( ) {
314+ Ok ( val) => match val {
315+ Some ( all_links) => pretty_print ( & all_links) ,
316+ None => show_red ( "No Links present in the database :(" ) ,
330317 } ,
331- OtherOptions :: ShowCompletedLinks => match db. get_completed_links ( ) {
332- Ok ( val) => {
333- match val {
334- Some ( completed_links) => pretty_print ( & completed_links) ,
335- None => show_red ( "No Completed Links :(" ) ,
336- }
337- break ;
338- }
339- Err ( e) => return Err ( e) ,
318+ Err ( e) => return Err ( e) ,
319+ } ,
320+ OtherOptions :: ShowCompletedLinks => match db. get_completed_links ( ) {
321+ Ok ( val) => match val {
322+ Some ( completed_links) => pretty_print ( & completed_links) ,
323+ None => show_red ( "No Completed Links :(" ) ,
340324 } ,
341- OtherOptions :: ShowSkippedLinks => match db. get_skipped_links ( ) {
342- Ok ( val) => {
343- match val {
344- Some ( skipped_links) => pretty_print ( & skipped_links) ,
345- None => show_red ( "No Skipped Links :)" ) ,
346- }
347- break ;
348- }
349- Err ( e) => return Err ( e) ,
325+ Err ( e) => return Err ( e) ,
326+ } ,
327+ OtherOptions :: ShowSkippedLinks => match db. get_skipped_links ( ) {
328+ Ok ( val) => match val {
329+ Some ( skipped_links) => pretty_print ( & skipped_links) ,
330+ None => show_red ( "No Skipped Links :)" ) ,
350331 } ,
351- OtherOptions :: SkippedToIncomplete => {
352- match db. skipped_to_incomplete ( ) {
353- Ok ( count) => show_green (
354- format ! ( "Changed {} Skipped Links To Incomplete Links" , count) . as_str ( ) ,
355- ) ,
356- Err ( e) => return Err ( e) ,
357- } ;
358- break ;
359- }
360- OtherOptions :: CompletedToIncomplete => {
361- match db. completed_to_incomplete ( ) {
362- Ok ( count) => show_green (
363- format ! ( "Changed {} Completed Links To Incomplete Links" , count) . as_str ( ) ,
364- ) ,
365- Err ( e) => return Err ( e) ,
366- } ;
367- break ;
368- }
369- OtherOptions :: MainMenu => break ,
370- OtherOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
332+ Err ( e) => return Err ( e) ,
333+ } ,
334+ OtherOptions :: SkippedToIncomplete => {
335+ match db. skipped_to_incomplete ( ) {
336+ Ok ( count) => show_green (
337+ format ! ( "Changed {} Skipped Links To Incomplete Links" , count) . as_str ( ) ,
338+ ) ,
339+ Err ( e) => return Err ( e) ,
340+ } ;
341+ }
342+ OtherOptions :: CompletedToIncomplete => {
343+ match db. completed_to_incomplete ( ) {
344+ Ok ( count) => show_green (
345+ format ! ( "Changed {} Completed Links To Incomplete Links" , count) . as_str ( ) ,
346+ ) ,
347+ Err ( e) => return Err ( e) ,
348+ } ;
371349 }
350+ OtherOptions :: MainMenu => ( ) ,
351+ OtherOptions :: Exit => return Err ( CustomErrors :: Exit ) ,
372352 }
373353
374354 Ok ( ( ) )
0 commit comments