Use module-qualified cmdlet names when invoking plugins#129
Use module-qualified cmdlet names when invoking plugins#129devblackops merged 2 commits intoposhbotio:masterfrom
Conversation
|
Good idea @Tadas. Thanks! |
|
@Tadas I'm trying to repro your issue but can't get the problem to occur. This is what I'm trying: function Start {
[cmdletbinding()]
param()
'Start your engines'
}or function Start-Engine {
[PoshBot.BotCommand(
CommandName = 'start'
)]
[cmdletbinding()]
param()
'Start your engines'
}or function Start-Engine {
[PoshBot.BotCommand(
Aliases = 'start'
)]
[cmdletbinding()]
param()
'Start your engines'
}All of these seem to work fine. What does your plugin command look like that triggers this? |
|
It can only happen when you have an alias defined Only your first example triggers the bug, that function is pretty much identical to what I have. |
|
Sorry still can't repro this, and I'm not sure why you're getting a problem either. 🤷♂️ PoshBot is already executing the actual command from the module, not the module-qualified name, but the actual function/cmdlet object returned from When it loads the module, it gets all the module's public commands via Get-Command here. It never executes the command by name only which I can see would cause a problem with aliases of the same name. Below is effectively what PoshBot does and even though I've added an alias for New-Alias -Name start -Value Start-Process
$c = Get-Command -Module PoshBot.PSSummit -Name start
& $cI'd like to understand more about how you're running into this. |
|
Ok I think we're running into serialization nuances. Is your plugin begin executed as job? Just before PoshBot/PoshBot/Classes/Command.ps1 Lines 133 to 138 in 5cadba8 and inside of the job: |
|
Ahh. That makes sense. I'm OK with this change to use the module qualified name. |
Description
I wanted to use
startcmdlet name in a plugin but discovered that command execution jobs never finish executing. Turns out thatstartwas being resolved asStart-Processby PowerShell. PoshBot should use module-qualified cmdlet names when invoking plugin commands to ensure that the right cmdlet is called regardless of aliases.https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_command_precedence?view=powershell-6#qualified-names
Related Issue
Motivation and Context
Enables usage of cmdlet names in plugins which might be hidden by an alias e.g.
start(a default alias forStart-Process)How Has This Been Tested?
Types of changes
Checklist: