diff mbox series

[U-Boot,4/5] tools: dumpimage: Add help option and make error paths consistent

Message ID 20190126023154.19749-4-martyn.welch@collabora.com
State Accepted
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/5] tools: dumpimage: Provide more feedback on error | expand

Commit Message

Martyn Welch Jan. 26, 2019, 2:31 a.m. UTC
The utility dumpimage has error paths that display the usage and others
that exit without displaying usage. Add an explicit help option to
dumpimage to display the usage and remove it's use in error paths to make
the error messages more obvious and errors paths more consistent.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
---

 tools/dumpimage.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Tom Rini Feb. 3, 2019, 1:09 a.m. UTC | #1
On Sat, Jan 26, 2019 at 02:31:53AM +0000, Martyn Welch wrote:

> The utility dumpimage has error paths that display the usage and others
> that exit without displaying usage. Add an explicit help option to
> dumpimage to display the usage and remove it's use in error paths to make
> the error messages more obvious and errors paths more consistent.
> 
> Signed-off-by: Martyn Welch <martyn.welch@collabora.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index e17e979b04..5c9ad36322 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -65,7 +65,7 @@  int main(int argc, char **argv)
 
 	params.cmdname = *argv;
 
-	while ((opt = getopt(argc, argv, "lo:T:p:V")) != -1) {
+	while ((opt = getopt(argc, argv, "hlo:T:p:V")) != -1) {
 		switch (opt) {
 		case 'l':
 			params.lflag = 1;
@@ -79,7 +79,7 @@  int main(int argc, char **argv)
 			if (params.type < 0) {
 				fprintf(stderr, "%s: Invalid type\n",
 					params.cmdname);
-				usage();
+				exit(EXIT_FAILURE);
 			}
 			break;
 		case 'p':
@@ -94,15 +94,20 @@  int main(int argc, char **argv)
 		case 'V':
 			printf("dumpimage version %s\n", PLAIN_VERSION);
 			exit(EXIT_SUCCESS);
+		case 'h':
+			usage();
 		default:
 			usage();
 			break;
 		}
 	}
 
+	if (argc < 2)
+		usage();
+
 	if (optind >= argc) {
 		fprintf(stderr, "%s: image file missing\n", params.cmdname);
-		usage();
+		exit(EXIT_FAILURE);
 	}
 
 	params.imagefile = argv[optind];
@@ -123,7 +128,7 @@  int main(int argc, char **argv)
 		if (tparams->check_params(&params)) {
 			fprintf(stderr, "%s: Parameter check failed\n",
 				params.cmdname);
-			usage();
+			exit(EXIT_FAILURE);
 		}
 	}
 
@@ -195,9 +200,12 @@  static void usage(void)
 		"          -T ==> set image type to 'type'\n"
 		"          -p ==> 'position' (starting at 0) of the component to extract from image\n",
 		params.cmdname);
+	fprintf(stderr,
+		"       %s -h ==> print usage information and exit\n",
+		params.cmdname);
 	fprintf(stderr,
 		"       %s -V ==> print version information and exit\n",
 		params.cmdname);
 
-	exit(EXIT_FAILURE);
+	exit(EXIT_SUCCESS);
 }