Skip to content

Commit 8654a1e

Browse files
committed
fix: show help when no parameters provided instead of error
- Made files argument optional instead of required - Added check to display help output when no files are provided - Refactored command definition into reusable build_command() function - Improves user experience by showing helpful usage information
1 parent 946ad65 commit 8654a1e

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/main.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ impl CsvFieldMap {
258258
}
259259
}
260260

261-
fn main() -> Result<()> {
262-
let matches = Command::new("BBL Parser")
261+
fn build_command() -> Command {
262+
Command::new("BBL Parser")
263263
.version(env!("CARGO_PKG_VERSION"))
264264
.about("Read and parse BBL blackbox log files. Output to various formats.")
265265
.arg(
266266
Arg::new("files")
267267
.help("BBL files to parse (.BBL, .BFL, .TXT extensions supported, case-insensitive, supports globbing)")
268-
.required(true)
268+
.required(false)
269269
.num_args(1..)
270270
.index(1),
271271
)
@@ -311,15 +311,28 @@ fn main() -> Result<()> {
311311
.help("Force export of all logs, including short flights (bypasses smart filtering: <5s skip, 5-15s needs >1500fps, >15s keep)")
312312
.action(clap::ArgAction::SetTrue),
313313
)
314-
.get_matches();
314+
}
315+
316+
fn main() -> Result<()> {
317+
let matches = build_command().get_matches();
315318

316319
let debug = matches.get_flag("debug");
317320
let export_csv = matches.get_flag("csv");
318321
let export_gpx = matches.get_flag("gpx") || matches.get_flag("gps");
319322
let export_event = matches.get_flag("event");
320323
let force_export = matches.get_flag("force-export");
321324
let output_dir = matches.get_one::<String>("output-dir").cloned();
322-
let file_patterns: Vec<&String> = matches.get_many::<String>("files").unwrap().collect();
325+
326+
// Check if no files were provided and show help
327+
let file_patterns: Vec<&String> = match matches.get_many::<String>("files") {
328+
Some(files) => files.collect(),
329+
None => {
330+
// No files provided, show help and exit
331+
build_command().print_help()?;
332+
println!();
333+
return Ok(());
334+
}
335+
};
323336

324337
let export_options = ExportOptions {
325338
csv: export_csv,

0 commit comments

Comments
 (0)