1 use std::ffi::{OsStr, OsString};
3 use std::process::Command;
5 use std::time::{Duration, SystemTime};
7 pub fn run(port: u16, lint: Option<&str>) -> ! {
8 let mut url = Some(match lint {
9 None => format!("http://localhost:{}", port),
10 Some(lint) => format!("http://localhost:{}/#{}", port, lint),
14 if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") {
15 Command::new("python3")
16 .arg("util/export.py")
22 if let Some(url) = url.take() {
23 thread::spawn(move || {
24 Command::new("python3")
27 .arg(port.to_string())
28 .current_dir("util/gh-pages")
31 // Give some time for python to start
32 thread::sleep(Duration::from_millis(500));
33 // Launch browser after first export.py has completed and http.server is up
34 let _ = opener::open(url);
37 thread::sleep(Duration::from_millis(1000));
41 fn mtime(path: impl AsRef<Path>) -> SystemTime {
42 let path = path.as_ref();
48 .map(|entry| mtime(&entry.path()))
50 .unwrap_or(SystemTime::UNIX_EPOCH)
53 .and_then(|metadata| metadata.modified())
54 .unwrap_or(SystemTime::UNIX_EPOCH)
58 #[allow(clippy::missing_errors_doc)]
59 pub fn validate_port(arg: &OsStr) -> Result<(), OsString> {
60 match arg.to_string_lossy().parse::<u16>() {
62 Err(err) => Err(OsString::from(err.to_string())),