From a1df68bfb81ce0d033ff146ac2882a59ec617cb6 Mon Sep 17 00:00:00 2001 From: devttys0 Date: Mon, 6 Jan 2025 15:28:20 -0500 Subject: [PATCH] Fixed output when no command line options are specified --- src/cliparser.rs | 13 +++++++++++-- src/main.rs | 7 +------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cliparser.rs b/src/cliparser.rs index ff7e89ecb..a54f29c12 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 output"); + std::process::exit(1); + } + + args } diff --git a/src/main.rs b/src/main.rs index ed46ef5fc..ff6a61894 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ fn main() { // Initialize logging env_logger::init(); - // Process command line aguments + // Process command line arguments let mut cliargs = cliparser::parse(); // If --list was specified, just display a list of signatures and return @@ -66,11 +66,6 @@ fn main() { cliargs.file_name = Some(STDIN.to_string()); } - // 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."); - } - let mut json_logger = json::JsonLogger::new(cliargs.log); // If entropy analysis was requested, generate the entropy graph and return