Feature request: Parameters for scripts

There seem to be a lot of scripts that do all sorts of wonderful stuff, and yet, it’s stuff that could theoretically be used as part of a bigger process. Distribution and usage can be tricky for people who haven’t tried any kind of scripting before.

I think both of these problems could be reduced if scripts are allowed to take arbitrary parameters (explicitly declared?) as input. That way, instead of forcing users to tamper with global variables or edit hardcoded strings, a script author could provide parameters as entry points, so that users could just copy&paste&run without being skilled in scripting.

How exactly could this go (syntax wise)? Perhaps the “/system script add” command could take a new “params” argument that will be comma separated list of allowed parameters. Within the script, these parameters will be avaiable as local variables (populated to nil if no value is set at run time?), and from the terminal itself, a user would be able to use “/system script run myScriptName param1=value1 param2=value2” to populate the parameters.

Ideally, there could also be a “paramHelp” argument that would be a comma separated list of parameter summaries, and a “help” command so that users could do “/system script help nameOfMyScript” and view a “?” like description when in terminal.

As a simpler alternative (although dirtier), there could be a single variable that users could populate at run time, and given that the could be an array, script authors could :pick all the information they need out of this one variable. I’m guessing this would be easier to implement.

That change, combined with some cultural shift to make people distribute files (that would then be “installed” with ‘/import file=“nameOfMyScript.rsc”’) instead of text pieces would make scripts a first class citizens of what it is to work with MikroTik… right now, most (public?) scripts seem to act as ditry patches, and nothing more.

+1 This is one of the biggest limitations with the current script model, everything has to be passed through globals which is just crazy.

While this does not completely fit your requirements, it does provide a means for local-scoped arguments in RouterOS scripts, simulating function-like capability.

http://forum.mikrotik.com/t/functions-in-cmd-scripts/34902/1