Commit 65a80b43b308bfae0b732765f75c25e5f65b9d84

Authored by Martyn Welch
Committed by Tom Rini
1 parent 11e3c1fd3b

tools: dumpimage: Add help option and make error paths consistent

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>

Showing 1 changed file with 13 additions and 5 deletions Side-by-side Diff

... ... @@ -65,7 +65,7 @@
65 65  
66 66 params.cmdname = *argv;
67 67  
68   - while ((opt = getopt(argc, argv, "lo:T:p:V")) != -1) {
  68 + while ((opt = getopt(argc, argv, "hlo:T:p:V")) != -1) {
69 69 switch (opt) {
70 70 case 'l':
71 71 params.lflag = 1;
... ... @@ -79,7 +79,7 @@
79 79 if (params.type < 0) {
80 80 fprintf(stderr, "%s: Invalid type\n",
81 81 params.cmdname);
82   - usage();
  82 + exit(EXIT_FAILURE);
83 83 }
84 84 break;
85 85 case 'p':
86 86  
87 87  
... ... @@ -94,15 +94,20 @@
94 94 case 'V':
95 95 printf("dumpimage version %s\n", PLAIN_VERSION);
96 96 exit(EXIT_SUCCESS);
  97 + case 'h':
  98 + usage();
97 99 default:
98 100 usage();
99 101 break;
100 102 }
101 103 }
102 104  
  105 + if (argc < 2)
  106 + usage();
  107 +
103 108 if (optind >= argc) {
104 109 fprintf(stderr, "%s: image file missing\n", params.cmdname);
105   - usage();
  110 + exit(EXIT_FAILURE);
106 111 }
107 112  
108 113 params.imagefile = argv[optind];
... ... @@ -123,7 +128,7 @@
123 128 if (tparams->check_params(&params)) {
124 129 fprintf(stderr, "%s: Parameter check failed\n",
125 130 params.cmdname);
126   - usage();
  131 + exit(EXIT_FAILURE);
127 132 }
128 133 }
129 134  
130 135  
... ... @@ -196,9 +201,12 @@
196 201 " -p ==> 'position' (starting at 0) of the component to extract from image\n",
197 202 params.cmdname);
198 203 fprintf(stderr,
  204 + " %s -h ==> print usage information and exit\n",
  205 + params.cmdname);
  206 + fprintf(stderr,
199 207 " %s -V ==> print version information and exit\n",
200 208 params.cmdname);
201 209  
202   - exit(EXIT_FAILURE);
  210 + exit(EXIT_SUCCESS);
203 211 }