-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use module-qualified cmdlet names when invoking plugins #129
Use module-qualified cmdlet names when invoking plugins #129
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
& $c I'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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
I wanted to use
start
cmdlet name in a plugin but discovered that command execution jobs never finish executing. Turns out thatstart
was being resolved asStart-Process
by 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: