Repository: dbrgn/tealdeer (rust)

Issue:
Auto update cache by default?
Hi!

Thanks for writing tealdeer, it's been great to use.

I've found having to manually update the cache to be confusing, especially on first-use. Consider the reference tldr package versus tealdeer:

```sh
❯ paru -S tldr
❯ tldr tldr

  Displays simple help pages for command-line tools, from the tldr-pages project.
  More information: <https://tldr.sh>.
```

```sh
❯ paru -S tealdeer
❯ tldr tldr
Warning: Cache not found. Please run `tldr --update`.
```

I had to dig throug the documentation and GitHub issues to find https://github.com/dbrgn/tealdeer/issues/90 and https://dbrgn.github.io/tealdeer/config_updates.html. At which point I had to seed the config:

```sh
❯ tldr --seed-config
```

Then enable auto cache update:

```diff
[updates]
-auto_update = false
+auto_update = true
auto_update_interval_hours = 720
```

Does it make sense to enable this behaviour by default? 

Pull request description:
Add note about auto-updates when cache is missing
Output:

![screenshot-20220109-153929](https://user-images.githubusercontent.com/105168/148687060-847475bd-d3e0-4ba3-9ae5-febafcfdff55.png)

Fixes #250.

@niklasmohrin @uhthomas what do you think?

Patch:
diff --git a/src/main.rs b/src/main.rs
index 17e7358..216c349 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -81,10 +81,20 @@ fn check_cache(args: &Args, enable_styles: bool) -> CheckCacheResult {
             CheckCacheResult::CacheFound
         }
         CacheFreshness::Missing => {
-            print_warning(
+            print_error(
                 enable_styles,
-                "Cache not found. Please run `tldr --update`.",
+                &anyhow::anyhow!(
+                    "Page cache not found. Please run `tldr --update` to download the cache."
+                ),
             );
+            println!("\nNote: You can optionally enable automatic cache updates by adding the");
+            println!("following config to your config file:\n");
+            println!("  [updates]");
+            println!("  auto_update = true\n");
+            println!("The path to your config file can be looked up with `tldr --show-paths`.");
+            println!("To create an initial config file, use `tldr --seed-config`.\n");
+            println!("You can find more tips and tricks in our docs:\n");
+            println!("  https://dbrgn.github.io/tealdeer/config_updates.html");
             CheckCacheResult::CacheMissing
         }
     }


Test patch:
diff --git a/tests/lib.rs b/tests/lib.rs
index 0f3128e..7c54477 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -131,7 +131,7 @@ fn test_missing_cache() {
         .args(["sl"])
         .assert()
         .failure()
-        .stderr(contains("Cache not found. Please run `tldr --update`."));
+        .stderr(contains("Page cache not found. Please run `tldr --update`"));
 }
 
 #[test]
@@ -143,7 +143,7 @@ fn test_update_cache() {
         .args(["sl"])
         .assert()
         .failure()
-        .stderr(contains("Cache not found. Please run `tldr --update`."));
+        .stderr(contains("Page cache not found. Please run `tldr --update`"));
 
     testenv
         .command()
@@ -518,7 +518,7 @@ fn test_list_flag_rendering() {
         .args(["--list"])
         .assert()
         .failure()
-        .stderr(contains("Cache not found. Please run `tldr --update`."));
+        .stderr(contains("Page cache not found. Please run `tldr --update`"));
 
     testenv.add_entry("foo", "");
 
@@ -551,7 +551,7 @@ fn test_autoupdate_cache() {
         .args(["--list"])
         .assert()
         .failure()
-        .stderr(contains("Cache not found. Please run `tldr --update`."));
+        .stderr(contains("Page cache not found. Please run `tldr --update`"));
 
     let config_file_path = testenv.config_dir.path().join("config.toml");
     let cache_file_path = testenv.cache_dir.path().join(TLDR_PAGES_DIR);