diff options
Diffstat (limited to 'vendor/mdbook/src/cmd')
-rw-r--r-- | vendor/mdbook/src/cmd/build.rs | 2 | ||||
-rw-r--r-- | vendor/mdbook/src/cmd/clean.rs | 2 | ||||
-rw-r--r-- | vendor/mdbook/src/cmd/init.rs | 8 | ||||
-rw-r--r-- | vendor/mdbook/src/cmd/serve.rs | 4 | ||||
-rw-r--r-- | vendor/mdbook/src/cmd/test.rs | 2 | ||||
-rw-r--r-- | vendor/mdbook/src/cmd/watch.rs | 34 |
6 files changed, 25 insertions, 27 deletions
diff --git a/vendor/mdbook/src/cmd/build.rs b/vendor/mdbook/src/cmd/build.rs index 14a9fec6e..e40e5c0c7 100644 --- a/vendor/mdbook/src/cmd/build.rs +++ b/vendor/mdbook/src/cmd/build.rs @@ -16,7 +16,7 @@ pub fn make_subcommand() -> Command { // Build command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") { book.config.build.build_dir = dest_dir.into(); diff --git a/vendor/mdbook/src/cmd/clean.rs b/vendor/mdbook/src/cmd/clean.rs index 3ec605fea..48b4147ca 100644 --- a/vendor/mdbook/src/cmd/clean.rs +++ b/vendor/mdbook/src/cmd/clean.rs @@ -16,7 +16,7 @@ pub fn make_subcommand() -> Command { // Clean command implementation pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> { let book_dir = get_book_dir(args); - let book = MDBook::load(&book_dir)?; + let book = MDBook::load(book_dir)?; let dir_to_remove = match args.get_one::<PathBuf>("dest-dir") { Some(dest_dir) => dest_dir.into(), diff --git a/vendor/mdbook/src/cmd/init.rs b/vendor/mdbook/src/cmd/init.rs index d8ce93d16..2c6415b6d 100644 --- a/vendor/mdbook/src/cmd/init.rs +++ b/vendor/mdbook/src/cmd/init.rs @@ -56,7 +56,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { "git" => builder.create_gitignore(true), _ => builder.create_gitignore(false), }; - } else { + } else if !args.get_flag("force") { println!("\nDo you want a .gitignore to be created? (y/n)"); if confirm() { builder.create_gitignore(true); @@ -65,6 +65,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> { config.book.title = if args.contains_id("title") { args.get_one::<String>("title").map(String::from) + } else if args.get_flag("force") { + None } else { request_book_title() }; @@ -84,7 +86,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { /// Obtains author name from git config file by running the `git config` command. fn get_author_name() -> Option<String> { let output = Command::new("git") - .args(&["config", "--get", "user.name"]) + .args(["config", "--get", "user.name"]) .output() .ok()?; @@ -114,5 +116,5 @@ fn confirm() -> bool { io::stdout().flush().unwrap(); let mut s = String::new(); io::stdin().read_line(&mut s).ok(); - matches!(&*s.trim(), "Y" | "y" | "yes" | "Yes") + matches!(s.trim(), "Y" | "y" | "yes" | "Yes") } diff --git a/vendor/mdbook/src/cmd/serve.rs b/vendor/mdbook/src/cmd/serve.rs index 88898567e..eeb19cb37 100644 --- a/vendor/mdbook/src/cmd/serve.rs +++ b/vendor/mdbook/src/cmd/serve.rs @@ -48,7 +48,7 @@ pub fn make_subcommand() -> Command { // Serve command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; let port = args.get_one::<String>("port").unwrap(); let hostname = args.get_one::<String>("hostname").unwrap(); @@ -102,7 +102,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { info!("Building book..."); // FIXME: This area is really ugly because we need to re-set livereload :( - let result = MDBook::load(&book_dir).and_then(|mut b| { + let result = MDBook::load(book_dir).and_then(|mut b| { update_config(&mut b); b.build() }); diff --git a/vendor/mdbook/src/cmd/test.rs b/vendor/mdbook/src/cmd/test.rs index 3efe130b1..69f99f409 100644 --- a/vendor/mdbook/src/cmd/test.rs +++ b/vendor/mdbook/src/cmd/test.rs @@ -44,7 +44,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let chapter: Option<&str> = args.get_one::<String>("chapter").map(|s| s.as_str()); let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") { book.config.build.build_dir = dest_dir.to_path_buf(); diff --git a/vendor/mdbook/src/cmd/watch.rs b/vendor/mdbook/src/cmd/watch.rs index bbc6bde71..e9806e1cd 100644 --- a/vendor/mdbook/src/cmd/watch.rs +++ b/vendor/mdbook/src/cmd/watch.rs @@ -1,5 +1,6 @@ use super::command_prelude::*; use crate::{get_book_dir, open}; +use ignore::gitignore::Gitignore; use mdbook::errors::Result; use mdbook::utils; use mdbook::MDBook; @@ -20,7 +21,7 @@ pub fn make_subcommand() -> Command { // Watch command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; let update_config = |book: &mut MDBook| { if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") { @@ -41,7 +42,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { trigger_on_change(&book, |paths, book_dir| { info!("Files changed: {:?}\nBuilding book...\n", paths); - let result = MDBook::load(&book_dir).and_then(|mut b| { + let result = MDBook::load(book_dir).and_then(|mut b| { update_config(&mut b); b.build() }); @@ -62,14 +63,14 @@ fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec<PathBuf> { match find_gitignore(book_root) { Some(gitignore_path) => { - match gitignore::File::new(gitignore_path.as_path()) { - Ok(exclusion_checker) => filter_ignored_files(exclusion_checker, paths), - Err(_) => { - // We're unable to read the .gitignore file, so we'll silently allow everything. - // Please see discussion: https://github.com/rust-lang/mdBook/pull/1051 - paths.iter().map(|path| path.to_path_buf()).collect() - } + let (ignore, err) = Gitignore::new(&gitignore_path); + if let Some(err) = err { + warn!( + "error reading gitignore `{}`: {err}", + gitignore_path.display() + ); } + filter_ignored_files(ignore, paths) } None => { // There is no .gitignore file. @@ -85,18 +86,13 @@ fn find_gitignore(book_root: &Path) -> Option<PathBuf> { .find(|p| p.exists()) } -fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec<PathBuf> { +fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> { paths .iter() - .filter(|path| match exclusion_checker.is_excluded(path) { - Ok(exclude) => !exclude, - Err(error) => { - warn!( - "Unable to determine if {:?} is excluded: {:?}. Including it.", - &path, error - ); - true - } + .filter(|path| { + !ignore + .matched_path_or_any_parents(path, path.is_dir()) + .is_ignore() }) .map(|path| path.to_path_buf()) .collect() |