1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 07:18:00 +01:00

allow -option foo in adition to -option=foo

This commit is contained in:
Martin Stubenschrott
2007-10-18 18:30:08 +00:00
parent 177a191940
commit 66c640578a

View File

@@ -271,8 +271,9 @@ function Commands() //{{{
if (!options) if (!options)
options = []; options = [];
var invalid = false;
var arg = null; var arg = null;
var count = 0; var count = 0; // the length of the argument
var i = 0; var i = 0;
outer: outer:
while(i < str.length) while(i < str.length)
@@ -293,11 +294,11 @@ function Commands() //{{{
optname = options[opt][0][name]; optname = options[opt][0][name];
if (sub.indexOf(optname) == 0) if (sub.indexOf(optname) == 0)
{ {
var invalid = false; invalid = false;
// no value to the option
if (optname.length >= sub.length || /\s/.test(sub[optname.length]))
{
arg = null; arg = null;
// no value to the option
if (optname.length >= sub.length)
{
count = 0; count = 0;
} }
else if (sub[optname.length] == "=") else if (sub[optname.length] == "=")
@@ -308,6 +309,18 @@ function Commands() //{{{
count++; // to compensate the "=" character count++; // to compensate the "=" character
} }
else if (options[opt][1] != OPTION_NOARG && /\s/.test(sub[optname.length]))
{
[count, arg] = getNextArg(sub.substr(optname.length + 1));
if (count == -1)
return { error: "Invalid argument for option " + optname, opts: [], args: [] }
// if we add the argument to an option after a space, it MUST not be empty
if (arg.length == 0)
arg = null;
count++; // to compensate the " " character
}
else else
{ {
// this isn't really an option as it has trailing characters, parse it as an argument // this isn't really an option as it has trailing characters, parse it as an argument