Krolyxon
Commit 85fffbb

Branches

Refs →

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
Author
NRK
Date
2022-09-28 18:15 +0200
Parent
daee344
Commit
85fffbb277418dfc5e03fc8e01335553333d8049

+7 −7

1 file changed

  1. M options.c +7 −7
M options.c View
@@ -150,7 +150,7 @@ void parse_options(int argc, char **argv)
150150 case 'A':
151151 n = strtol(op.optarg, &end, 0);
152152 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);
154154 _options.framerate = n;
155155 /* fall through */
156156 case 'a':
@@ -165,7 +165,7 @@ void parse_options(int argc, char **argv)
165165 case 'e':
166166 n = strtol(op.optarg, &end, 0);
167167 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);
169169 _options.embed = n;
170170 break;
171171 case 'f':
@@ -174,7 +174,7 @@ void parse_options(int argc, char **argv)
174174 case 'G':
175175 n = strtol(op.optarg, &end, 0);
176176 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);
178178 _options.gamma = n;
179179 break;
180180 case 'g':
@@ -189,7 +189,7 @@ void parse_options(int argc, char **argv)
189189 case 'n':
190190 n = strtol(op.optarg, &end, 0);
191191 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);
193193 _options.startnum = n - 1;
194194 break;
195195 case 'N':
@@ -210,13 +210,13 @@ void parse_options(int argc, char **argv)
210210 case 'S':
211211 f = strtof(op.optarg, &end) * 10.0f;
212212 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);
214214 _options.slideshow = (unsigned int)f;
215215 break;
216216 case 's':
217217 s = strchr(scalemodes, op.optarg[0]);
218218 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);
220220 _options.scalemode = s - scalemodes;
221221 break;
222222 case 'T':
@@ -235,7 +235,7 @@ void parse_options(int argc, char **argv)
235235 case 'z':
236236 n = strtol(op.optarg, &end, 0);
237237 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);
239239 _options.scalemode = SCALE_ZOOM;
240240 _options.zoom = (float) n / 100.0f;
241241 break;