Skip to content
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

Merged
merged 11 commits into from Mar 25, 2022
Merged

Connor/default config location #1494

merged 11 commits into from Mar 25, 2022

Conversation

connormullett
Copy link
Contributor

Summary of changes
Changes introduced in this pull request:

  • Forest will look for a default config file in $XDG_CONFIG_HOME (~/.config) or in the users home directory if not available.
  • If a config file is not passed to Forest when the node is started and a config file is not found, it will use a default configuration.

Reference issue to close (if applicable)

Closes

Other information and links

@codecov
Copy link

codecov bot commented Mar 22, 2022

Codecov Report

Merging #1494 (33d8b8a) into main (cf49ba7) will increase coverage by 0.07%.
The diff coverage is 0.00%.

@@            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     
Impacted Files Coverage Δ
forest/src/cli/mod.rs 0.00% <0.00%> (ø)
blockchain/message_pool/src/msg_chain.rs 80.24% <0.00%> (-0.41%) ⬇️
vm/actor/src/builtin/miner/mod.rs 33.49% <0.00%> (-0.05%) ⬇️
types/src/lib.rs 57.14% <0.00%> (ø)
types/src/sector/post.rs 27.27% <0.00%> (ø)
types/src/sector/registered_proof.rs
types/src/sector/mod.rs
types/src/randomness.rs
encoding/src/bytes.rs

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf49ba7...33d8b8a. Read the comment docs.

@lemmih
Copy link
Contributor

lemmih commented Mar 23, 2022

Let's use https://crates.io/crates/directories/ instead of querying XDG_CONFIG_HOME directly.

Copy link
Contributor

@lemmih lemmih left a 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.

@LesnyRumcajs
Copy link
Member

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.

@@ -224,6 +217,31 @@ impl CliOpts {
}
}

pub fn find_default_config() -> Option<Config> {
// check forest config path first, then look at other default locations
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how others feel about it @lemmih @elmattic

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

};

if path.exists() {
let toml = match read_file_to_string(&path) {
Copy link
Member

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()??

Copy link
Contributor Author

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

@elmattic
Copy link
Contributor

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.

What are the pros of using directories here instead of the lower level dirs?

@lemmih
Copy link
Contributor

lemmih commented Mar 23, 2022

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.

What are the pros of using directories here instead of the lower level dirs?

It's easier to follow OS conventions with directories. On mac and windows, we don't just want to create a forest folder in the config directory.

forest/src/cli/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@LesnyRumcajs LesnyRumcajs left a 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?

Comment on lines 163 to 166
None => match find_default_config() {
Some(cfg) => cfg,
None => Config::default(),
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
None => match find_default_config() {
Some(cfg) => cfg,
None => Config::default(),
},
None => find_default_config().unwrap_or_default()

Copy link
Contributor Author

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

forest/src/cli/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@LesnyRumcajs LesnyRumcajs left a 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!

@lemmih lemmih merged commit 1bad495 into main Mar 25, 2022
@lemmih lemmih deleted the connor/default-config-location branch March 25, 2022 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants