1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-25 20:25:28 +03:00
aports/testing/pipr/handle-unrecognized-option.patch
2022-04-02 15:32:27 +00:00

37 lines
1.2 KiB
Diff

Patch-Source: https://github.com/elkowar/pipr/pull/10
--
From d6618e720090f1f5e2c768684149a7518b2aa269 Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 2 Apr 2022 16:45:13 +0200
Subject: [PATCH] Print error message instead of panic on unrecognized option
Before:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnrecognizedOption("version")', src/main.rs:126:46
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted
After:
pipr: Unrecognized option: 'version'
---
src/main.rs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/main.rs b/src/main.rs
index 5d061c1..06b5c7c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -123,7 +123,13 @@ fn handle_cli_arguments() -> CliArgs {
);
opts.optflag("h", "help", "print this help menu");
- let matches = opts.parse(&cli_args[1..]).unwrap();
+ let matches = match opts.parse(&cli_args[1..]) {
+ Ok(m) => { m }
+ Err(e) => {
+ eprintln!("{}: {}", program, e.to_string());
+ std::process::exit(1);
+ }
+ };
if matches.opt_present("help") {
let brief = format!("Usage: {} [options]", program);