-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPSConfEU-Class.psm1
75 lines (66 loc) · 2.34 KB
/
PSConfEU-Class.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$sessionData = Import-Clixml -LiteralPath 'D:\Backup\PSConfEU-Export.clixml'
class EuCompleter : System.Management.Automation.IArgumentCompleter {
[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument (
[String]$CommandName,
[String]$ParameterName,
[String]$WordToComplete,
[System.Management.Automation.Language.CommandAst]$CommandAst,
[System.Collections.IDictionary]$FakeBoundParameters
) {
$splat = @{}
switch ($ParameterName) {
Speaker {
if ($FakeBoundParameters.Contains('Title')) {
$splat.Title = $FakeBoundParameters['Title']
}
}
Title {
if ($FakeBoundParameters.Contains('Speaker')) {
$splat.Speaker = $FakeBoundParameters['Speaker']
}
}
}
return [System.Management.Automation.CompletionResult[]]@(
Get-ConfEUSession @splat |
Where-Object $ParameterName -Like "$WordToComplete*" |
ForEach-Object $ParameterName |
ForEach-Object {
$this.NewResult($_)
}
)
}
[System.Management.Automation.CompletionResult] NewResult (
[String]$CompletionText
) {
$tokens = $null
$null = [System.Management.Automation.Language.Parser]::ParseInput(
"echo $CompletionText",
[ref]$tokens,
[ref]$null
)
if (
$tokens.Length -ne 3 -or
(
$tokens[1] -is [System.Management.Automation.Language.StringExpandableToken] -and
$tokens[1].Kind -eq [System.Management.Automation.Language.TokenKind]::Generic
)
) {
$CompletionText = "'$CompletionText'"
}
return [System.Management.Automation.CompletionResult]::new($CompletionText)
}
}
function Get-ConfEUSession {
param (
[ArgumentCompleter([EuCompleter])]
[String]$Speaker = '*',
[ArgumentCompleter([EuCompleter])]
[String]$Title = '*',
[String]$Abstract = '*'
)
$sessionData.Where{
$_.Speaker -like $Speaker -and
$_.Title -like $Title -and
$_.Abstract -like $Abstract
}
}