From cdb251736507f01ca945ed9564b754e641df359c Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Tue, 5 Jan 2021 00:01:28 +0100 Subject: [PATCH] new: make walk options configurable on CLI By default hidden files, patterns listed in `.export-ignore` as well as any files ignored by git are excluded from exports. This behavior has been made configurable on the CLI using the new flags `--hidden`, `--ignore-file` and `--no-git`. --- README.md | 7 +++++-- book/book-src/README.md | 7 +++++-- book/book-src/usage.md | 7 +++++-- book/obsidian-src/usage.md | 7 +++++-- src/main.rs | 23 ++++++++++++++++++++--- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 566ff01..6139cca 100644 --- a/README.md +++ b/README.md @@ -72,9 +72,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev ### Ignoring files By default, hidden files, patterns listed in `.export-ignore` as well as any files ignored by git (if your vault is part of a git repository) will be excluded from exports. -These options will become configurable in the next release. -Notes linking to ignored notes will be unlinked (they'll only include the link text). Embeds of ignored notes will be skipped entirely. +These options may be adjusted with `--hidden`, `--ignore-file` and `--no-git` if desired. +(See `--help` for more information). + +Notes linking to ignored notes will be unlinked (they'll only include the link text). +Embeds of ignored notes will be skipped entirely. #### Ignorefile syntax diff --git a/book/book-src/README.md b/book/book-src/README.md index 566ff01..6139cca 100644 --- a/book/book-src/README.md +++ b/book/book-src/README.md @@ -72,9 +72,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev ### Ignoring files By default, hidden files, patterns listed in `.export-ignore` as well as any files ignored by git (if your vault is part of a git repository) will be excluded from exports. -These options will become configurable in the next release. -Notes linking to ignored notes will be unlinked (they'll only include the link text). Embeds of ignored notes will be skipped entirely. +These options may be adjusted with `--hidden`, `--ignore-file` and `--no-git` if desired. +(See `--help` for more information). + +Notes linking to ignored notes will be unlinked (they'll only include the link text). +Embeds of ignored notes will be skipped entirely. #### Ignorefile syntax diff --git a/book/book-src/usage.md b/book/book-src/usage.md index 3ec49c6..d6d6fe2 100644 --- a/book/book-src/usage.md +++ b/book/book-src/usage.md @@ -39,9 +39,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev ### Ignoring files By default, hidden files, patterns listed in `.export-ignore` as well as any files ignored by git (if your vault is part of a git repository) will be excluded from exports. -These options will become configurable in the next release. -Notes linking to ignored notes will be unlinked (they'll only include the link text). Embeds of ignored notes will be skipped entirely. +These options may be adjusted with `--hidden`, `--ignore-file` and `--no-git` if desired. +(See `--help` for more information). + +Notes linking to ignored notes will be unlinked (they'll only include the link text). +Embeds of ignored notes will be skipped entirely. #### Ignorefile syntax diff --git a/book/obsidian-src/usage.md b/book/obsidian-src/usage.md index e4bc8ce..5db3fb6 100644 --- a/book/obsidian-src/usage.md +++ b/book/obsidian-src/usage.md @@ -39,9 +39,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev ### Ignoring files By default, hidden files, patterns listed in `.export-ignore` as well as any files ignored by git (if your vault is part of a git repository) will be excluded from exports. -These options will become configurable in the next release. -Notes linking to ignored notes will be unlinked (they'll only include the link text). Embeds of ignored notes will be skipped entirely. +These options may be adjusted with `--hidden`, `--ignore-file` and `--no-git` if desired. +(See `--help` for more information). + +Notes linking to ignored notes will be unlinked (they'll only include the link text). +Embeds of ignored notes will be skipped entirely. #### Ignorefile syntax diff --git a/src/main.rs b/src/main.rs index 4614f7d..caf15f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use eyre::{eyre, Result}; use gumdrop::Options; -use obsidian_export::{ExportError, Exporter, FrontmatterStrategy}; +use obsidian_export::{ExportError, Exporter, FrontmatterStrategy, WalkOptions}; use std::path::PathBuf; #[derive(Debug, Options)] @@ -22,6 +22,19 @@ struct Opts { default = "auto" )] frontmatter_strategy: FrontmatterStrategy, + + #[options( + no_short, + help = "Read ignore patterns from files with this name", + default = ".export-ignore" + )] + ignore_file: String, + + #[options(no_short, help = "Export hidden files", default = "false")] + hidden: bool, + + #[options(no_short, help = "Disable git integration", default = "false")] + no_git: bool, } fn frontmatter_strategy_from_str(input: &str) -> Result { @@ -38,10 +51,14 @@ fn main() -> Result<()> { let source = args.source.unwrap(); let destination = args.destination.unwrap(); + let mut walk_options = WalkOptions::default(); + walk_options.ignore_filename = &args.ignore_file; + walk_options.ignore_hidden = !args.hidden; + walk_options.honor_gitignore = !args.no_git; + let mut exporter = Exporter::new(source, destination); exporter.frontmatter_strategy(args.frontmatter_strategy); - // TODO: Pass in configurable walk_options here: exporter.walk_options(..); - // TODO: This should allow settings for ignore_hidden and honor_gitignore. + exporter.walk_options(walk_options); if let Err(err) = exporter.run() { match err {