Skip to content

Commit 3db0c0b

Browse files
authored
Merge pull request #1511 from joshrotenberg/example-semver
Use semver crate to validate version compatibility in nop-preprocessor example
2 parents 2c7aac6 + 5b7abf4 commit 3db0c0b

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ ammonia = { version = "3", optional = true }
4949

5050
[dev-dependencies]
5151
select = "0.5"
52+
semver = "0.11.0"
5253
pretty_assertions = "0.6"
5354
walkdir = "2.0"
5455

examples/nop-preprocessor.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clap::{App, Arg, ArgMatches, SubCommand};
33
use mdbook::book::Book;
44
use mdbook::errors::Error;
55
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
6+
use semver::{Version, VersionReq};
67
use std::io;
78
use std::process;
89

@@ -33,9 +34,10 @@ fn main() {
3334
fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
3435
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
3536

36-
if ctx.mdbook_version != mdbook::MDBOOK_VERSION {
37-
// We should probably use the `semver` crate to check compatibility
38-
// here...
37+
let book_version = Version::parse(&ctx.mdbook_version)?;
38+
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
39+
40+
if version_req.matches(&book_version) != true {
3941
eprintln!(
4042
"Warning: The {} plugin was built against version {} of mdbook, \
4143
but we're being called from version {}",

0 commit comments

Comments
 (0)