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

Minor cli improvements #139

Merged
merged 6 commits into from
Jan 30, 2025
Merged

Minor cli improvements #139

merged 6 commits into from
Jan 30, 2025

Conversation

gytis-ivaskevicius
Copy link
Contributor

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?

Copy link

cloudflare-workers-and-pages bot commented Jan 29, 2025

Deploying blockfrost-platform with  Cloudflare Pages  Cloudflare Pages

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

View logs

@michalrus
Copy link
Member

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?

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

@michalrus
Copy link
Member

Also, in that --help text:

      --init

      --config <CONFIG>

IMO, --init and --config are important (and non-obvious) enough to warrant some short help text, WDYT? Like:

      --solitary
          Whether to run in solitary mode, without registering with the Icebreakers API

Copy link
Member

@michalrus michalrus left a 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 ↑

Copy link
Member

@michalrus michalrus left a 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) ✅

Copy link
Member

@michalrus michalrus left a comment

Choose a reason for hiding this comment

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

Checks are failing:

  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.

@vladimirvolek vladimirvolek merged commit 7bc6815 into main Jan 30, 2025
10 checks passed
@michalrus michalrus deleted the minor-cli-improvements branch January 31, 2025 08:46
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.

3 participants