From 87cece7e01d0e5de17cd9493b3a83fada25142d3 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sun, 14 Aug 2022 16:30:07 +0200 Subject: [PATCH 1/2] make date-check more easy to use One could not run it like the following, for the would be a panic: cargo run --manifest-path ci/date-check/Cargo.toml . Also, remove the need to specify argument, in which case, current_dir is assumed. --- ci/date-check/src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ci/date-check/src/main.rs b/ci/date-check/src/main.rs index bb3542f24..ea8b24315 100644 --- a/ci/date-check/src/main.rs +++ b/ci/date-check/src/main.rs @@ -124,9 +124,7 @@ fn filter_dates( } fn main() { - let root_dir = env::args() - .nth(1) - .expect("expect root Markdown directory as CLI argument"); + let root_dir = env::args().nth(1).unwrap_or(".".into()); let root_dir_path = Path::new(&root_dir); let glob_pat = format!("{}/**/*.md", root_dir); let today_chrono = Utc::today(); @@ -167,7 +165,7 @@ fn main() { for (path, dates) in dates_by_file { println!( "- [ ] {}", - path.strip_prefix(&root_dir_path).unwrap().display() + path.strip_prefix(&root_dir_path).unwrap_or(&path).display(), ); for (line, date) in dates { println!(" - [ ] line {}: {}", line, date); From aeff3a69636005fcd0317b7b6db26f271d49f7f1 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 19 Aug 2022 07:19:14 +0200 Subject: [PATCH 2/2] address review comment https://github.com/rust-lang/rustc-dev-guide/pull/1428#discussion_r948143840 --- ci/date-check/src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ci/date-check/src/main.rs b/ci/date-check/src/main.rs index ea8b24315..70fce8b1c 100644 --- a/ci/date-check/src/main.rs +++ b/ci/date-check/src/main.rs @@ -3,6 +3,7 @@ use std::{ convert::TryInto as _, env, fmt, fs, path::{Path, PathBuf}, + process, str::FromStr, }; @@ -124,7 +125,12 @@ fn filter_dates( } fn main() { - let root_dir = env::args().nth(1).unwrap_or(".".into()); + let mut args = env::args(); + if args.len() == 1 { + eprintln!("error: expected root Markdown directory as CLI argument"); + process::exit(1); + } + let root_dir = args.nth(1).unwrap(); let root_dir_path = Path::new(&root_dir); let glob_pat = format!("{}/**/*.md", root_dir); let today_chrono = Utc::today();