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

Allow multiple +c and ++cmd command line options.

This commit is contained in:
Doug Kearns
2009-08-19 02:27:31 +10:00
parent e10bde5c0f
commit cc187d8372
4 changed files with 42 additions and 11 deletions

View File

@@ -585,13 +585,27 @@ function Commands() //{{{
* @param {string} str The Ex command-line string to parse. E.g. * @param {string} str The Ex command-line string to parse. E.g.
* "-x=foo -opt=bar arg1 arg2" * "-x=foo -opt=bar arg1 arg2"
* @param {Array} options The options accepted. These are specified as * @param {Array} options The options accepted. These are specified as
* an array [name, type, validator, completions]. E.g. * an array [names, type, validator, completions, multiple].
* names - an array of option names. The first name is the
* canonical option name.
* type - the option's value type. This is one of:
* (@link Commands#OPTION_NOARG),
* (@link Commands#OPTION_STRING),
* (@link Commands#OPTION_BOOL),
* (@link Commands#OPTION_INT),
* (@link Commands#OPTION_FLOAT),
* (@link Commands#OPTION_LIST),
* (@link Commands#OPTION_ANY)
* validator - a validator function
* completer - a list of completions, or a completion function
* multiple - whether this option can be specified multiple times
* E.g.
* options = [[["-force"], OPTION_NOARG], * options = [[["-force"], OPTION_NOARG],
* [["-fullscreen", "-f"], OPTION_BOOL], * [["-fullscreen", "-f"], OPTION_BOOL],
* [["-language"], OPTION_STRING, validateFunc, ["perl", "ruby"]], * [["-language"], OPTION_STRING, validateFunc, ["perl", "ruby"]],
* [["-speed"], OPTION_INT], * [["-speed"], OPTION_INT],
* [["-acceleration"], OPTION_FLOAT], * [["-acceleration"], OPTION_FLOAT],
* [["-accessories"], OPTION_LIST, null, ["foo", "bar"]], * [["-accessories"], OPTION_LIST, null, ["foo", "bar"], true],
* [["-other"], OPTION_ANY]]; * [["-other"], OPTION_ANY]];
* @param {string} argCount The number of arguments accepted. * @param {string} argCount The number of arguments accepted.
* "0": no arguments * "0": no arguments
@@ -769,7 +783,12 @@ function Commands() //{{{
} }
} }
args[opt[0][0]] = opt[1] == this.OPTION_NOARG || arg; // always use the first name of the option // option allowed multiple times
if (!!opt[4])
args[opt[0][0]] = (args[opt[0][0]] || []).concat(arg);
else
args[opt[0][0]] = opt[1] == this.OPTION_NOARG || arg;
i += optname.length + count; i += optname.length + count;
if (i == str.length) if (i == str.length)
break outer; break outer;

View File

@@ -1692,8 +1692,8 @@ const liberator = (function () //{{{
const options = [ const options = [
[["+u"], commands.OPTIONS_STRING], [["+u"], commands.OPTIONS_STRING],
[["++noplugin"], commands.OPTIONS_NOARG], [["++noplugin"], commands.OPTIONS_NOARG],
[["++cmd"], commands.OPTIONS_STRING], [["++cmd"], commands.OPTIONS_STRING, null, null, true],
[["+c"], commands.OPTIONS_STRING] [["+c"], commands.OPTIONS_STRING, null, null, true]
]; ];
return commands.parseArgs(cmdline, options, "*"); return commands.parseArgs(cmdline, options, "*");
}, },
@@ -1746,8 +1746,8 @@ const liberator = (function () //{{{
let args = liberator.parseCommandLine(commandline); let args = liberator.parseCommandLine(commandline);
liberator.commandLineOptions.rcFile = args["+u"]; liberator.commandLineOptions.rcFile = args["+u"];
liberator.commandLineOptions.noPlugins = "++noplugin" in args; liberator.commandLineOptions.noPlugins = "++noplugin" in args;
liberator.commandLineOptions.postCommand = args["+c"]; liberator.commandLineOptions.postCommands = args["+c"];
liberator.commandLineOptions.preCommand = args["++cmd"]; liberator.commandLineOptions.preCommands = args["++cmd"];
liberator.dump("Processing command-line option: " + commandline); liberator.dump("Processing command-line option: " + commandline);
} }
@@ -1769,8 +1769,10 @@ const liberator = (function () //{{{
// TODO: we should have some class where all this guioptions stuff fits well // TODO: we should have some class where all this guioptions stuff fits well
hideGUI(); hideGUI();
if (liberator.commandLineOptions.preCommand) if (liberator.commandLineOptions.preCommands)
liberator.execute(liberator.commandLineOptions.preCommand); liberator.commandLineOptions.preCommands.forEach(function (cmd) {
liberator.execute(cmd);
});
// finally, read the RC file and source plugins // finally, read the RC file and source plugins
// make sourcing asynchronous, otherwise commands that open new tabs won't work // make sourcing asynchronous, otherwise commands that open new tabs won't work
@@ -1827,8 +1829,10 @@ const liberator = (function () //{{{
option.value = option.value; option.value = option.value;
} }
if (liberator.commandLineOptions.postCommand) if (liberator.commandLineOptions.postCommands)
liberator.execute(liberator.commandLineOptions.postCommand); liberator.commandLineOptions.postCommands.forEach(function (cmd) {
liberator.execute(cmd);
});
liberator.triggerObserver("enter", null); liberator.triggerObserver("enter", null);
autocommands.trigger(config.name + "Enter", {}); autocommands.trigger(config.name + "Enter", {});

View File

@@ -11,6 +11,8 @@ E.g firefox -liberator "$$++cmd='set exrc' +u='tempRcFile' ++noplugin$$"
________________________________________________________________________________ ________________________________________________________________________________
Execute a single Ex command after all initialization has been performed. See Execute a single Ex command after all initialization has been performed. See
[j]initialization[j]. [j]initialization[j].
This option can be specified multiple times.
________________________________________________________________________________ ________________________________________________________________________________
@@ -19,6 +21,8 @@ ________________________________________________________________________________
________________________________________________________________________________ ________________________________________________________________________________
Execute a single Ex command before any initialization has been performed. See Execute a single Ex command before any initialization has been performed. See
[j]initialization[j]. [j]initialization[j].
This option can be specified multiple times.
________________________________________________________________________________ ________________________________________________________________________________

View File

@@ -11,6 +11,8 @@ E.g firefox -liberator "$$++cmd='set exrc' +u='tempRcFile' ++noplugin$$"
________________________________________________________________________________ ________________________________________________________________________________
Execute a single Ex command after all initialization has been performed. See Execute a single Ex command after all initialization has been performed. See
[j]initialization[j]. [j]initialization[j].
This option can be specified multiple times.
________________________________________________________________________________ ________________________________________________________________________________
@@ -19,6 +21,8 @@ ________________________________________________________________________________
________________________________________________________________________________ ________________________________________________________________________________
Execute a single Ex command before any initialization has been performed. See Execute a single Ex command before any initialization has been performed. See
[j]initialization[j]. [j]initialization[j].
This option can be specified multiple times.
________________________________________________________________________________ ________________________________________________________________________________