1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 15:52:29 +01:00

Emit completion messages for arg parser errors.

This commit is contained in:
Kris Maglione
2008-11-28 11:44:58 +00:00
parent 18cf334054
commit ceaa5d913e
2 changed files with 13 additions and 9 deletions

View File

@@ -491,6 +491,14 @@ function Commands() //{{{
args.completeArg = 0; args.completeArg = 0;
} }
function echoerr(error)
{
if (complete)
complete.message = error;
else
liberator.echoerr(error);
}
outer: outer:
while (i < str.length || complete) while (i < str.length || complete)
{ {
@@ -565,30 +573,26 @@ function Commands() //{{{
arg = type.parse(arg); arg = type.parse(arg);
if (arg == null || arg == NaN) if (arg == null || arg == NaN)
{ {
echoerr("Invalid argument for " + type.description + "option: " + optname);
if (complete) if (complete)
complete.highlight(args.completeStart, count - 1, "SPELLCHECK"); complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
else else
{
liberator.echoerr("Invalid argument for " + type.description + "option: " + optname);
return null; return null;
} }
} }
}
// we have a validator function // we have a validator function
if (typeof opt[2] == "function") if (typeof opt[2] == "function")
{ {
if (opt[2].call(this, arg) == false) if (opt[2].call(this, arg) == false)
{ {
echoerr("Invalid argument for option: " + optname);
if (complete) if (complete)
complete.highlight(args.completeStart, count - 1, "SPELLCHECK"); complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
else else
{
liberator.echoerr("Invalid argument for option: " + optname);
return null; return null;
} }
} }
}
args[opt[0][0]] = arg; // always use the first name of the option args[opt[0][0]] = arg; // always use the first name of the option
i += optname.length + count; i += optname.length + count;
@@ -678,8 +682,7 @@ function Commands() //{{{
else if (args.length == 1 && (argCount == "0") || else if (args.length == 1 && (argCount == "0") ||
args.length > 1 && /^[01?]$/.test(argCount)) args.length > 1 && /^[01?]$/.test(argCount))
{ {
if (!complete) echoerr("E488: Trailing characters");
liberator.echoerr("E488: Trailing characters");
return null; return null;
} }

View File

@@ -355,7 +355,8 @@ const liberator = (function () //{{{
commands.add(["loadplugins", "lpl"], commands.add(["loadplugins", "lpl"],
"Load all plugins immediately", "Load all plugins immediately",
function () { liberator.loadPlugins(); }); function () { liberator.loadPlugins(); },
{ argCount: "0" );
commands.add(["norm[al]"], commands.add(["norm[al]"],
"Execute Normal mode commands", "Execute Normal mode commands",