diff options
author | Tom Milligan <tom@reinfer.io> | 2022-10-16 09:00:17 +0100 |
---|---|---|
committer | Tom Milligan <tommilligan@users.noreply.github.com> | 2022-10-16 09:32:06 +0100 |
commit | 603c83e2eb8f0b2ed43d649bb47ff04bd87f9383 (patch) | |
tree | 1a3ff433902d8a735c93fc3c7fa8f0b6390bc604 | |
parent | fbdffaa723ec3013ac930bc9e2eb1b0ea49232b2 (diff) |
chore: upgrade to clap v4
-rw-r--r-- | .github/workflows/check.yml | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | Cargo.lock | 72 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/bin/mdbook-admonish.rs | 91 |
5 files changed, 121 insertions, 52 deletions
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d7f6d6a..fa76f8b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -70,7 +70,7 @@ jobs: rust: - stable - beta - - 1.58.0 + - 1.60.0 experimental: - false # Run a canary test on nightly that's allowed to fail diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a341e..5ce6141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +## Unreleased + +### Changed + +- MSRV (minimum supported rust version) is now 1.60.0 for clap v4 + ## 1.7.0 ### Changed @@ -147,7 +147,7 @@ checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", "bitflags", - "clap_lex", + "clap_lex 0.2.4", "indexmap", "once_cell", "strsim", @@ -156,12 +156,37 @@ dependencies = [ ] [[package]] +name = "clap" +version = "4.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f" +dependencies = [ + "bitflags", + "clap_derive", + "clap_lex 0.3.0", + "once_cell", +] + +[[package]] name = "clap_complete" version = "3.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" dependencies = [ - "clap", + "clap 3.2.22", +] + +[[package]] +name = "clap_derive" +version = "4.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -174,6 +199,15 @@ dependencies = [ ] [[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + +[[package]] name = "codespan-reporting" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -564,6 +598,12 @@ dependencies = [ ] [[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -847,7 +887,7 @@ dependencies = [ "ammonia", "anyhow", "chrono", - "clap", + "clap 3.2.22", "clap_complete", "elasticlunr-rs", "env_logger", @@ -876,7 +916,7 @@ name = "mdbook-admonish" version = "1.7.0" dependencies = [ "anyhow", - "clap", + "clap 4.0.15", "env_logger", "log", "mdbook", @@ -1231,6 +1271,30 @@ dependencies = [ ] [[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] name = "proc-macro2" version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -23,7 +23,7 @@ path = "src/lib.rs" [dependencies] anyhow = "1.0.65" -clap = { version = "3.2.22", default_features = false, features = ["std", "cargo"], optional = true } +clap = { version = "4", default_features = false, features = ["std", "derive"], optional = true } env_logger = { version = "0.9.1", default_features = false, optional = true } log = { version = "0.4.17", optional = true } mdbook = "0.4.21" diff --git a/src/bin/mdbook-admonish.rs b/src/bin/mdbook-admonish.rs index 12b9b63..280862f 100644 --- a/src/bin/mdbook-admonish.rs +++ b/src/bin/mdbook-admonish.rs @@ -1,55 +1,59 @@ -use clap::{crate_version, Arg, ArgMatches, Command}; use mdbook::{ errors::Error, preprocess::{CmdPreprocessor, Preprocessor}, }; use mdbook_admonish::Admonish; -use std::{io, process}; - -pub fn make_app() -> Command<'static> { - let mut command = Command::new("mdbook-admonish") - .version(crate_version!()) - .about("mdbook preprocessor to add support for admonitions"); - command = command.subcommand( - Command::new("supports") - .arg(Arg::new("renderer").required(true)) - .about("Check whether a renderer is supported by this preprocessor"), - ); +use std::{io, path::PathBuf, process}; + +use clap::{Parser, Subcommand}; + +/// mdbook preprocessor to add support for admonitions +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + #[command(subcommand)] + command: Option<Commands>, +} + +#[derive(Subcommand)] +enum Commands { + /// Check whether a renderer is supported by this preprocessor + Supports { renderer: String }, #[cfg(feature = "cli-install")] - { - command = command.subcommand( - Command::new("install") - .arg(Arg::new("css-dir").long("css-dir").default_value(".").help( - "Relative directory for the css assets,\nfrom the book directory root", - )) - .arg(Arg::new("dir").default_value(".").help( - "Root directory for the book,\nshould contain the configuration file (`book.toml`)", - )) - .about("Install the required assset files and include it in the config")); - } - command + /// Install the required assset files and include it in the config + Install { + /// Root directory for the book, should contain the configuration file (`book.toml`) + dir: Option<PathBuf>, + + /// Relative directory for the css assets, from the book directory root + #[arg(long)] + css_dir: Option<PathBuf>, + }, } fn main() { env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); - let matches = make_app().get_matches(); + let cli = Cli::parse(); - if let Some(sub_args) = matches.subcommand_matches("supports") { - handle_supports(sub_args); - } else if let Some(sub_args) = matches.subcommand_matches("install") { - #[cfg(feature = "cli-install")] - { - install::handle_install(sub_args); + match cli.command { + None => { + if let Err(e) = handle_preprocessing() { + eprintln!("{}", e); + process::exit(1); + } } - #[cfg(not(feature = "cli-install"))] - { - panic!("cli-install feature not enabled: {:?}", sub_args) + Some(Commands::Supports { renderer }) => { + handle_supports(renderer); + } + #[cfg(feature = "cli-install")] + Some(Commands::Install { dir, css_dir }) => { + install::handle_install( + dir.unwrap_or_else(|| PathBuf::from(".")), + css_dir.unwrap_or_else(|| PathBuf::from(".")), + ); } - } else if let Err(e) = handle_preprocessing() { - eprintln!("{}", e); - process::exit(1); } } @@ -71,9 +75,8 @@ fn handle_preprocessing() -> Result<(), Error> { Ok(()) } -fn handle_supports(sub_args: &ArgMatches) -> ! { - let renderer = sub_args.value_of("renderer").expect("Required argument"); - let supported = Admonish.supports_renderer(renderer); +fn handle_supports(renderer: String) -> ! { + let supported = Admonish.supports_renderer(&renderer); // Signal whether the renderer is supported by exiting with 1 or 0. if supported { @@ -85,7 +88,6 @@ fn handle_supports(sub_args: &ArgMatches) -> ! { #[cfg(feature = "cli-install")] mod install { - use clap::ArgMatches; use std::{ fs::{self, File}, io::Write, @@ -112,10 +114,7 @@ mod install { } } - pub fn handle_install(sub_args: &ArgMatches) { - let dir = sub_args.value_of("dir").expect("Required argument"); - let css_dir = sub_args.value_of("css-dir").expect("Required argument"); - let proj_dir = PathBuf::from(dir); + pub fn handle_install(proj_dir: PathBuf, css_dir: PathBuf) { let config = proj_dir.join("book.toml"); if !config.exists() { @@ -142,7 +141,7 @@ mod install { let mut additional_css = additional_css(&mut doc); for (name, content) in ADMONISH_CSS_FILES { - let filepath = proj_dir.join(css_dir).join(name); + let filepath = proj_dir.join(&css_dir).join(name); let filepath_str = filepath.to_str().expect("non-utf8 filepath"); if let Ok(ref mut additional_css) = additional_css { |