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

[Question] Would it be more user-friendly to not panic when binwalk is run with no arguments? #814

Open
Adamkadaban opened this issue Dec 28, 2024 · 0 comments

Comments

@Adamkadaban
Copy link

This is very minor, but when I first ran v3 I saw the first and last line and automatically assumed binwalk was broken without reading the panic message.

image

Almost every other tool I use prints the help menu by default when run with no arguments.

I think just exiting rather than panicking would also be more consistent with what binwalk currently prints when invalid arguments are passed

Thoughts on switching panic! for one of the following?

Error and exit here

diff --git a/src/main.rs b/src/main.rs
index ed46ef5..50e22e7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -68,7 +68,8 @@ fn main() {
 
     // If --list was not specified, a target file must be provided
     if cliargs.file_name.is_none() {
-        panic!("No target file name specified! Try --help.");
+        eprintln!("No target file name specified! Try --help.");
+        process::exit(1);
     }
 
     let mut json_logger = json::JsonLogger::new(cliargs.log);

Print help menu and exit here

diff --git a/src/cliparser.rs b/src/cliparser.rs
index ff7e89e..8a0605a 100644
--- a/src/cliparser.rs
+++ b/src/cliparser.rs
@@ -1,4 +1,4 @@
-use clap::Parser;
+use clap::{CommandFactory, Parser};
 
 #[derive(Debug, Parser)]
 #[command(author, version, about, long_about = None)]
@@ -68,5 +68,14 @@ pub struct CliArgs {
 }
 
 pub fn parse() -> CliArgs {
-    CliArgs::parse()
+    let args = CliArgs::parse();
+
+    if std::env::args().len() == 1 {
+        CliArgs::command()
+            .print_help()
+            .expect("Failed to print help");
+        std::process::exit(0);
+    }
+
+    args
 }

If one of these is something you think is reasonable, I can formalize it in a PR

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

No branches or pull requests

1 participant