Skip to content

Commit 1d8facd

Browse files
Merge pull request #83 from indented-automation/development
Adds Get-PSMDArgumentCompleter
2 parents a8353b1 + efd3709 commit 1d8facd

File tree

2 files changed

+103
-35
lines changed

2 files changed

+103
-35
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
11
@{
2-
2+
33
# Script module or binary module file associated with this manifest
44
RootModule = 'PSModuleDevelopment.psm1'
5-
5+
66
# Version number of this module.
77
ModuleVersion = '2.2.6.51'
8-
8+
99
# ID used to uniquely identify this module
1010
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
11-
11+
1212
# Author of this module
1313
Author = 'Friedrich Weinmann'
14-
14+
1515
# Company or vendor of this module
1616
CompanyName = 'Infernal Associates ltd.'
17-
17+
1818
# Copyright statement for this module
1919
Copyright = '(c) 2016. All rights reserved.'
20-
20+
2121
# Description of the functionality provided by this module
2222
Description = 'A module designed to speed up the development of PowerShell modules'
23-
23+
2424
# Minimum version of the Windows PowerShell engine required by this module
2525
PowerShellVersion = '3.0'
26-
26+
2727
# Name of the Windows PowerShell host required by this module
2828
PowerShellHostName = ''
29-
29+
3030
# Minimum version of the Windows PowerShell host required by this module
3131
PowerShellHostVersion = ''
32-
32+
3333
# Minimum version of the .NET Framework required by this module
3434
DotNetFrameworkVersion = '2.0'
35-
35+
3636
# Minimum version of the common language runtime (CLR) required by this module
3737
CLRVersion = '2.0.50727'
38-
38+
3939
# Processor architecture (None, X86, Amd64, IA64) required by this module
4040
ProcessorArchitecture = 'None'
41-
41+
4242
# Modules that must be imported into the global environment prior to importing
4343
# this module
4444
RequiredModules = @(
4545
@{ ModuleName = 'PSFramework'; ModuleVersion = '0.10.31.176' }
4646
)
47-
47+
4848
# Assemblies that must be loaded prior to importing this module
4949
RequiredAssemblies = @('bin\PSModuleDevelopment.dll')
50-
50+
5151
# Script files (.ps1) that are run in the caller's environment prior to
5252
# importing this module
5353
ScriptsToProcess = @()
54-
54+
5555
# Type files (.ps1xml) to be loaded when importing this module
5656
TypesToProcess = @('xml\PSModuleDevelopment.Types.ps1xml')
57-
57+
5858
# Format files (.ps1xml) to be loaded when importing this module
5959
FormatsToProcess = @('xml\PSModuleDevelopment.Format.ps1xml')
60-
60+
6161
# Modules to import as nested modules of the module specified in
6262
# ModuleToProcess
6363
NestedModules = @()
64-
64+
6565
# Functions to export from this module
6666
FunctionsToExport = @(
6767
'Expand-PSMDTypeName',
6868
'Find-PSMDFileContent',
6969
'Find-PSMDType',
7070
'Format-PSMDParameter',
71+
'Get-PSMDArgumentCompleter',
7172
'Get-PSMDAssembly',
7273
'Get-PSMDConstructor',
7374
'Get-PSMDHelpEx',
@@ -98,13 +99,13 @@
9899
'Show-PSMDSyntax',
99100
'Split-PSMDScriptFile'
100101
)
101-
102+
102103
# Cmdlets to export from this module
103-
CmdletsToExport = ''
104-
104+
CmdletsToExport = ''
105+
105106
# Variables to export from this module
106107
VariablesToExport = ''
107-
108+
108109
# Aliases to export from this module
109110
AliasesToExport = @(
110111
'dotnetnew',
@@ -117,36 +118,36 @@
117118
'rss',
118119
'smd'
119120
)
120-
121+
121122
# List of all modules packaged with this module
122123
ModuleList = @()
123-
124+
124125
# List of all files packaged with this module
125126
FileList = @()
126-
127+
127128
# Private data to pass to the module specified in ModuleToProcess
128129
PrivateData = @{
129-
130+
130131
#Support for PowerShellGet galleries.
131132
PSData = @{
132-
133+
133134
# Tags applied to this module. These help with module discovery in online galleries.
134135
Tags = @('Development', 'Module')
135-
136+
136137
# A URL to the license for this module.
137138
# LicenseUri = ''
138-
139+
139140
# A URL to the main website for this project.
140141
ProjectUri = 'http://psframework.org'
141-
142+
142143
# A URL to an icon representing this module.
143144
# IconUri = ''
144-
145+
145146
# ReleaseNotes of this module
146147
# ReleaseNotes = ''
147-
148+
148149
} # End of PSData hashtable
149-
150+
150151
} # End of PrivateData hashtable
151152
}
152153

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function Get-PSMDArgumentCompleter
2+
{
3+
<#
4+
.SYNOPSIS
5+
Gets the registered argument completers.
6+
7+
.DESCRIPTION
8+
This function can be used to serach the argument completers registered using either the Register-ArgumentCompleter command or created using the ArgumentCompleter attribute.
9+
10+
.PARAMETER CommandName
11+
Filter the results to a specific command. Wildcards are supported.
12+
13+
.PARAMETER ParameterName
14+
Filter results to a specific parameter name. Wildcards are supported.
15+
16+
.EXAMPLE
17+
PS C:\> Get-PSMDArgumentCompleter
18+
19+
Get all argument completers in use in the current PowerShell session.
20+
21+
#>
22+
[CmdletBinding()]
23+
Param (
24+
[Parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName)]
25+
[Alias('Name')]
26+
[String]
27+
$CommandName = '*',
28+
29+
[String]
30+
$ParameterName = '*'
31+
)
32+
33+
begin
34+
{
35+
$internalExecutionContext = [PSFramework.Utility.UtilityHost]::GetExecutionContextFromTLS()
36+
$customArgumentCompletersProperty = $internalExecutionContext.GetType().GetProperty(
37+
'CustomArgumentCompleters',
38+
[System.Reflection.BindingFlags]'NonPublic, Instance'
39+
)
40+
$customArgumentCompleters = $customArgumentCompletersProperty.GetGetMethod($true).Invoke(
41+
$internalExecutionContext,
42+
[System.Reflection.BindingFlags]'Instance, NonPublic, GetProperty',
43+
$null,
44+
@(),
45+
$psculture
46+
)
47+
}
48+
process
49+
{
50+
foreach ($argumentCompleter in $customArgumentCompleters.Keys)
51+
{
52+
$name, $parameter = $argumentCompleter -split ':'
53+
54+
if ($name -like $CommandName)
55+
{
56+
if ($parameter -like $ParameterName)
57+
{
58+
New-Object PSObject -Property @{
59+
CommandName = $name
60+
ParameterName = $parameter
61+
Definition = $customArgumentCompleters[$argumentCompleter]
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)