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`.
This commit is contained in:
Nick Groenen 2021-01-05 00:01:28 +01:00
parent 4401123ea1
commit cdb2517365
No known key found for this signature in database
GPG Key ID: 4F0AD019928AE098
5 changed files with 40 additions and 11 deletions

View File

@ -72,9 +72,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev
### Ignoring files ### 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. 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 #### Ignorefile syntax

View File

@ -72,9 +72,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev
### Ignoring files ### 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. 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 #### Ignorefile syntax

View File

@ -39,9 +39,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev
### Ignoring files ### 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. 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 #### Ignorefile syntax

View File

@ -39,9 +39,12 @@ To completely remove any frontmatter from exported notes, use `--frontmatter=nev
### Ignoring files ### 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. 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 #### Ignorefile syntax

View File

@ -1,6 +1,6 @@
use eyre::{eyre, Result}; use eyre::{eyre, Result};
use gumdrop::Options; use gumdrop::Options;
use obsidian_export::{ExportError, Exporter, FrontmatterStrategy}; use obsidian_export::{ExportError, Exporter, FrontmatterStrategy, WalkOptions};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Debug, Options)] #[derive(Debug, Options)]
@ -22,6 +22,19 @@ struct Opts {
default = "auto" default = "auto"
)] )]
frontmatter_strategy: FrontmatterStrategy, 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<FrontmatterStrategy> { fn frontmatter_strategy_from_str(input: &str) -> Result<FrontmatterStrategy> {
@ -38,10 +51,14 @@ fn main() -> Result<()> {
let source = args.source.unwrap(); let source = args.source.unwrap();
let destination = args.destination.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); let mut exporter = Exporter::new(source, destination);
exporter.frontmatter_strategy(args.frontmatter_strategy); exporter.frontmatter_strategy(args.frontmatter_strategy);
// TODO: Pass in configurable walk_options here: exporter.walk_options(..); exporter.walk_options(walk_options);
// TODO: This should allow settings for ignore_hidden and honor_gitignore.
if let Err(err) = exporter.run() { if let Err(err) = exporter.run() {
match err { match err {