@@ -16,7 +16,7 @@ pub struct Cli {
16
16
Outputs the contents of MFT found in the root of the volume and calculates what will be restored.
17
17
"#
18
18
) ]
19
- dry_run : bool ,
19
+ pub dry_run : bool ,
20
20
21
21
#[ arg(
22
22
long,
@@ -25,7 +25,7 @@ Outputs the contents of MFT found in the root of the volume and calculates what
25
25
The path to which the restored files will be written.
26
26
"#
27
27
) ]
28
- output_dir : PathBuf ,
28
+ pub output_dir : PathBuf ,
29
29
30
30
#[ arg(
31
31
long,
@@ -34,39 +34,44 @@ The path to which the restored files will be written.
34
34
The path to the image of file system to be restored that was retrieved with dd.
35
35
"#
36
36
) ]
37
- image : PathBuf ,
38
- }
39
-
40
- pub struct CliParsed {
41
- pub dry_run : bool ,
42
- pub output_dir : PathBuf ,
43
37
pub image : PathBuf ,
44
38
}
45
39
46
- impl CliParsed {
40
+ impl Cli {
47
41
pub fn display ( & self ) {
48
42
info ! ( "Configured with dry-run: {}" , self . dry_run) ;
49
43
info ! ( "Configured with output-dir: {}" , self . output_dir. display( ) ) ;
50
- info ! ( "Configured with volume : {}" , self . image. display( ) ) ;
44
+ info ! ( "Configured with image : {}" , self . image. display( ) ) ;
51
45
}
52
46
53
- pub fn parse_and_validate ( args : Cli ) -> Result < Self , UndeleteError > {
54
- if !args . image . exists ( ) {
47
+ pub fn parse_and_validate ( self ) -> Result < Self , UndeleteError > {
48
+ if !self . image . exists ( ) {
55
49
return Err ( UndeleteError :: Parse (
56
- "Specified volume is Non-existant!" . to_string ( ) ,
50
+ "Specified image is Non-existant!" . to_string ( ) ,
57
51
) ) ;
58
52
}
59
53
60
- Ok ( args. into ( ) )
54
+ if !self . output_dir . exists ( ) && !self . dry_run {
55
+ return Err ( UndeleteError :: Parse (
56
+ "Specified output directory is Non-existant!" . to_string ( ) ,
57
+ ) ) ;
58
+ }
59
+
60
+ Ok ( self )
61
61
}
62
62
}
63
63
64
- impl From < Cli > for CliParsed {
65
- fn from ( value : Cli ) -> Self {
66
- CliParsed {
67
- dry_run : value. dry_run ,
68
- output_dir : value. output_dir ,
69
- image : value. image ,
70
- }
64
+ #[ cfg( test) ]
65
+ mod tests {
66
+ use super :: * ;
67
+
68
+ #[ test]
69
+ fn test_parse_and_validate_non_existant_image ( ) {
70
+ let args = Cli :: parse_and_validate ( Cli {
71
+ dry_run : false ,
72
+ image : PathBuf :: from ( "non-existant/ntfs.dd" ) ,
73
+ output_dir : PathBuf :: from ( "src" ) ,
74
+ } ) ;
75
+ assert ! ( args. is_err( ) ) ;
71
76
}
72
77
}
0 commit comments