@@ -4,6 +4,7 @@ use inquire::{validator::Validation, CustomUserError, Text};
4
4
use regex:: Regex ;
5
5
6
6
use super :: Params ;
7
+ use indoc:: indoc;
7
8
8
9
pub fn get_params_from_user ( ) -> Result < Params , String > {
9
10
let project_root = get_project_root_from_user ( ) ?;
@@ -18,6 +19,7 @@ fn get_project_root_from_user() -> Result<PathBuf, String> {
18
19
Text :: new ( "Project root directory path:" )
19
20
. with_validator ( validate_project_root_is_not_special)
20
21
. with_validator ( validate_project_root_is_dir)
22
+ . with_validator ( validate_project_root_is_not_current_dir)
21
23
. with_validator ( validate_project_root_contains_project_descriptor)
22
24
. prompt ( )
23
25
. map ( |project_root| PathBuf :: from ( project_root) )
@@ -44,6 +46,26 @@ fn validate_project_root_is_dir(project_root: &str) -> Result<Validation, Custom
44
46
}
45
47
}
46
48
49
+ fn validate_project_root_is_not_current_dir (
50
+ project_root : & str ,
51
+ ) -> Result < Validation , CustomUserError > {
52
+ let project_root = PathBuf :: from ( project_root) ;
53
+ let current_dir = std:: env:: current_dir ( ) . map_err ( |err| err. to_string ( ) ) ?;
54
+ let abs_current_dir = fs:: canonicalize ( current_dir) . map_err ( |err| err. to_string ( ) ) ?;
55
+ let abs_project_root = fs:: canonicalize ( project_root) . map_err ( |err| err. to_string ( ) ) ?;
56
+
57
+ if abs_project_root == abs_current_dir {
58
+ let error_message = indoc ! { "
59
+ Provided directory is the current directory which is protected
60
+ Move to the parent directory and try again\
61
+ "} ;
62
+
63
+ return Ok ( Validation :: Invalid ( error_message. into ( ) ) ) ;
64
+ }
65
+
66
+ Ok ( Validation :: Valid )
67
+ }
68
+
47
69
fn validate_project_root_contains_project_descriptor (
48
70
project_root : & str ,
49
71
) -> Result < Validation , CustomUserError > {
0 commit comments