1- use crate :: print:: pretty_print;
1+ use crate :: print:: { pretty_print, pretty_status } ;
22use crate :: utility:: show_red;
33use crate :: CustomErrors ;
44use crate :: { database:: Db , utility:: show_green} ;
55use inquire:: { required, validator:: Validation , Select , Text } ;
66
77enum MainMenuOptions {
8+ Status ,
89 GetLink ,
910 AddLink ,
1011 SearchLink ,
@@ -30,7 +31,14 @@ enum OtherOptions {
3031}
3132
3233pub fn show_options ( db : & Db ) -> Result < ( ) , CustomErrors > {
33- let options = vec ! [ "Get Link" , "Add Link" , "Search Link" , "Other" , "Exit" ] ;
34+ let options = vec ! [
35+ "Check Status" ,
36+ "Get Link" ,
37+ "Add Link" ,
38+ "Search Link" ,
39+ "Other" ,
40+ "Exit" ,
41+ ] ;
3442
3543 let user_option = match Select :: new ( "select your option" , options) . prompt ( ) {
3644 Ok ( val) => val,
@@ -50,6 +58,7 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
5058 } ;
5159
5260 let selected_item = match user_option {
61+ "Check Status" => MainMenuOptions :: Status ,
5362 "Get Link" => MainMenuOptions :: GetLink ,
5463 "Add Link" => MainMenuOptions :: AddLink ,
5564 "Search Link" => MainMenuOptions :: SearchLink ,
@@ -59,6 +68,7 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
5968 } ;
6069
6170 match selected_item {
71+ MainMenuOptions :: Status => get_status ( & db) ?,
6272 MainMenuOptions :: GetLink => get_link_options ( & db) ?,
6373 MainMenuOptions :: AddLink => add_link_options ( & db) ?,
6474 MainMenuOptions :: SearchLink => search_link_options ( & db) ?,
@@ -69,6 +79,21 @@ pub fn show_options(db: &Db) -> Result<(), CustomErrors> {
6979 Ok ( ( ) )
7080}
7181
82+ fn get_status ( db : & Db ) -> Result < ( ) , CustomErrors > {
83+ match db. get_status ( ) {
84+ Ok ( val) => {
85+ match val {
86+ Some ( ( total_links, completed_links, skipped_links) ) => {
87+ pretty_status ( total_links, completed_links, skipped_links)
88+ }
89+ None => pretty_status ( 0 , 0 , 0 ) ,
90+ } ;
91+ }
92+ Err ( e) => return Err ( e) ,
93+ } ;
94+ Ok ( ( ) )
95+ }
96+
7297fn get_link_options ( db : & Db ) -> Result < ( ) , CustomErrors > {
7398 let link = match db. get_single_link ( ) {
7499 Ok ( val) => match val {
0 commit comments