diff --git a/mdbook-course/src/bin/course-schedule.rs b/mdbook-course/src/bin/course-schedule.rs index a076c5023f3..b11c5a180a5 100644 --- a/mdbook-course/src/bin/course-schedule.rs +++ b/mdbook-course/src/bin/course-schedule.rs @@ -12,21 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. +use clap::Command; use mdbook::MDBook; -use mdbook_course::course::{Course, Courses}; +use mdbook_course::course::Courses; use mdbook_course::markdown::duration; fn main() { pretty_env_logger::init(); + let app = Command::new("mdbook-course") + .about("mdbook preprocessor for Comprehensive Rust") + .subcommand(Command::new("sessions").about("Show session summary (default)")) + .subcommand(Command::new("segments").about("Show segment summary")) + .subcommand(Command::new("pr").about("Show summary for a PR")); + let matches = app.get_matches(); + let root_dir = "."; let mdbook = MDBook::load(root_dir).expect("Unable to load the book"); let (courses, _) = Courses::extract_structure(mdbook.book) .expect("Unable to extract course structure"); - println!("## Course Schedule"); - println!("With this pull request applied, the course schedule is as follows:"); - for course in &courses { - print_summary(course); + match matches.subcommand() { + Some(("session", _)) | None => session_summary(&courses), + Some(("pr", _)) => pr_summary(&courses), + _ => unreachable!(), } } @@ -44,18 +52,42 @@ fn timediff(actual: u64, target: u64, slop: u64) -> String { } } -fn print_summary(course: &Course) { - if course.target_minutes() == 0 { - return; +fn session_summary(courses: &Courses) { + for course in courses { + if course.target_minutes() == 0 { + return; + } + for session in course { + println!("### {} // {}", course.name, session.name); + println!( + "_{}_", + timediff(session.minutes(), session.target_minutes(), 15) + ); + println!(); + for segment in session { + println!("* {} - _{}_", segment.name, duration(segment.minutes())); + } + println!(); + } } - println!("### {}", course.name); - println!("_{}_", timediff(course.minutes(), course.target_minutes(), 15)); - - for session in course { - println!( - "* {} - _{}_", - session.name, - timediff(session.minutes(), session.target_minutes(), 5) - ); +} + +fn pr_summary(courses: &Courses) { + println!("## Course Schedule"); + println!("With this pull request applied, the course schedule is as follows:"); + for course in courses { + if course.target_minutes() == 0 { + return; + } + println!("### {}", course.name); + println!("_{}_", timediff(course.minutes(), course.target_minutes(), 15)); + + for session in course { + println!( + "* {} - _{}_", + session.name, + timediff(session.minutes(), session.target_minutes(), 5) + ); + } } } diff --git a/src/control-flow-basics/blocks-and-scopes.md b/src/control-flow-basics/blocks-and-scopes.md index 3e8d685e0fb..76a1da0c999 100644 --- a/src/control-flow-basics/blocks-and-scopes.md +++ b/src/control-flow-basics/blocks-and-scopes.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 5 --- # Blocks and Scopes diff --git a/src/control-flow-basics/break-continue.md b/src/control-flow-basics/break-continue.md index 6cad37fdbb1..e46a3382941 100644 --- a/src/control-flow-basics/break-continue.md +++ b/src/control-flow-basics/break-continue.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 4 --- # `break` and `continue` diff --git a/src/control-flow-basics/conditionals.md b/src/control-flow-basics/conditionals.md index 03bd50e4369..81378ac3332 100644 --- a/src/control-flow-basics/conditionals.md +++ b/src/control-flow-basics/conditionals.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 4 --- # Conditionals diff --git a/src/generics/generic-data.md b/src/generics/generic-data.md index 54bc15b2e1c..8724524970e 100644 --- a/src/generics/generic-data.md +++ b/src/generics/generic-data.md @@ -1,5 +1,5 @@ --- -minutes: 15 +minutes: 10 --- # Generic Data Types diff --git a/src/generics/trait-bounds.md b/src/generics/trait-bounds.md index 2ebdcb62d33..75581414e2c 100644 --- a/src/generics/trait-bounds.md +++ b/src/generics/trait-bounds.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # Trait Bounds diff --git a/src/iterators/iterator.md b/src/iterators/iterator.md index 826e1ac0451..d0b7c072691 100644 --- a/src/iterators/iterator.md +++ b/src/iterators/iterator.md @@ -2,10 +2,6 @@ minutes: 5 --- - - # `Iterator` The [`Iterator`][1] trait supports iterating over values in a collection. It diff --git a/src/memory-management/copy-types.md b/src/memory-management/copy-types.md index 835222b9432..25f5cfb525a 100644 --- a/src/memory-management/copy-types.md +++ b/src/memory-management/copy-types.md @@ -2,10 +2,6 @@ minutes: 5 --- - - # Copy Types While move semantics are the default, certain types are copied by default: diff --git a/src/memory-management/drop.md b/src/memory-management/drop.md index 698a06754bf..4f7a9f3df76 100644 --- a/src/memory-management/drop.md +++ b/src/memory-management/drop.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # The `Drop` Trait diff --git a/src/memory-management/move.md b/src/memory-management/move.md index aacfaa34d21..53c982991a0 100644 --- a/src/memory-management/move.md +++ b/src/memory-management/move.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 5 --- # Move Semantics diff --git a/src/methods-and-traits/deriving.md b/src/methods-and-traits/deriving.md index ac4efe9e9d2..99190a03339 100644 --- a/src/methods-and-traits/deriving.md +++ b/src/methods-and-traits/deriving.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 3 --- # Deriving diff --git a/src/methods-and-traits/methods.md b/src/methods-and-traits/methods.md index 06269721597..f16268a3387 100644 --- a/src/methods-and-traits/methods.md +++ b/src/methods-and-traits/methods.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # Methods diff --git a/src/methods-and-traits/traits.md b/src/methods-and-traits/traits.md index ce483b3f6c2..1a5924d983f 100644 --- a/src/methods-and-traits/traits.md +++ b/src/methods-and-traits/traits.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # Traits diff --git a/src/modules/modules.md b/src/modules/modules.md index d0630885536..5c6b7f53ed8 100644 --- a/src/modules/modules.md +++ b/src/modules/modules.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 3 --- # Modules diff --git a/src/modules/paths.md b/src/modules/paths.md index f8f570adebf..9497b5b5f65 100644 --- a/src/modules/paths.md +++ b/src/modules/paths.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # use, super, self diff --git a/src/pattern-matching/destructuring.md b/src/pattern-matching/destructuring.md index 6df5ea5418d..228959ff981 100644 --- a/src/pattern-matching/destructuring.md +++ b/src/pattern-matching/destructuring.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # Destructuring diff --git a/src/smart-pointers/box.md b/src/smart-pointers/box.md index a8e66c426d2..7074f8f7d54 100644 --- a/src/smart-pointers/box.md +++ b/src/smart-pointers/box.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 8 --- # `Box` diff --git a/src/testing/lints.md b/src/testing/lints.md index 846ecf7fc45..2df1a79abc7 100644 --- a/src/testing/lints.md +++ b/src/testing/lints.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 3 --- # Compiler Lints and Clippy diff --git a/src/testing/other.md b/src/testing/other.md index f1eea8e1861..b361829b33d 100644 --- a/src/testing/other.md +++ b/src/testing/other.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 5 --- # Other Types of Tests diff --git a/src/testing/unit-tests.md b/src/testing/unit-tests.md index fc99bf67c0c..2c3495f5ffe 100644 --- a/src/testing/unit-tests.md +++ b/src/testing/unit-tests.md @@ -23,7 +23,7 @@ fn first_word(text: &str) -> &str { } #[cfg(test)] -mod test { +mod tests { use super::*; #[test] diff --git a/src/types-and-values/arithmetic.md b/src/types-and-values/arithmetic.md index 30ebbc5920e..8e7eb072995 100644 --- a/src/types-and-values/arithmetic.md +++ b/src/types-and-values/arithmetic.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 3 --- # Arithmetic diff --git a/src/types-and-values/inference.md b/src/types-and-values/inference.md index 8a82a48e5be..1da78bf1bd5 100644 --- a/src/types-and-values/inference.md +++ b/src/types-and-values/inference.md @@ -1,5 +1,5 @@ --- -minutes: 5 +minutes: 3 --- # Type Inference diff --git a/src/types-and-values/strings.md b/src/types-and-values/strings.md index 1d52e2eab55..47b0d13aca1 100644 --- a/src/types-and-values/strings.md +++ b/src/types-and-values/strings.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 5 --- # Strings diff --git a/src/types-and-values/values.md b/src/types-and-values/values.md index 311a27e1da6..71bef8e62c8 100644 --- a/src/types-and-values/values.md +++ b/src/types-and-values/values.md @@ -1,5 +1,5 @@ --- -minutes: 10 +minutes: 5 --- # Values