From e343095e3bbdaf7b1d3327d98aa497d3c9d330ec Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Wed, 9 Oct 2024 01:26:26 -0600 Subject: [PATCH] book: add command (#791) --- Cargo.lock | 153 ++++++++++++++++++++++++++++++++++++++- bin/Cargo.toml | 1 + bin/src/commands/book.rs | 19 +++++ bin/src/commands/mod.rs | 1 + bin/src/lib.rs | 4 +- 5 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 bin/src/commands/book.rs diff --git a/Cargo.lock b/Cargo.lock index 93f28424..c04836c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,6 +343,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" +dependencies = [ + "objc2", +] + [[package]] name = "bstr" version = "1.10.0" @@ -428,6 +437,12 @@ dependencies = [ "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-expr" version = "0.15.8" @@ -563,6 +578,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "console" version = "0.15.8" @@ -618,6 +643,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -1396,6 +1431,7 @@ dependencies = [ "tracing-subscriber", "vfs", "walkdir", + "webbrowser", "whoami", "winreg 0.52.0", "zip", @@ -1603,6 +1639,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "html5ever" version = "0.27.0" @@ -1981,6 +2026,28 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + [[package]] name = "jobserver" version = "0.1.32" @@ -2407,6 +2474,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -2573,6 +2646,40 @@ dependencies = [ "libc", ] +[[package]] +name = "objc-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" + +[[package]] +name = "objc2" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" +dependencies = [ + "objc-sys", + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8" + +[[package]] +name = "objc2-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" +dependencies = [ + "bitflags 2.6.0", + "block2", + "libc", + "objc2", +] + [[package]] name = "object" version = "0.36.5" @@ -3501,7 +3608,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.9.4", "core-foundation-sys", "libc", "security-framework-sys", @@ -3890,7 +3997,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys", ] @@ -4688,6 +4795,24 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webbrowser" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5f07fb9bc8de2ddfe6b24a71a75430673fd679e568c48b52716cef1cfae923" +dependencies = [ + "block2", + "core-foundation 0.10.0", + "home", + "jni", + "log", + "ndk-context", + "objc2", + "objc2-foundation", + "url", + "web-sys", +] + [[package]] name = "weezl" version = "0.1.8" @@ -4790,6 +4915,15 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -4817,6 +4951,21 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/bin/Cargo.toml b/bin/Cargo.toml index e1c0ca91..4d212115 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -50,6 +50,7 @@ tracing = { workspace = true } tracing-subscriber = { version = "0.3.18", features = ["json"] } vfs = { workspace = true } walkdir = { workspace = true } +webbrowser = "1.0.2" whoami = "1.5.2" zip = { workspace = true } diff --git a/bin/src/commands/book.rs b/bin/src/commands/book.rs new file mode 100644 index 00000000..f2fa2333 --- /dev/null +++ b/bin/src/commands/book.rs @@ -0,0 +1,19 @@ +use clap::{ArgMatches, Command}; + +use crate::{report::Report, Error}; + +#[must_use] +pub fn cli() -> Command { + Command::new("book").about("Open The HEMTT book") +} + +/// Execute the book command +/// +/// # Errors +/// Will not return an error +pub fn execute(_: &ArgMatches) -> Result { + if let Err(e) = webbrowser::open("https://brettmayson.github.io/HEMTT/") { + eprintln!("Failed to open the HEMTT book: {e}"); + } + Ok(Report::new()) +} diff --git a/bin/src/commands/mod.rs b/bin/src/commands/mod.rs index c4054d85..11340d13 100644 --- a/bin/src/commands/mod.rs +++ b/bin/src/commands/mod.rs @@ -1,3 +1,4 @@ +pub mod book; pub mod build; pub mod check; pub mod dev; diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 6483e909..2a2b18eb 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -23,6 +23,7 @@ pub fn cli() -> Command { .version(env!("HEMTT_VERSION")) .subcommand_required(false) .arg_required_else_help(true) + .subcommand(commands::book::cli()) .subcommand(commands::new::cli()) .subcommand(commands::check::cli()) .subcommand(commands::dev::cli()) @@ -133,6 +134,7 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> { } } let report = match matches.subcommand() { + Some(("book", matches)) => commands::book::execute(matches).map(Some), Some(("new", matches)) => commands::new::execute(matches).map(Some), Some(("dev", matches)) => commands::dev::execute(matches, &[]).map(Some), Some(("check", _matches)) => commands::check::execute().map(Some), @@ -166,7 +168,7 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> { report.write_to_stdout(); if !matches .subcommand_name() - .is_some_and(|s| s == "new" || s == "utils") + .is_some_and(|s| s == "new" || s == "utils" || s == "wiki" || s == "book") { report.write_ci_annotations()?; }