Skip to content

Commit 14a6f65

Browse files
committed
rustfmt: Use struct-like enum variants for Operation
1 parent 65bc5c2 commit 14a6f65

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/bin/rustfmt.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ use getopts::{Matches, Options};
3131
/// Rustfmt operations.
3232
enum Operation {
3333
/// Format files and their child modules.
34-
Format(Vec<PathBuf>, Option<PathBuf>),
34+
Format {
35+
files: Vec<PathBuf>,
36+
config_path: Option<PathBuf>,
37+
},
3538
/// Print the help message.
3639
Help,
3740
// Print version information
3841
Version,
3942
/// Print detailed configuration help.
4043
ConfigHelp,
41-
/// Invalid program input, including reason.
42-
InvalidInput(String),
44+
/// Invalid program input.
45+
InvalidInput {
46+
reason: String,
47+
},
4348
/// No file specified, read from stdin
44-
Stdin(String, Option<PathBuf>),
49+
Stdin {
50+
input: String,
51+
config_path: Option<PathBuf>,
52+
},
4553
}
4654

4755
/// 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 {
156164
let operation = determine_operation(&matches);
157165

158166
match operation {
159-
Operation::InvalidInput(reason) => {
167+
Operation::InvalidInput { reason } => {
160168
print_usage(&opts, &reason);
161169
1
162170
}
@@ -172,7 +180,7 @@ fn execute() -> i32 {
172180
Config::print_docs();
173181
0
174182
}
175-
Operation::Stdin(input, config_path) => {
183+
Operation::Stdin { input, config_path } => {
176184
// try to read config from local directory
177185
let (mut config, _) = match_cli_path_or_file(config_path, &env::current_dir().unwrap())
178186
.expect("Error resolving config");
@@ -183,7 +191,7 @@ fn execute() -> i32 {
183191
run_from_stdin(input, &config);
184192
0
185193
}
186-
Operation::Format(files, config_path) => {
194+
Operation::Format { files, config_path } => {
187195
let mut config = Config::default();
188196
let mut path = None;
189197
// Load the config path file if provided
@@ -281,13 +289,19 @@ fn determine_operation(matches: &Matches) -> Operation {
281289
let mut buffer = String::new();
282290
match io::stdin().read_to_string(&mut buffer) {
283291
Ok(..) => (),
284-
Err(e) => return Operation::InvalidInput(e.to_string()),
292+
Err(e) => return Operation::InvalidInput { reason: e.to_string() },
285293
}
286294

287-
return Operation::Stdin(buffer, config_path);
295+
return Operation::Stdin {
296+
input: buffer,
297+
config_path: config_path,
298+
};
288299
}
289300

290301
let files: Vec<_> = matches.free.iter().map(PathBuf::from).collect();
291302

292-
Operation::Format(files, config_path)
303+
Operation::Format {
304+
files: files,
305+
config_path: config_path,
306+
}
293307
}

0 commit comments

Comments
 (0)