tealdeer-rs / tealdeer

A very fast implementation of tldr in Rust.
https://tealdeer-rs.github.io/tealdeer/
Apache License 2.0
4.17k stars 123 forks source link

`tldr --clear-cache` with $TEALDEER_CACHE_DIR requires manual mkdir to rebuild cache #167

Closed cho-m closed 3 years ago

cho-m commented 3 years ago

tldr --clear-cache deletes the $TEALDEER_CACHE_DIR folder but tldr --update is unable to remake the folder.

❯ tldr --list | head -n 2
2to3
7z

~
❯ tldr --clear-cache
Successfully deleted cache.
Could not update cache: Path specified by $TEALDEER_CACHE_DIR does not exist or is not a directory.

~
❯ tldr --list | head -n 2
Could not update cache: Path specified by $TEALDEER_CACHE_DIR does not exist or is not a directory.

~
❯ tldr --update
Could not update cache: Path specified by $TEALDEER_CACHE_DIR does not exist or is not a directory.

~
❯ mkdir -p "$TEALDEER_CACHE_DIR"

~
❯ tldr --update
Successfully updated cache.

Also, error messages in --show-paths:

❯ ./target/debug/tldr --show-paths
Config dir:  /Users/cho-m/.config/tealdeer/ (env variable)
Config path: /Users/cho-m/.config/tealdeer/config.toml
Cache dir:   [Error: CacheError: Path specified by $TEALDEER_CACHE_DIR does not exist or is not a directory.]
Pages dir:   [Error: CacheError: Path specified by $TEALDEER_CACHE_DIR does not exist or is not a directory.]
Could not update cache: Path specified by $TEALDEER_CACHE_DIR does not exist or is not a directory.
dbrgn commented 3 years ago

Oh, good catch!

dbrgn commented 3 years ago

I guess this only happens if you set the TEALDEER_CACHE_DIR variable, right?

I'm not yet sure what the ideal solution would be. Either the cache dir is implicitly created, or we only delete contents instead of the full directory.

cho-m commented 3 years ago

I guess this only happens if you set the TEALDEER_CACHE_DIR variable, right?

I think so (at least it is the case for me on macOS).

❯ unset TEALDEER_CACHE_DIR

❯ tldr --clear-cache
Successfully deleted cache.
Successfully updated cache.

I'm not yet sure what the ideal solution would be. Either the cache dir is implicitly created, or we only delete contents instead of the full directory.

Both are valid options. In case of latter, there should probably be some documentation that the user will need to mkdir on initial setup.

In my experience, a lot of modern tools do try to implicitly create directories. The tools I use that require manual creation are usually older like: less, zsh, gnupg, vim

dbrgn commented 3 years ago

I just wonder if creating the directory (including all parent directories) could have undesired side effects. It could mask a typo, for example.

On the other hand, that's easy to fix. Creating the directory automatically (just like it's being done for the default directory path) would probably be the best approach.