Skip to content

Commit 5bc6929

Browse files
committed
Add a help message
And in that case do not run the web server. Also exits if there is a build error. Closes #211
1 parent dcf22ac commit 5bc6929

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/bin/cargo-src.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,35 @@ fn main() {
2626
args.next().unwrap();
2727
}
2828

29+
let args: Vec<_> = args.collect();
30+
31+
if args.contains(&"--help".to_owned()) {
32+
print_help();
33+
return;
34+
}
35+
2936
let workspace_root = workspace_root();
3037

3138
let build_args = BuildArgs {
3239
program: env::var("CARGO").expect("Missing $CARGO var"),
33-
args: args.collect(),
40+
args,
3441
workspace_root,
3542
};
3643

3744
cargo_src::run_server(build_args);
3845
}
3946

47+
fn print_help() {
48+
println!("cargo-src");
49+
println!("Browse a program's source code\n");
50+
println!("USAGE:");
51+
println!(" cargo src [OPTIONS]\n");
52+
println!("OPTIONS:");
53+
println!(" --help show this message");
54+
println!(" --open open the cargo-src frontend in your web browser");
55+
println!("\nOther options follow `cargo check`, see `cargo check --help` for more.");
56+
}
57+
4058
fn workspace_root() -> String {
4159
let output = Command::new("cargo").args(&["metadata", "--format-version", "1"]).output();
4260
let stdout = String::from_utf8(output.expect("error executing `cargo metadata`").stdout).expect("unexpected output");

src/build/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ impl Builder {
5454
pub fn build(&self) -> Option<i32> {
5555
let mut cmd = self.init_cmd();
5656
let status = cmd.status().expect("Running build failed");
57-
self.clean_analysis();
58-
status.code()
57+
let result = status.code();
58+
if let Some(0) = result {
59+
self.clean_analysis();
60+
}
61+
result
5962
}
6063

6164
// Remove any old or duplicate json files.

src/server.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use futures::Future;
1616

1717
use std::fmt;
1818
use std::path::{Path, PathBuf};
19-
use std::process::Command;
19+
use std::process::{self, Command};
2020
use std::str::FromStr;
2121
use std::sync::{Arc, Mutex, atomic::{AtomicU32, Ordering}};
2222
use std::thread;
@@ -74,9 +74,12 @@ impl Server {
7474
thread::spawn(move || {
7575
println!("Building...");
7676
status.start_build();
77-
builder.build().unwrap();
77+
let code = builder.build().unwrap();
7878
status.finish_build();
7979

80+
if code != 0 {
81+
process::exit(1);
82+
}
8083
status.start_analysis();
8184
file_cache.update_analysis();
8285
status.finish_analysis();

0 commit comments

Comments
 (0)