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

Save Results #43

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Save Results #43

wants to merge 7 commits into from

Conversation

PriceHiller
Copy link

@PriceHiller PriceHiller commented Aug 11, 2022

This PR closes issue #11.

Summary

This PR adds the ability to save results to a file via the -r flag. In the current implementation results are not saved by default, instead the user must pass either the new -r flag and a path or set the TOIPE_RESULTS_FILE environment variable to a file path.

Notes

The only thing that we might want to modify is the error type being returned by the save_results function I've added. I do not use ToipeError and instead fall back on std::io::Error which gets unrolled up where it is then turned into ToipeError, but in doing so the error information is dropped. See here for the save_results function and here for how I'm taking the error in and returning ToipeError.



Let me know what suggestions you have and I'll be happy to make any relevant modifications. I'm not the biggest Rust guy, so I may have missed more idiomatic patterns that would improve this PR.

@PriceHiller PriceHiller changed the title Add Results Save Results Aug 11, 2022
@Samyak2
Copy link
Owner

Samyak2 commented Oct 21, 2022

Thank you for this @treatybreaker. I haven't been able to find time to review this PR thoroughly, it will take some more time.

Some thoughts though:

  • I think the results should be saved by default. With a flag to disable them. Something like -r NONE to disable saving and -r filepath to save to a different file. (This is also how neovim works for its -u flag).
  • As for the error handling part, I was moving toipe to use anyhow in Better errors using anyhow #40. I'll update here once that is merged and you can use that.

Copy link
Owner

@Samyak2 Samyak2 left a comment

Choose a reason for hiding this comment

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

Your code looks pretty good! Just one suggestion for now. I haven't looked too closely and I haven't tried it out yet, so I may have some more comments later.

Comment on lines +95 to +101
if config.results_file.is_none() {
config.results_file = match std::env::var("TOIPE_RESULTS_FILE") {
Ok(results_file_env) => Some(results_file_env),
Err(_) => None,
}
}

Copy link
Owner

Choose a reason for hiding this comment

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

clap supports reading a configuration value from an environment variable. See env under https://docs.rs/clap/latest/clap/_derive/index.html#arg-attributes. Could you add that to the ToipeConfig struct and remove this code from here?

Copy link
Author

Choose a reason for hiding this comment

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

I can take a look and get those changes in. I'm pretty busy myself as it stands, so I likely won't be able to get around to it until this coming weekend. Only saw this now due to my inbox refreshing.

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.

2 participants