nsxiv85fffbb
improve error message on bad cli argument (#371)
currently the error messages have the shortopt hardcoded in them, even when the user actually entered a longopt: $ ./nsxiv --framerate v nsxiv: Invalid argument for option -A: v and as far as I see, there's no way to *reliably* tell weather we're processing a longopt or a shortopt. perhaps we can do some shenanigangs with `optind` but that seems finicky at best. and it seems like other coreutils which support longopt has similar issues: $ xargs --max-procs=z xargs: invalid number "z" for -P option utils like `grep` and `head` seems to work-around it by not mentioning the flag: $ head --lines=z head: invalid number of lines: ‘z’ $ grep --max-count=l grep: invalid max count this patch does the same thing as `grep/head` and omits the flag from the error message. Closes: https://codeberg.org/nsxiv/nsxiv/issues/368
+7 −7
1 file changed
- M options.c +7 −7
| @@ -150,7 +150,7 @@ void parse_options(int argc, char **argv) | |||
| 150 | 150 | case 'A': | |
| 151 | 151 | n = strtol(op.optarg, &end, 0); | |
| 152 | 152 | if (*end != '\0' || n <= 0 || n > INT_MAX) | |
| 153 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", op.optarg); | |
| 153 | + | error(EXIT_FAILURE, 0, "Invalid framerate: %s", op.optarg); | |
| 154 | 154 | _options.framerate = n; | |
| 155 | 155 | /* fall through */ | |
| 156 | 156 | case 'a': | |
| @@ -165,7 +165,7 @@ void parse_options(int argc, char **argv) | |||
| 165 | 165 | case 'e': | |
| 166 | 166 | n = strtol(op.optarg, &end, 0); | |
| 167 | 167 | if (*end != '\0') | |
| 168 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", op.optarg); | |
| 168 | + | error(EXIT_FAILURE, 0, "Invalid window id: %s", op.optarg); | |
| 169 | 169 | _options.embed = n; | |
| 170 | 170 | break; | |
| 171 | 171 | case 'f': | |
| @@ -174,7 +174,7 @@ void parse_options(int argc, char **argv) | |||
| 174 | 174 | case 'G': | |
| 175 | 175 | n = strtol(op.optarg, &end, 0); | |
| 176 | 176 | if (*end != '\0' || n < INT_MIN || n > INT_MAX) | |
| 177 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", op.optarg); | |
| 177 | + | error(EXIT_FAILURE, 0, "Invalid gamma: %s", op.optarg); | |
| 178 | 178 | _options.gamma = n; | |
| 179 | 179 | break; | |
| 180 | 180 | case 'g': | |
| @@ -189,7 +189,7 @@ void parse_options(int argc, char **argv) | |||
| 189 | 189 | case 'n': | |
| 190 | 190 | n = strtol(op.optarg, &end, 0); | |
| 191 | 191 | if (*end != '\0' || n <= 0 || n > INT_MAX) | |
| 192 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", op.optarg); | |
| 192 | + | error(EXIT_FAILURE, 0, "Invalid starting number: %s", op.optarg); | |
| 193 | 193 | _options.startnum = n - 1; | |
| 194 | 194 | break; | |
| 195 | 195 | case 'N': | |
| @@ -210,13 +210,13 @@ void parse_options(int argc, char **argv) | |||
| 210 | 210 | case 'S': | |
| 211 | 211 | f = strtof(op.optarg, &end) * 10.0f; | |
| 212 | 212 | if (*end != '\0' || f <= 0 || f >= (float)UINT_MAX) | |
| 213 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", op.optarg); | |
| 213 | + | error(EXIT_FAILURE, 0, "Invalid slideshow delay: %s", op.optarg); | |
| 214 | 214 | _options.slideshow = (unsigned int)f; | |
| 215 | 215 | break; | |
| 216 | 216 | case 's': | |
| 217 | 217 | s = strchr(scalemodes, op.optarg[0]); | |
| 218 | 218 | if (s == NULL || *s == '\0' || strlen(op.optarg) != 1) | |
| 219 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", op.optarg); | |
| 219 | + | error(EXIT_FAILURE, 0, "Invalid scale mode: %s", op.optarg); | |
| 220 | 220 | _options.scalemode = s - scalemodes; | |
| 221 | 221 | break; | |
| 222 | 222 | case 'T': | |
| @@ -235,7 +235,7 @@ void parse_options(int argc, char **argv) | |||
| 235 | 235 | case 'z': | |
| 236 | 236 | n = strtol(op.optarg, &end, 0); | |
| 237 | 237 | if (*end != '\0' || n <= 0) | |
| 238 | − | error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", op.optarg); | |
| 238 | + | error(EXIT_FAILURE, 0, "Invalid zoom level: %s", op.optarg); | |
| 239 | 239 | _options.scalemode = SCALE_ZOOM; | |
| 240 | 240 | _options.zoom = (float) n / 100.0f; | |
| 241 | 241 | break; | |