-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
chore(cli): configure remaining arguments via .env file #1940
Conversation
We are using nightly formatter=) |
Could you also update |
Also, it would be nice if you added a unit test that verifies that all arguments can be configured via the |
Sorry to get back only now. I'm trying to do that but I'm wondering what's the best approach given there are a lot of arguments and I'd like some feedback if possible. I've seen there is a nice procedural macro fuel-core/bin/fuel-core/src/cli/run/consensus.rs Lines 80 to 88 in 12cb17f
This can be used also for environment variables as well, like so: #[test_case(&[] => Ok(Trigger::Instant); "defaults to instant trigger")]
#[test_case(&["", "--poa-instant=false"] => Ok(Trigger::Never); "never trigger if instant is explicitly disabled")]
#[test_case(&["POA_INSTANT=FALSE", ] => Ok(Trigger::Never); "ENV never trigger if instant is explicitly disabled")]
#[test_case(&["", "--poa-interval-period=1s"] => Ok(Trigger::Interval { block_time: StdDuration::from_secs(1)}); "uses interval mode if set")]
#[test_case(&["POA_INTERVAL_PERIOD=1s", ] => Ok(Trigger::Interval { block_time: StdDuration::from_secs(1)}); "ENV uses interval mode if set")]
#[test_case(&["", "--poa-instant=true", "--poa-interval-period=1s"] => Err(()); "can't set interval and instant at the same time")]
#[test_case(&["POA_INSTANT=TRUE", "POA_INTERVAL_PERIOD=1s"] => Err(()); "ENV can't set interval and instant at the same time")]
fn parse(args: &[&str]) -> Result<Trigger, ()> {
Command::try_parse_from(args)
.map_err(|_| ())
.map(|c| c.trigger.into())
} It would still be a bit noisy considering all the arguments of the I've also noticed that using reading from an environment variables file and using |
Sorry about the slow response. We appreciate the contribution.
What kind of feedback are you looking for?
I would encourage you to not force existing tests to fit your needs. Feel free to write some new tests with or without their own
Having a hard time understanding the problem described here. You can look to see if it's possible to use a tempfile to set up the |
Thanks for the response! I'll try my best to clarify some points:
Here is an example: suppose I'm in #[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[derive(Debug, Clone, Parser)]
pub struct Command {
#[clap(flatten)]
trigger: PoATriggerArgs,
}
#[test]
fn parse_from_env() {
std::env::set_var("POA_INTERVAL_PERIOD", "2s");
Command::parse();
}
} The test may fail depending on how you run it, which I think is a bit undesirable: if you run it with
In my opinion not being able to run test individually is not an ideal development experience but of course I cannot enforce this. With that said, I think the only way to avoid
In general I wanted to know if you had some guidelines/strategy I need to follow before trying to tackle these unit tests considering also the constraints outline above, also because it may be a lot of manual work even with the |
Sorry for the delay=D PR looks good, but it must be updated to the latest master. I will close PR for now just to reduce the number of PRs=) But you are welcome to open it gain on top of the |
Closes #458. This PR allows to configure the remaining CLI arguments using the
.env
file. I hope I haven't left some options out! :)I have reviewed the changes by playing around with the
.env
file and see if the options were set properly, but I'm not very familiar with the codebase yet so I apologise in advance for any hiccup.Small q: is there some formatting rule I need to enable? I think I'm running vanilla
rustfmt
but imports were consistently re-organised so I had to turn it off.