diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
commit | a4b7ed7a42c716ab9f05e351f003d589124fd55d (patch) | |
tree | b620cd3f223850b28716e474e80c58059dca5dd4 /vendor/mdbook/src/cmd/init.rs | |
parent | Adding upstream version 1.67.1+dfsg1. (diff) | |
download | rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip |
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/mdbook/src/cmd/init.rs')
-rw-r--r-- | vendor/mdbook/src/cmd/init.rs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/vendor/mdbook/src/cmd/init.rs b/vendor/mdbook/src/cmd/init.rs index c964dcc13..d8ce93d16 100644 --- a/vendor/mdbook/src/cmd/init.rs +++ b/vendor/mdbook/src/cmd/init.rs @@ -1,5 +1,5 @@ use crate::get_book_dir; -use clap::{arg, App, Arg, ArgMatches}; +use clap::{arg, ArgMatches, Command as ClapCommand}; use mdbook::config; use mdbook::errors::Result; use mdbook::MDBook; @@ -8,30 +8,22 @@ use std::io::Write; use std::process::Command; // Create clap subcommand arguments -pub fn make_subcommand<'help>() -> App<'help> { - App::new("init") +pub fn make_subcommand() -> ClapCommand { + ClapCommand::new("init") .about("Creates the boilerplate structure and files for a new book") - // the {n} denotes a newline which will properly aligned in all help messages - .arg(arg!([dir] - "Directory to create the book in{n}\ - (Defaults to the Current Directory when omitted)" - )) - .arg(arg!(--theme "Copies the default theme into your source folder")) - .arg(arg!(--force "Skips confirmation prompts")) .arg( - Arg::new("title") - .long("title") - .takes_value(true) - .help("Sets the book title") - .required(false), + arg!([dir] + "Directory to create the book in\n\ + (Defaults to the current directory when omitted)" + ) + .value_parser(clap::value_parser!(std::path::PathBuf)), ) + .arg(arg!(--theme "Copies the default theme into your source folder")) + .arg(arg!(--force "Skips confirmation prompts")) + .arg(arg!(--title <title> "Sets the book title")) .arg( - Arg::new("ignore") - .long("ignore") - .takes_value(true) - .possible_values(&["none", "git"]) - .help("Creates a VCS ignore file (i.e. .gitignore)") - .required(false), + arg!(--ignore <ignore> "Creates a VCS ignore file (i.e. .gitignore)") + .value_parser(["none", "git"]), ) } @@ -41,12 +33,12 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let mut builder = MDBook::init(&book_dir); let mut config = config::Config::default(); // If flag `--theme` is present, copy theme to src - if args.is_present("theme") { + if args.get_flag("theme") { let theme_dir = book_dir.join("theme"); println!(); println!("Copying the default theme to {}", theme_dir.display()); // Skip this if `--force` is present - if !args.is_present("force") && theme_dir.exists() { + if !args.get_flag("force") && theme_dir.exists() { println!("This could potentially overwrite files already present in that directory."); print!("\nAre you sure you want to continue? (y/n) "); @@ -59,7 +51,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { } } - if let Some(ignore) = args.value_of("ignore") { + if let Some(ignore) = args.get_one::<String>("ignore").map(|s| s.as_str()) { match ignore { "git" => builder.create_gitignore(true), _ => builder.create_gitignore(false), @@ -71,8 +63,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> { } } - config.book.title = if args.is_present("title") { - args.value_of("title").map(String::from) + config.book.title = if args.contains_id("title") { + args.get_one::<String>("title").map(String::from) } else { request_book_title() }; |