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

Adds support of usage of a TOML "dotfile" config file in the user's homedir (In-Progress) #19

Merged
merged 20 commits into from
Oct 5, 2024

Conversation

mulla028
Copy link
Contributor

@mulla028 mulla028 commented Oct 1, 2024

Description

This is a draft pull-request that allows us to communicate along with arrival of the new commits.

What's new ?

Cargo.toml file updated, it acquired new dependency called "TOML"
Parses TOML file and uses data out there

Closes #18

@mulla028 mulla028 changed the title TOML dependecies added Adds support usage of a TOML "dotfile" config file in the user's homedir Oct 1, 2024
@mulla028 mulla028 changed the title Adds support usage of a TOML "dotfile" config file in the user's homedir Adds support usage of a TOML "dotfile" config file in the user's homedir (In-Progress) Oct 1, 2024
@mulla028 mulla028 changed the title Adds support usage of a TOML "dotfile" config file in the user's homedir (In-Progress) Adds support of usage of a TOML "dotfile" config file in the user's homedir (In-Progress) Oct 1, 2024
@theoforger
Copy link
Owner

Thanks for the contribution! Can you make a separate module for this new feature?

Simply declare the module inside lib.rs:

pub mod config;

And then add your code inside config.rs.

Happy coding!

@mulla028
Copy link
Contributor Author

mulla028 commented Oct 2, 2024

Thanks for the contribution! Can you make a separate module for this new feature?

Simply declare the module inside lib.rs:

pub mod config;

And then add your code inside config.rs.

Happy coding!

Yes, for this feature the best practice would be to wrap the entire implementation in a separate module.
Thank you for your attention!

@mulla028 mulla028 marked this pull request as ready for review October 2, 2024 02:14
@mulla028
Copy link
Contributor Author

mulla028 commented Oct 2, 2024

I have marked this pr as ready for review; however, if you are satisfied with the result, do not merge. I still have to comment the code.

@theoforger
Copy link
Owner

Just letting you know that I merged another branch to main, which I just merged into this branch as well.

Also, I added linting check to the GitHub Actions workflow. Make sure you run cargo fmt on the local project before pushing.

Thanks!

@theoforger
Copy link
Owner

While you're still working on this:

For the sake of freedesktop convention, is it OK to keep the toml file inside the config directory? You can call the dir::config_dir() function to get the path. Create a directory in the config directory called mastermind, and put the config file inside as config.toml.

For example, on Linux, dir::config_dir() will point you to ~/.config, so the config file should be located at ~/.config/mastermind/config.toml

Hope that's clear enough. Feel free to ask me anything! 😄

@mulla028
Copy link
Contributor Author

mulla028 commented Oct 4, 2024

Have completed all the required changes, now file is getting generated based on .env inside of homedir

Copy link
Owner

@theoforger theoforger left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! The new modules looks nice and neat. I also like the custom enum for error handling

There are some issues though:

First I noticed that if the config file exist but is empty, the program will just panic:

thread 'main' panicked at src/config.rs:102:22:
index not found
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Second, if the config file doesn't exist, the generated file uses inline tables instead of tables. It doesn't affect the functionalities, but is less readable, which is important for config files. Here's the generated file:

api = { base = "...", key = "..." }

There are some other issues which I'll discuss in code review

Cargo.toml Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
Copy link
Owner

@theoforger theoforger left a comment

Choose a reason for hiding this comment

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

Great work! We're almost there. Just some trivial details

sample-mindmaster-config.toml Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
@theoforger theoforger merged commit 8549cbe into theoforger:main Oct 5, 2024
1 check passed
@mulla028 mulla028 deleted the issue-18 branch November 13, 2024 01:35
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.

New Feature: Add support using a TOML "dotfile" config file in the user's homedir
2 participants