Description: |
The function Tcl_ParseArgsObjv() behaves differently depending on whether the last argument, remObjv, is null or not. In the case of null last argument, it errors out when parses an unrecognized argument. The error message, however, is not on par with other functions like Tcl_GetIndexFromObj(). For example:
C side table:
const Tcl_ArgvInfo argsTable[] = {
{TCL_ARGV_STRING, "-command", NULL , &command, NULL, NULL},
{TCL_ARGV_GENFUNC, "-flush", ParseBool, &flush , NULL, NULL},
{TCL_ARGV_STRING, "-variable", NULL, &variable, NULL, NULL},
{TCL_ARGV_GENFUNC, "-watchunset", ParseBool, &watchunset, NULL, NULL},
TCL_ARGV_TABLE_END
};
Tcl result:
% parseargs -foo asd
unrecognized argument "-foo"
%
Compare, for example, with other standard error messages
% lsort -foo {}
bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, -stride, or -unique
%
Since Tcl_ParseArgsObjv() already provides a way to print a helpful error message with TCL_ARGS_AUTO_HELP (or the corresponding full entry with TCL_ARGV_HELP type), I think it would be better to add this information after the terse 'unrecognized argument "-foo"' error message.
The attached patch implements such change, resulting instead in
% parsewithout -foo asd
unrecognized argument "-foo"
Command-specific options:
-command:
-flush:
-variable:
-watchunset:
%
Note that when remObjv option is not null the function doesn't error out on unrecognized options, copying them out to remObjv instead.
|