Skip to content

Commit 2364677

Browse files
committed
Remove clap dependency.
This is a pretty heavy dependency, which is only used to check for the arguments "supports renderer". This doesn't actually drop the clap dependency from the tree due to mdbook. Hopefully I will get that fixed one day.
1 parent a218f00 commit 2364677

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

blacksmith/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blacksmith/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ serde = { version = "1.0.130", features = ["derive"] }
1616
serde_json = "1.0.71"
1717
toml = "0.8.8"
1818

19-
[dependencies.clap]
20-
version = "3"
21-
default-features = false
22-
2319
[dependencies.mdbook]
2420
version = "0.4.21"
2521
default-features = false

blacksmith/src/main.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{env, io, path::Path, process};
22

3-
use clap::ArgMatches;
43
use mdbook::{
54
errors::Error,
65
preprocess::{CmdPreprocessor, Preprocessor},
@@ -21,15 +20,6 @@ fn main() {
2120
.init();
2221
}
2322

24-
let matches = clap::clap_app!(blacksmith =>
25-
(about: clap::crate_description!())
26-
(@subcommand supports =>
27-
(about: "Check whether a renderer is supported by this preprocessor")
28-
(@arg renderer: +takes_value +required)
29-
)
30-
)
31-
.get_matches();
32-
3323
macro_rules! log_unwrap {
3424
($result:expr) => {
3525
match $result {
@@ -51,25 +41,34 @@ fn main() {
5141
Blacksmith::new()
5242
};
5343

54-
if let Some(sub_args) = matches.subcommand_matches("supports") {
55-
handle_supports(&blacksmith, sub_args);
56-
} else {
57-
let mut update_cache = false;
58-
if blacksmith.is_stale(CACHE_TTL_SECONDS) {
59-
blacksmith = log_unwrap!(Blacksmith::init());
60-
update_cache = true;
61-
} else {
62-
log::info!("Using cached data in {}", cache_file.display());
44+
let mut args = std::env::args().skip(1);
45+
match args.next().as_deref() {
46+
Some("supports") => {
47+
let renderer = args.next().expect("renderer name must be second argument");
48+
handle_supports(&blacksmith, &renderer);
6349
}
64-
log_unwrap!(handle_preprocessing(&blacksmith));
65-
66-
if update_cache {
67-
log::info!("Storing the cache in {}", cache_file.display());
68-
log_unwrap!(std::fs::write(
69-
&cache_file,
70-
&log_unwrap!(serde_json::to_vec(&blacksmith))
71-
));
50+
Some(arg) => {
51+
eprintln!("unknown argument: {arg}");
52+
std::process::exit(1);
7253
}
54+
None => {}
55+
}
56+
57+
let mut update_cache = false;
58+
if blacksmith.is_stale(CACHE_TTL_SECONDS) {
59+
blacksmith = log_unwrap!(Blacksmith::init());
60+
update_cache = true;
61+
} else {
62+
log::info!("Using cached data in {}", cache_file.display());
63+
}
64+
log_unwrap!(handle_preprocessing(&blacksmith));
65+
66+
if update_cache {
67+
log::info!("Storing the cache in {}", cache_file.display());
68+
log_unwrap!(std::fs::write(
69+
&cache_file,
70+
&log_unwrap!(serde_json::to_vec(&blacksmith))
71+
));
7372
}
7473
}
7574

@@ -94,9 +93,8 @@ fn handle_preprocessing(pre: &Blacksmith) -> Result<(), Error> {
9493
Ok(())
9594
}
9695

97-
fn handle_supports(pre: &Blacksmith, sub_args: &ArgMatches) -> ! {
98-
let renderer = sub_args.value_of("renderer").expect("Required argument");
99-
let supported = pre.supports_renderer(&renderer);
96+
fn handle_supports(pre: &Blacksmith, renderer: &str) -> ! {
97+
let supported = pre.supports_renderer(renderer);
10098

10199
// Signal whether the renderer is supported by exiting with 1 or 0.
102100
if supported {

0 commit comments

Comments
 (0)