From cc187d83722b0d733f18f511b293067ae29fe8e6 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Wed, 19 Aug 2009 02:27:31 +1000 Subject: [PATCH] Allow multiple +c and ++cmd command line options. --- common/content/commands.js | 25 ++++++++++++++++++++++--- common/content/liberator.js | 20 ++++++++++++-------- vimperator/locale/en-US/starting.txt | 4 ++++ xulmus/locale/en-US/starting.txt | 4 ++++ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/common/content/commands.js b/common/content/commands.js index 48be9206..e9ffeaa3 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -585,13 +585,27 @@ function Commands() //{{{ * @param {string} str The Ex command-line string to parse. E.g. * "-x=foo -opt=bar arg1 arg2" * @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], * [["-fullscreen", "-f"], OPTION_BOOL], * [["-language"], OPTION_STRING, validateFunc, ["perl", "ruby"]], * [["-speed"], OPTION_INT], * [["-acceleration"], OPTION_FLOAT], - * [["-accessories"], OPTION_LIST, null, ["foo", "bar"]], + * [["-accessories"], OPTION_LIST, null, ["foo", "bar"], true], * [["-other"], OPTION_ANY]]; * @param {string} argCount The number of arguments accepted. * "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; if (i == str.length) break outer; diff --git a/common/content/liberator.js b/common/content/liberator.js index 2d88640c..902c41b9 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1692,8 +1692,8 @@ const liberator = (function () //{{{ const options = [ [["+u"], commands.OPTIONS_STRING], [["++noplugin"], commands.OPTIONS_NOARG], - [["++cmd"], commands.OPTIONS_STRING], - [["+c"], commands.OPTIONS_STRING] + [["++cmd"], commands.OPTIONS_STRING, null, null, true], + [["+c"], commands.OPTIONS_STRING, null, null, true] ]; return commands.parseArgs(cmdline, options, "*"); }, @@ -1746,8 +1746,8 @@ const liberator = (function () //{{{ let args = liberator.parseCommandLine(commandline); liberator.commandLineOptions.rcFile = args["+u"]; liberator.commandLineOptions.noPlugins = "++noplugin" in args; - liberator.commandLineOptions.postCommand = args["+c"]; - liberator.commandLineOptions.preCommand = args["++cmd"]; + liberator.commandLineOptions.postCommands = args["+c"]; + liberator.commandLineOptions.preCommands = args["++cmd"]; 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 hideGUI(); - if (liberator.commandLineOptions.preCommand) - liberator.execute(liberator.commandLineOptions.preCommand); + if (liberator.commandLineOptions.preCommands) + liberator.commandLineOptions.preCommands.forEach(function (cmd) { + liberator.execute(cmd); + }); // finally, read the RC file and source plugins // make sourcing asynchronous, otherwise commands that open new tabs won't work @@ -1827,8 +1829,10 @@ const liberator = (function () //{{{ option.value = option.value; } - if (liberator.commandLineOptions.postCommand) - liberator.execute(liberator.commandLineOptions.postCommand); + if (liberator.commandLineOptions.postCommands) + liberator.commandLineOptions.postCommands.forEach(function (cmd) { + liberator.execute(cmd); + }); liberator.triggerObserver("enter", null); autocommands.trigger(config.name + "Enter", {}); diff --git a/vimperator/locale/en-US/starting.txt b/vimperator/locale/en-US/starting.txt index d437e4b4..5361bb10 100644 --- a/vimperator/locale/en-US/starting.txt +++ b/vimperator/locale/en-US/starting.txt @@ -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 [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 [j]initialization[j]. + +This option can be specified multiple times. ________________________________________________________________________________ diff --git a/xulmus/locale/en-US/starting.txt b/xulmus/locale/en-US/starting.txt index 000b40e0..c4a2e5ba 100644 --- a/xulmus/locale/en-US/starting.txt +++ b/xulmus/locale/en-US/starting.txt @@ -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 [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 [j]initialization[j]. + +This option can be specified multiple times. ________________________________________________________________________________