summaryrefslogtreecommitdiffstats
path: root/vendor/mdbook/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/mdbook/src/main.rs42
1 files changed, 19 insertions, 23 deletions
diff --git a/vendor/mdbook/src/main.rs b/vendor/mdbook/src/main.rs
index 35562e64b..3e576c5b5 100644
--- a/vendor/mdbook/src/main.rs
+++ b/vendor/mdbook/src/main.rs
@@ -5,7 +5,7 @@ extern crate log;
use anyhow::anyhow;
use chrono::Local;
-use clap::{App, AppSettings, Arg, ArgMatches};
+use clap::{Arg, ArgMatches, Command};
use clap_complete::Shell;
use env_logger::Builder;
use log::LevelFilter;
@@ -13,7 +13,7 @@ use mdbook::utils;
use std::env;
use std::ffi::OsStr;
use std::io::Write;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
mod cmd;
@@ -22,10 +22,10 @@ const VERSION: &str = concat!("v", crate_version!());
fn main() {
init_logger();
- let app = create_clap_app();
+ let command = create_clap_command();
- // Check which subcomamnd the user ran...
- let res = match app.get_matches().subcommand() {
+ // Check which subcommand the user ran...
+ let res = match command.get_matches().subcommand() {
Some(("init", sub_matches)) => cmd::init::execute(sub_matches),
Some(("build", sub_matches)) => cmd::build::execute(sub_matches),
Some(("clean", sub_matches)) => cmd::clean::execute(sub_matches),
@@ -35,15 +35,13 @@ fn main() {
Some(("serve", sub_matches)) => cmd::serve::execute(sub_matches),
Some(("test", sub_matches)) => cmd::test::execute(sub_matches),
Some(("completions", sub_matches)) => (|| {
- let shell: Shell = sub_matches
- .value_of("shell")
- .ok_or_else(|| anyhow!("Shell name missing."))?
- .parse()
- .map_err(|s| anyhow!("Invalid shell: {}", s))?;
+ let shell = sub_matches
+ .get_one::<Shell>("shell")
+ .ok_or_else(|| anyhow!("Shell name missing."))?;
- let mut complete_app = create_clap_app();
+ let mut complete_app = create_clap_command();
clap_complete::generate(
- shell,
+ *shell,
&mut complete_app,
"mdbook",
&mut std::io::stdout().lock(),
@@ -61,13 +59,13 @@ fn main() {
}
/// Create a list of valid arguments and sub-commands
-fn create_clap_app() -> App<'static> {
- let app = App::new(crate_name!())
+fn create_clap_command() -> Command {
+ let app = Command::new(crate_name!())
.about(crate_description!())
.author("Mathieu David <mathieudavid@mathieudavid.org>")
.version(VERSION)
- .setting(AppSettings::PropagateVersion)
- .setting(AppSettings::ArgRequiredElseHelp)
+ .propagate_version(true)
+ .arg_required_else_help(true)
.after_help(
"For more information about a specific command, try `mdbook <command> --help`\n\
The source code for mdBook is available at: https://github.com/rust-lang/mdBook",
@@ -77,12 +75,11 @@ fn create_clap_app() -> App<'static> {
.subcommand(cmd::test::make_subcommand())
.subcommand(cmd::clean::make_subcommand())
.subcommand(
- App::new("completions")
+ Command::new("completions")
.about("Generate shell completions for your shell to stdout")
.arg(
Arg::new("shell")
- .takes_value(true)
- .possible_values(Shell::possible_values())
+ .value_parser(clap::value_parser!(Shell))
.help("the shell to generate completions for")
.value_name("SHELL")
.required(true),
@@ -124,11 +121,10 @@ fn init_logger() {
}
fn get_book_dir(args: &ArgMatches) -> PathBuf {
- if let Some(dir) = args.value_of("dir") {
+ if let Some(p) = args.get_one::<PathBuf>("dir") {
// Check if path is relative from current dir, or absolute...
- let p = Path::new(dir);
if p.is_relative() {
- env::current_dir().unwrap().join(dir)
+ env::current_dir().unwrap().join(p)
} else {
p.to_path_buf()
}
@@ -146,5 +142,5 @@ fn open<P: AsRef<OsStr>>(path: P) {
#[test]
fn verify_app() {
- create_clap_app().debug_assert();
+ create_clap_command().debug_assert();
}