diff --git a/Commands/Module/Use-Module.ps.ps1 b/Commands/Module/Use-Module.ps.ps1 index 05f5f8c03..743ec8f15 100644 --- a/Commands/Module/Use-Module.ps.ps1 +++ b/Commands/Module/Use-Module.ps.ps1 @@ -6,17 +6,7 @@ function Use-Module .SYNOPSIS Uses a module. .DESCRIPTION - Uses a module. - - This can either: - - * If present, run a module's `Use` function, method, or script property. - * Otherwise, run a script block in the module's context. - - * Run a module's `Use` function, if present - * Call a module's `Use` method, if present - - In all cases, the script block should be run in the module's context, using dot-sourcing. + Uses a module's context to run a `[ScriptBlock]` (with dot-sourcing). .EXAMPLE Get-Module PipeScript | Use-Module -ScriptBlock { $myInvocation.MyCommand.ScriptBlock.Module } #> @@ -61,43 +51,12 @@ function Use-Module Get-Module $Name | Select-Object -First 1 } - # Return if there is no module context. - return if -not $moduleContext - # Get the use commands. - $useCommands = $moduleContent.ExportedCommands[@( - "Use-$($moduleContext.Name)", - "Use.$($moduleContext.Name)" - "$($moduleContext.Name).Use" - )] - - # Get the use method. - $useMethod = $moduleContext.psobject.methods["Use"] - - $ToRun = - # If we have a method - if ($useMethod) - { - $useMethod.Script # use it - # (and pass the script block as an argument) - $ArgumentList = @($ScriptBlock) + @($ArgumentList) - } - # If we have any use commands, use the first one - elseif ($useCommands -ne $null) - { - @($useCommands -ne $null)[0] - # (and pass the script block as an argument) - $ArgumentList = @($ScriptBlock) + @($ArgumentList) - } - else - { - # Otherwise, use the script block - $ScriptBlock - } - - # We're running in the module context, and now we know what we want `$toRun`. + # We're running in the module context, $runningIn = $moduleContext - + # and we want `$toRun` the ScriptBlock. + $ToRun = $ScriptBlock + # The rest of the code is tedium. # If there were arguments and parameters, pass them both with splatting. if ($ArgumentList) {