-
Notifications
You must be signed in to change notification settings - Fork 2
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
Minor cli improvements #139
Conversation
Deploying blockfrost-platform with
|
Latest commit: |
8f59c97
|
Status: | ✅ Deploy successful! |
Preview URL: | https://8eebd0ba.blockfrost-platform.pages.dev |
Branch Preview URL: | https://minor-cli-improvements.blockfrost-platform.pages.dev |
What about something like this? diff --git a/src/cli.rs b/src/cli.rs
index 08a1b0c..872a01f 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -75,10 +75,20 @@ fn get_config_path() -> PathBuf {
impl Args {
fn parse_args(config_path: PathBuf) -> Result<Args, AppError> {
+ const ENV_PREFIX: &str = "BLOCKFROST_";
+
+ let no_config_file = !config_path.exists();
+ let no_env_vars = std::env::vars().all(|(key, _val)| !key.starts_with(ENV_PREFIX));
+ let empty_argv = std::env::args().len() == 1;
+ if no_config_file && no_env_vars && empty_argv {
+ Self::command().print_help().unwrap();
+ std::process::exit(1);
+ }
+
let matches = Self::command().get_matches();
let mut config_layers = vec![
- Layer::Env(Some(String::from("BLOCKFROST_"))),
+ Layer::Env(Some(String::from(ENV_PREFIX))),
Layer::Clap(matches),
];
if config_path.exists() { |
Also, in that
IMO,
|
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.
Wrote some comments/questions above ↑
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.
LGTM, if you don’t want to add a little helper text to --init
(see the previous comment) ✅
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.
Failed to extract .tar.bz2 archive: Custom { kind: InvalidInput, error: TarError { desc: "failed to iterate over archive", io: Custom { kind: InvalidInput, error: DataMagic } } }
This is not your fault, probably GitHub gave us a broken archive, because of their current issues.
So I'm going to approve, but it would be good to restart the checks, and get ✅s.
Context
Implementation of #133
Unfortunately, I dont think it is possible to implement --help screen whenever the application is run without configuration due to the amount of config sources. I hope that's alright?