-
Notifications
You must be signed in to change notification settings - Fork 159
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
Connor/default config location #1494
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1494 +/- ##
==========================================
+ Coverage 44.30% 44.37% +0.07%
==========================================
Files 323 319 -4
Lines 28414 28253 -161
==========================================
- Hits 12588 12537 -51
+ Misses 15826 15716 -110
Continue to review full report at Codecov.
|
Let's use https://crates.io/crates/directories/ instead of querying |
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.
If FOREST_CONFIG_PATH
isn't available, use https://crates.io/crates/directories/ to query the config path in a cross platform way.
I didn't know this one, looks pretty good. Probably we should use it in some other places around Forest we want to strive for being cross-platform without containterization. |
forest/src/cli/mod.rs
Outdated
@@ -224,6 +217,31 @@ impl CliOpts { | |||
} | |||
} | |||
|
|||
pub fn find_default_config() -> Option<Config> { | |||
// check forest config path first, then look at other default locations |
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.
From a user perspective, it may be nice to check all those places and display a piece of information if e.g. forest
will use config from XDG_CONFIG_HOME
and not what is there in HOME_DIR
. Otherwise, we could at least document it somewhere in README.
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.
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.
Yes, I think it would help to have some info
log that displays to the user the loaded config file location.
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.
And in case of doubt the user still can add config dump
to command-line to see the computed config.
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.
Added logging with config locations and errors that occured while trying to load the config. Resorts to default on error
forest/src/cli/mod.rs
Outdated
}; | ||
|
||
if path.exists() { | ||
let toml = match read_file_to_string(&path) { |
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.
Perhaps you could omit match
and if let
later on with ?
and ok()?
?
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.
Gets tricky with Result<> into Option<>, this is the simplest way i can see it currently. I've refactored to DRY and reduce repeated code
What are the pros of using |
It's easier to follow OS conventions with |
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.
Let's put the available default locations and their priority to the config section of README, what do you think?
forest/src/cli/mod.rs
Outdated
None => match find_default_config() { | ||
Some(cfg) => cfg, | ||
None => Config::default(), | ||
}, |
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.
None => match find_default_config() { | |
Some(cfg) => cfg, | |
None => Config::default(), | |
}, | |
None => find_default_config().unwrap_or_default() |
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.
I think that's a good idea, will sneak it in now
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.
Thanks! It's really useful!
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links