Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 42d8f78

Browse files
committed
Merge #58
58: Don't require clippy r=oli-obk a=Manishearth This makes it more suitable to use for epoch stuff We also need better error reporting here :| (Can this get a release?) r? @killercup
2 parents 64b9042 + 0877709 commit 42d8f78

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/main.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ fn try_main() -> Result<(), ProgramError> {
6868
.long("only")
6969
.help("Only show errors or lints with the specific id(s) (comma separated)")
7070
.use_delimiter(true))
71+
.arg(Arg::with_name("file")
72+
.long("file")
73+
.takes_value(true)
74+
.help("Load errors from the given JSON file (produced by `cargo build --message-format=json`)"))
7175
.get_matches();
7276

7377
let mut extra_args = Vec::new();
@@ -97,7 +101,14 @@ fn try_main() -> Result<(), ProgramError> {
97101
}
98102

99103
// Get JSON output from rustc...
100-
let json = get_json(&extra_args)?;
104+
let json = if let Some(file) = matches.value_of("file") {
105+
let mut f = File::open(file)?;
106+
let mut j = "".into();
107+
f.read_to_string(&mut j)?;
108+
j
109+
} else {
110+
get_json(&extra_args, matches.is_present("clippy"))?
111+
};
101112

102113
let suggestions: Vec<Suggestion> = json.lines()
103114
.filter(not_empty)
@@ -117,9 +128,14 @@ struct CargoMessage {
117128
message: Diagnostic,
118129
}
119130

120-
fn get_json(extra_args: &[&str]) -> Result<String, ProgramError> {
131+
fn get_json(extra_args: &[&str], clippy: bool) -> Result<String, ProgramError> {
132+
let build_cmd = if clippy {
133+
"clippy"
134+
} else {
135+
"rustc"
136+
};
121137
let output = try!(Command::new("cargo")
122-
.args(&["clippy", "--message-format", "json"])
138+
.args(&[build_cmd, "--message-format", "json"])
123139
.arg("--")
124140
.args(extra_args)
125141
.output());

0 commit comments

Comments
 (0)