@@ -31,17 +31,25 @@ use getopts::{Matches, Options};
31
31
/// Rustfmt operations.
32
32
enum Operation {
33
33
/// Format files and their child modules.
34
- Format ( Vec < PathBuf > , Option < PathBuf > ) ,
34
+ Format {
35
+ files : Vec < PathBuf > ,
36
+ config_path : Option < PathBuf > ,
37
+ } ,
35
38
/// Print the help message.
36
39
Help ,
37
40
// Print version information
38
41
Version ,
39
42
/// Print detailed configuration help.
40
43
ConfigHelp ,
41
- /// Invalid program input, including reason.
42
- InvalidInput ( String ) ,
44
+ /// Invalid program input.
45
+ InvalidInput {
46
+ reason : String ,
47
+ } ,
43
48
/// No file specified, read from stdin
44
- Stdin ( String , Option < PathBuf > ) ,
49
+ Stdin {
50
+ input : String ,
51
+ config_path : Option < PathBuf > ,
52
+ } ,
45
53
}
46
54
47
55
/// Try to find a project file in the given directory and its parents. Returns the path of a the
@@ -156,7 +164,7 @@ fn execute() -> i32 {
156
164
let operation = determine_operation ( & matches) ;
157
165
158
166
match operation {
159
- Operation :: InvalidInput ( reason) => {
167
+ Operation :: InvalidInput { reason } => {
160
168
print_usage ( & opts, & reason) ;
161
169
1
162
170
}
@@ -172,7 +180,7 @@ fn execute() -> i32 {
172
180
Config :: print_docs ( ) ;
173
181
0
174
182
}
175
- Operation :: Stdin ( input, config_path) => {
183
+ Operation :: Stdin { input, config_path } => {
176
184
// try to read config from local directory
177
185
let ( mut config, _) = match_cli_path_or_file ( config_path, & env:: current_dir ( ) . unwrap ( ) )
178
186
. expect ( "Error resolving config" ) ;
@@ -183,7 +191,7 @@ fn execute() -> i32 {
183
191
run_from_stdin ( input, & config) ;
184
192
0
185
193
}
186
- Operation :: Format ( files, config_path) => {
194
+ Operation :: Format { files, config_path } => {
187
195
let mut config = Config :: default ( ) ;
188
196
let mut path = None ;
189
197
// Load the config path file if provided
@@ -281,13 +289,19 @@ fn determine_operation(matches: &Matches) -> Operation {
281
289
let mut buffer = String :: new ( ) ;
282
290
match io:: stdin ( ) . read_to_string ( & mut buffer) {
283
291
Ok ( ..) => ( ) ,
284
- Err ( e) => return Operation :: InvalidInput ( e. to_string ( ) ) ,
292
+ Err ( e) => return Operation :: InvalidInput { reason : e. to_string ( ) } ,
285
293
}
286
294
287
- return Operation :: Stdin ( buffer, config_path) ;
295
+ return Operation :: Stdin {
296
+ input : buffer,
297
+ config_path : config_path,
298
+ } ;
288
299
}
289
300
290
301
let files: Vec < _ > = matches. free . iter ( ) . map ( PathBuf :: from) . collect ( ) ;
291
302
292
- Operation :: Format ( files, config_path)
303
+ Operation :: Format {
304
+ files : files,
305
+ config_path : config_path,
306
+ }
293
307
}
0 commit comments