Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions PoshBot/Classes/Command.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Command : BaseLogger {
[bool]$AsJob = $true

# Fully qualified name of a cmdlet or function in a module to execute
[string]$ModuleCommand
[string]$ModuleQualifiedCommand

[string]$ManifestPath

Expand Down Expand Up @@ -81,7 +81,6 @@ class Command : BaseLogger {

Import-Module -Name $Options.ManifestPath -Scope Local -Force -Verbose:$false -WarningAction SilentlyContinue

$cmd = $Options.Function
$namedParameters = $Options.NamedParameters
$positionalParameters = $Options.PositionalParameters

Expand All @@ -101,7 +100,7 @@ class Command : BaseLogger {
BackendType = $options.BackendType
}

& $cmd @namedParameters @positionalParameters
& $Options.ModuleQualifiedCommand @namedParameters @positionalParameters
}

[string]$sb = [string]::Empty
Expand All @@ -113,21 +112,20 @@ class Command : BaseLogger {
ConfigurationDirectory = $script:ConfigurationDirectory
BackendType = $Backend
PoshBotManifestPath = (Join-Path -Path $script:moduleBase -ChildPath "PoshBot.psd1")
ModuleQualifiedCommand = $this.ModuleQualifiedCommand
}
if ($this.FunctionInfo) {
$options.Function = $this.FunctionInfo
$fqCommand = "$($this.FunctionInfo.Module.name)\$($this.FunctionInfo.name)"
} elseIf ($this.CmdletInfo) {
$options.Function = $this.CmdletInfo
$fqCommand = "$($this.CmdletInfo.Module.name)\$($this.CmdletInfo.name)"
}

# Add named/positional parameters
$options.NamedParameters = $ParsedCommand.NamedParameters
$options.PositionalParameters = $ParsedCommand.PositionalParameters

if ($InvokeAsJob) {
$this.LogDebug("Executing command [$fqCommand] as job")
$this.LogDebug("Executing command [$($this.ModuleQualifiedCommand)] as job")
$fdt = Get-Date -Format FileDateTimeUniversal
$jobName = "$($this.Name)_$fdt"
$jobParams = @{
Expand All @@ -137,7 +135,7 @@ class Command : BaseLogger {
}
return (Start-Job @jobParams)
} else {
$this.LogDebug("Executing command [$fqCommand] in current PS session")
$this.LogDebug("Executing command [$($this.ModuleQualifiedCommand)] in current PS session")
$errors = $null
$information = $null
$warning = $null
Expand Down
10 changes: 0 additions & 10 deletions PoshBot/Classes/Plugin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ class PluginDisabled : PluginException {
PluginDisabled([string]$Message) : base($Message) {}
}

# Represents a fully qualified module command
class ModuleCommand {
[string]$Module
[string]$Command

[string]ToString() {
return "$($this.Module)\$($this.Command)"
}
}

class Plugin : BaseLogger {

# Unique name for the plugin
Expand Down
34 changes: 16 additions & 18 deletions PoshBot/Classes/PluginManager.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,10 @@ class PluginManager : BaseLogger {

# Get exported cmdlets/functions from the module and add them to the plugin
# Adjust bot command behaviour based on metadata as appropriate
Import-Module -Name $manifestPath -Scope Local -Verbose:$false -WarningAction SilentlyContinue -Force
Import-Module -Name $ManifestPath -Scope Local -Verbose:$false -WarningAction SilentlyContinue -Force
$moduleCommands = Microsoft.PowerShell.Core\Get-Command -Module $ModuleName -CommandType @('Cmdlet', 'Function') -Verbose:$false
foreach ($command in $moduleCommands) {

# Get the command help so we can pull information from it
# to construct the bot command
$cmdHelp = Get-Help -Name "$ModuleName\$($command.Name)" -ErrorAction SilentlyContinue

# Get any command metadata that may be attached to the command
# via the PoshBot.BotCommand extended attribute
# NOTE: This only works on functions, not cmdlets
Expand All @@ -482,9 +478,18 @@ class PluginManager : BaseLogger {
}

$this.LogVerbose("Creating command [$($command.Name)] for new plugin [$($plugin.Name)]")
$cmd = [Command]::new()
$cmd.Logger = $this.Logger
$cmd.Name = $command.Name
$cmd = [Command]::new()
$cmd.Name = $command.Name
$cmd.ModuleQualifiedCommand = "$ModuleName\$($command.Name)"
$cmd.ManifestPath = $ManifestPath
$cmd.Logger = $this.Logger
$cmd.AsJob = $AsJob

if ($command.CommandType -eq 'Function') {
$cmd.FunctionInfo = $command
} elseIf ($command.CommandType -eq 'Cmdlet') {
$cmd.CmdletInfo = $command
}

# Triggers that will be added to the command
$triggers = @()
Expand Down Expand Up @@ -578,16 +583,12 @@ class PluginManager : BaseLogger {
$triggers += [Trigger]::new([TriggerType]::Command, $cmd.Name)
}

# Get the command help so we can pull information from it
# to construct the bot command
$cmdHelp = Get-Help -Name $cmd.ModuleQualifiedCommand -ErrorAction SilentlyContinue
if ($cmdHelp) {
$cmd.Description = $cmdHelp.Synopsis.Trim()
}
$cmd.ManifestPath = $manifestPath

if ($command.CommandType -eq 'Function') {
$cmd.FunctionInfo = $command
} elseIf ($command.CommandType -eq 'Cmdlet') {
$cmd.CmdletInfo = $command
}

# Set the command usage differently for [Command] and [Regex] trigger types
if ($cmd.TriggerType -eq [TriggerType]::Command) {
Expand Down Expand Up @@ -615,9 +616,6 @@ class PluginManager : BaseLogger {
# Add triggers based on command type and metadata
$cmd.Triggers += $triggers

$cmd.ModuleCommand = "$ModuleName\$($command.Name)"
$cmd.AsJob = $AsJob

$plugin.AddCommand($cmd)
}

Expand Down
2 changes: 1 addition & 1 deletion PoshBot/Plugins/Builtin/Public/Get-CommandHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function Get-CommandHelp {
}
if ($HelpParams.Keys.Count -gt 0) {
$fullVersionName = "$($result.FullCommandName)`:$($result.Version)"
$manString = Get-Help $Bot.PluginManager.Commands[$fullVersionName].ModuleCommand @HelpParams | Out-String
$manString = Get-Help $Bot.PluginManager.Commands[$fullVersionName].ModuleQualifiedCommand @HelpParams | Out-String
$result | Add-Member -MemberType NoteProperty -Name Manual -Value "`n$manString"
}
$respParams.Text = ($result | Format-List | Out-String -Width 150).Trim()
Expand Down