-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow overriding cache directory through config #276
Conversation
@niklasmohrin sorry for missing #266, I wanted to get PRs unblocked starting at the oldest, and didn't yet see that you already submitted a proposed solution (I skimmed over it since it was still marked as draft)... 🙁 I think I chose a different approach than you did. I determine the final path in Validation of that path is being done by the cache itself: If the cache is instantiated with a path, it tries to ensure that the path exists. If it doesn't, it is created. If creation fails, the program is aborted. I'd be interested in your opinion on that. |
1a7e71f
to
477eed0
Compare
dc64d41
to
5c017cd
Compare
@niklasmohrin everything should be updated and all your feedback should be addressed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Some more comments, a handful of them are suggestions about removing code comments - I think that the code following those comments is just as expressive (if not more) than the comment while being more precise. I think the comments here add noise and don't provide any benefit. (and, also, all the textbook arguments like "comments aren't run in tests", "comments duplicate knowledge", ...)
There are more such comments around the codebase (and I would, in most cases, like them gone; not today, but with every little refactor :D). If I recall correctly, we disagreed over this before, haven't we? What did we settle on back then?
Hehe, I know that discussion from other projects 🙂 It comes down to a matter of style, but I think there are good reasons for it. I really like to structure code into blocks that do some kind of action. For example, when creating a file in a directory: fn myfunction() {
check_if_dir_exists();
check_if_dir_is_writable();
write_file();
set_file_permissions();
} In the example above, the three function calls are only 1 line each and self-explanatory. However, when code get bigger, sometimes you need to fully read through the block to understand what it does. With trivial code, that's simple. But if it's a bit more complex, it takes longer. So I follow a code style where these blocks (potentially spanning multiple lines of code) are preceded with a line comment that explains what the following code does. For example: fn myfunction() {
// Ensure that we can write the directory
check_if_dir_exists();
check_if_dir_is_writable();
// Directory is writable! Actually write the file
write_file();
set_file_permissions();
} What I like about this style is that it's really simple to skim over an implementation by just looking at the block headers. Sometimes, blocks are small and self-explanatory, but I usually add these comments anyways for consistency. The idea is not to just state what the next line is doing, but to guide the reader through the code, and - if it makes sense - to also explain the reason why certain things are the way they are. As a concrete example. This code: ...can be skimmed over easily, especially with syntax highlighting. To my mind, I read it like this: ...which, I would argue, is much easier to quickly understand than this: Note that the last example is not unreadable. I think it's fairly easy to read. But it takes more time and brainpower to process than the version where each block is summarized. I do kind of feel strongly about this, so I would not want to take away comments, as long as this "block-summary-comment" style is consistent within a function. I don't expect contributors to do this as well, of course, as long as functions remain small and easy to read. (Once functions do get more complex, I think it's valuable to either split them up into multiple functions, or to use comments in a more structured way.) |
8c8f612
to
2894f48
Compare
Great, thanks for the review. All issues should have been addressed. Regarding the comments: Yes, absolutely, often the clarity of the code can be improved with refactoring or better naming. I'm not saying that shouldn't be done, on the contrary 🙂 And if a method is simple enough, then comments aren't needed. Once it crosses a certain complexity, I simply like adding block comments (in the style of headlines) consistently. Even if this means that sometimes very short blocks have a comment as well. But it looks more consistent. Any other last feedback? I plan to merge this and prepare the 1.5.1 release by the end of the week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Some last remarks for this PR:
- Config: Add `cache_dir` to `[directories]` section - Logic to handle legacy env var, config override and default cache dir selection is now in the `Config::try_from(RawConfig)` impl - Deprecate old `TEALDEER_CACHE_DIR` env variable - Update docs Co-authored-by: Hans Gaiser <hansg91@gmail.com>
This also introduces the path source information for that directory, which was previously unknown.
Additionally, rename `cache_dir` to `pages_dir` where terminology was wrong.
- StyleConfig - DisplayConfig - UpdatesConfig
2894f48
to
c44faf2
Compare
🎉 Thanks! All feedback should now be addressed. |
Based on #212. Thanks @hgaiser for the initial work!
cache_dir
to[directories]
sectionTEALDEER_CACHE_DIR
env variablecustom_pages_dir
as wellImplementation notes:
Config::try_from(RawConfig)
implcustom_pages_dir
is moved intoConfig::try_from(RawConfig)
as well for consistencyThe logic to determine which cache directory is used is now in
config.rs
, when converting theRawConfig
toConfig
. I think this is the place where the config file and external factors (defaults, env vars, etc) can be taken into account to determine a final config.