Thank you for your response Marco. The ProxyCommand class makes it much easier to write proxies.
I don't know if this is the best place to put this, but I would like to see a more dynamic way of making a proxies. The ProxyCommand approach basically amounts to the same workaround I mentioned -- writing a new function which explicitly re-declares all the same parameters as the wrapped function, except for possibly omitting or adding some parameters. The ProxyCommand::create method just generates the initial source code for you to work with. While this certainly removes one of the disadvantages of a hand-written wrapper, having to hand-write the parameter re-declarations, it still has the other disadvantages:
- The generated code obscures the actual content of the wrapper. There might be dozens of lines of generated wrapper code, and one or two lines of code I actually wrote in there somewhere.
- Since the parameter re-declarations are hard-coded in the wrapper, if the wrapped command is ever modified such that its parameters are changed, then the wrapper becomes out of date and needs to be updated.
What I would like to see is something like the existing DynamicParameter feature, but extended to support dynamically adding an arbitrary number of parameters. So for example, here is how I might write Select-StringCS:
# A wrapper around Select-String which does case-sensitive matching
function Select-StringCS {
# add all parameters of Select-String except for -CaseSensitive as parameters of this function
DynamicParameters {
$meta = New-Object System.Management.Automation.CommandMetaData (gcm Select-String)
$params = $meta.Parameters
[void] $params.Remove('CaseSensitive')
$params
}
@PSBoundParameters['CaseSensitive'] = $true
Select-String @PSBoundParameters
}
Since DynamicParameter already exists in Powershell, it seems to me that adding the plural of it shouldn't be too hard, and that this would provide a much neater way of doing this sort of meta-programming. If there is a better place for me to send this suggestion, please let me know. And thanks again for pointing me to the ProxyCommand functionality.