@@ -14,7 +14,7 @@ pub fn request(url: String) -> Result<Value, Box<dyn std::error::Error>> {
1414
1515fn construct_header ( ) -> HeaderMap {
1616 let mut headers = HeaderMap :: new ( ) ;
17- headers. insert ( USER_AGENT , "User " . parse ( ) . unwrap ( ) ) ;
17+ headers. insert ( USER_AGENT , "GSTATS " . parse ( ) . unwrap ( ) ) ;
1818 headers. insert ( ACCEPT , "application/vnd.github.v3+json" . parse ( ) . unwrap ( ) ) ;
1919 return headers;
2020}
@@ -25,14 +25,18 @@ pub fn pretty_dates(date: &str) -> String {
2525 format ! ( "{}-{}-{}" , date[ 2 ] , date[ 1 ] , date[ 0 ] )
2626}
2727
28- pub fn validate_path ( path : String ) -> Result < PathBuf , String > {
28+ pub fn validate_and_convert_path ( path : String ) -> Result < PathBuf , String > {
2929 let real_path = Path :: new ( & path) ;
3030
31- if !real_path. exists ( ) {
32- return Err ( format ! ( "Failed to find path \" {}\" " , path) ) ;
31+ if real_path. is_file ( ) {
32+ println ! ( "A file was found at the path: \" {}\" " , path) ;
33+ println ! ( "Would you like to clear the file and continue? [y/N]" ) ;
34+ let mut input = String :: new ( ) ;
35+ std:: io:: stdin ( ) . read_line ( & mut input) . unwrap ( ) ;
36+ if input. trim ( ) . to_lowercase ( ) != "y" {
37+ return Err ( "A file already exists at the path." . to_owned ( ) ) ;
38+ }
3339 }
3440
35-
36-
3741 Ok ( real_path. to_owned ( ) )
3842}
0 commit comments