Skip to content

Commit f99b45a

Browse files
committed
Move Spec creation out of main
This is in preparation for error handling in future commits.
1 parent 42e435c commit f99b45a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

mdbook-spec/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![deny(rust_2018_idioms, unused_lifetimes)]
22

3+
use anyhow::Result;
34
use mdbook::book::{Book, Chapter};
45
use mdbook::errors::Error;
56
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
@@ -20,7 +21,8 @@ static ADMONITION_RE: Lazy<Regex> = Lazy::new(|| {
2021
Regex::new(r"(?m)^ *> \[!(?<admon>[^]]+)\]\n(?<blockquote>(?: *>.*\n)+)").unwrap()
2122
});
2223

23-
pub fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
24+
pub fn handle_preprocessing() -> Result<(), Error> {
25+
let pre = Spec::new()?;
2426
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
2527

2628
let book_version = Version::parse(&ctx.mdbook_version)?;
@@ -49,10 +51,9 @@ pub struct Spec {
4951
}
5052

5153
impl Spec {
52-
pub fn new() -> Spec {
53-
Spec {
54-
deny_warnings: std::env::var("SPEC_DENY_WARNINGS").as_deref() == Ok("1"),
55-
}
54+
fn new() -> Result<Spec> {
55+
let deny_warnings = std::env::var("SPEC_DENY_WARNINGS").as_deref() == Ok("1");
56+
Ok(Spec { deny_warnings })
5657
}
5758

5859
/// Generates link references to all rules on all pages, so you can easily

mdbook-spec/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ fn main() {
1212
None => {}
1313
}
1414

15-
let preprocessor = mdbook_spec::Spec::new();
16-
17-
if let Err(e) = mdbook_spec::handle_preprocessing(&preprocessor) {
15+
if let Err(e) = mdbook_spec::handle_preprocessing() {
1816
eprintln!("{}", e);
1917
std::process::exit(1);
2018
}

0 commit comments

Comments
 (0)