From 7899d3d24ac126e4fa974c04d38e40cf1a583a85 Mon Sep 17 00:00:00 2001 From: Liam Bigelow <40188355+bglw@users.noreply.github.com> Date: Tue, 17 Dec 2024 21:09:31 +1300 Subject: [PATCH] Add `--quiet` and `--silent` configuration options when indexing --- docs/content/docs/config-options.md | 18 +++++++++++-- .../_macros/run_failing.toolproof.macro.yml | 3 +++ ...run_failing_with_flags.toolproof.macro.yml | 3 +++ .../log_levels/error_logs.toolproof.yml | 15 +++++++++++ .../log_levels/success_logs.toolproof.yml | 26 +++++++++++++++++++ pagefind/src/fossick/mod.rs | 14 +++++----- pagefind/src/lib.rs | 4 +-- pagefind/src/logging.rs | 19 +++++++++----- pagefind/src/options.rs | 22 ++++++++++++++++ 9 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 pagefind/integration_tests/_macros/run_failing.toolproof.macro.yml create mode 100644 pagefind/integration_tests/_macros/run_failing_with_flags.toolproof.macro.yml create mode 100644 pagefind/integration_tests/log_levels/error_logs.toolproof.yml create mode 100644 pagefind/integration_tests/log_levels/success_logs.toolproof.yml diff --git a/docs/content/docs/config-options.md b/docs/content/docs/config-options.md index 6e215646..e519f0a0 100644 --- a/docs/content/docs/config-options.md +++ b/docs/content/docs/config-options.md @@ -5,11 +5,11 @@ nav_section: References weight: 51 --- -The Pagefind CLI has the following options. +The Pagefind CLI has the following options. These can be set via any [configuration source](/docs/config-sources/). > These configuration options only apply when running the Pagefind indexing tool on your site. -> For configuring Pagefind search in the browser, see [Pagefind Search Config](/docs/search-config/). +> For configuring Pagefind search in the browser, see [Pagefind Search Config](/docs/search-config/). > For configuring the Pagefind Default UI, see [Pagefind UI](/docs/ui/). ## Required arguments @@ -102,6 +102,20 @@ Prints extra logging while indexing the site. Only affects the CLI, does not imp |-------------|--------------------|------------| | `--verbose` | `PAGEFIND_VERBOSE` | `verbose` | +### Quiet +Only logs errors and warnings while indexing the site. Only affects the CLI, does not impact web-facing search. + +| CLI Flag | ENV Variable | Config Key | +|-----------|------------------|------------| +| `--quiet` | `PAGEFIND_QUIET` | `quiet` | + +### Silent +Only logs errors while indexing the site. Only affects the CLI, does not impact web-facing search. + +| CLI Flag | ENV Variable | Config Key | +|-----------|------------------|------------| +| `--silent` | `PAGEFIND_SILENT` | `silent` | + ### Logfile Writes logs to the given logfile, in addition to the console. Replaces the file on each run. diff --git a/pagefind/integration_tests/_macros/run_failing.toolproof.macro.yml b/pagefind/integration_tests/_macros/run_failing.toolproof.macro.yml new file mode 100644 index 00000000..6c96163d --- /dev/null +++ b/pagefind/integration_tests/_macros/run_failing.toolproof.macro.yml @@ -0,0 +1,3 @@ +macro: I run a failing Pagefind +steps: + - I run "%toolproof_process_directory%/target/%pagefind_mode%/pagefind" and expect it to fail diff --git a/pagefind/integration_tests/_macros/run_failing_with_flags.toolproof.macro.yml b/pagefind/integration_tests/_macros/run_failing_with_flags.toolproof.macro.yml new file mode 100644 index 00000000..c2998896 --- /dev/null +++ b/pagefind/integration_tests/_macros/run_failing_with_flags.toolproof.macro.yml @@ -0,0 +1,3 @@ +macro: I run a failing Pagefind with {flags} +steps: + - I run "%toolproof_process_directory%/target/%pagefind_mode%/pagefind %flags%" and expect it to fail diff --git a/pagefind/integration_tests/log_levels/error_logs.toolproof.yml b/pagefind/integration_tests/log_levels/error_logs.toolproof.yml new file mode 100644 index 00000000..2bb8873f --- /dev/null +++ b/pagefind/integration_tests/log_levels/error_logs.toolproof.yml @@ -0,0 +1,15 @@ +name: Log level > error logs +steps: + - step: I have the environment variable "PAGEFIND_SITE" set to "public" + + - macro: I run a failing Pagefind with "--verbose" + - "stdout should contain 'Found 0 files'" + - "stderr should contain 'Error: Pagefind was not able to build an index'" + + - macro: I run a failing Pagefind with "--quiet" + - "stdout should be empty" + - "stderr should contain 'Error: Pagefind was not able to build an index'" + + - macro: I run a failing Pagefind with "--silent" + - "stdout should be empty" + - "stderr should contain 'Error: Pagefind was not able to build an index'" diff --git a/pagefind/integration_tests/log_levels/success_logs.toolproof.yml b/pagefind/integration_tests/log_levels/success_logs.toolproof.yml new file mode 100644 index 00000000..140f9678 --- /dev/null +++ b/pagefind/integration_tests/log_levels/success_logs.toolproof.yml @@ -0,0 +1,26 @@ +name: Log level > success logs +steps: + - step: I have the environment variable "PAGEFIND_SITE" set to "public" + - step: I have a "public/index.html" file with the content {html} + html: >- +
Nothing
+ - step: I have a "public/cat/index.html" file with the content {html} + html: >- +Hello
+ - step: I have a "public/no-lang/index.html" file with the content {html} + html: >- +