14
14
15
15
mod diff_util;
16
16
17
- use std:: { fs, io, path:: PathBuf } ;
18
-
19
17
use clap:: Parser ;
20
18
use diff_util:: {
21
19
common:: { FormatOptions , OutputFormat } ,
22
20
diff_exit_status:: DiffExitStatus ,
23
21
dir_diff:: DirDiff ,
24
22
file_diff:: FileDiff ,
25
- functions:: check_existance ,
23
+ functions:: check_existence ,
26
24
} ;
27
25
use gettextrs:: { bind_textdomain_codeset, setlocale, textdomain, LocaleCategory } ;
26
+ use std:: { fs, io, path:: PathBuf } ;
28
27
29
28
/// diff - compare two files
30
29
#[ derive( Parser , Clone ) ]
@@ -54,6 +53,10 @@ struct Args {
54
53
#[ arg( short, long) ]
55
54
recurse : bool ,
56
55
56
+ /// Print a message even when there are no differences between files
57
+ #[ arg( short = 's' , long = "report-identical-files" ) ]
58
+ report_identical_files : bool ,
59
+
57
60
/// Output 3 lines of unified context
58
61
#[ arg( short) ]
59
62
unified3 : bool ,
@@ -103,17 +106,16 @@ impl From<&Args> for OutputFormat {
103
106
}
104
107
105
108
fn check_difference ( args : Args ) -> io:: Result < DiffExitStatus > {
106
- let path1 = PathBuf :: from ( & args. file1 ) ;
107
- let path2 = PathBuf :: from ( & args. file2 ) ;
109
+ let path1 = PathBuf :: from ( args. file1 . as_str ( ) ) ;
110
+ let path2 = PathBuf :: from ( args. file2 . as_str ( ) ) ;
108
111
109
- let path1_exists = check_existance ( & path1) ? ;
110
- let path2_exists = check_existance ( & path2) ? ;
112
+ let path1_path = path1. as_path ( ) ;
113
+ let path2_path = path2. as_path ( ) ;
111
114
112
- if !path1_exists || !path2_exists {
113
- return Ok ( DiffExitStatus :: Trouble ) ;
114
- }
115
+ let path1_exists = check_existence ( path1_path) ;
116
+ let path2_exists = check_existence ( path2_path) ;
115
117
116
- if path1 == path2 {
118
+ if !path1_exists || !path2_exists {
117
119
return Ok ( DiffExitStatus :: Trouble ) ;
118
120
}
119
121
@@ -124,18 +126,24 @@ fn check_difference(args: Args) -> io::Result<DiffExitStatus> {
124
126
output_format,
125
127
args. label ,
126
128
args. label2 ,
129
+ args. report_identical_files ,
127
130
) ;
131
+
128
132
let format_options = format_options. unwrap ( ) ;
129
133
130
- let path1_is_file = fs:: metadata ( & path1 ) ?. is_file ( ) ;
131
- let path2_is_file = fs:: metadata ( & path2 ) ?. is_file ( ) ;
134
+ let path1_is_file = fs:: metadata ( path1_path ) ?. is_file ( ) ;
135
+ let path2_is_file = fs:: metadata ( path2_path ) ?. is_file ( ) ;
132
136
133
137
if path1_is_file && path2_is_file {
134
- FileDiff :: file_diff ( path1 , path2 , & format_options, None )
138
+ FileDiff :: file_diff ( path1_path , path2_path , & format_options, None )
135
139
} else if !path1_is_file && !path2_is_file {
136
- DirDiff :: dir_diff ( path1 , path2 , & format_options, args. recurse )
140
+ DirDiff :: dir_diff ( path1_path , path2_path , & format_options, args. recurse )
137
141
} else {
138
- FileDiff :: file_dir_diff ( path1, path2, & format_options)
142
+ Ok ( FileDiff :: file_dir_diff (
143
+ path1_path,
144
+ path2_path,
145
+ & format_options,
146
+ ) ?)
139
147
}
140
148
}
141
149
@@ -151,7 +159,7 @@ fn main() -> DiffExitStatus {
151
159
match result {
152
160
Ok ( diff_exit_status) => diff_exit_status,
153
161
Err ( error) => {
154
- eprintln ! ( "diff: {}" , error ) ;
162
+ eprintln ! ( "diff: {error}" ) ;
155
163
156
164
DiffExitStatus :: Trouble
157
165
}
0 commit comments