Handlers/Utilities.ps1

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
76
77
78
79
80
81
82

## netsh
& {
    Register-TabExpansion netsh.exe -Type Command {
        param($Context, [ref]$TabExpansionHasOutput)
        $Argument = $Context.Argument
        switch -exact ($Context.Parameter) {
            'r' {
                $TabExpansionHasOutput.Value = $true
                Get-TabExpansion "$Argument*" Computer | New-TabItem -Value {$_.Text} -Text {$_.Text} -ResultType ParameterValue
            }
        }
    }.GetNewClosure()

    Function netshexeparameters {
        param(
            [String]$a
            ,
            [ValidateSet("advfirewall","branchcache","bridge","dhcpclient","dnsclient","firewall","http","interface","ipsec",
                "lan","mbn","namespace","nap","netio","p2p","ras","rpc","trace","wcn","wfp","winhttp","winsock","wlan")]
            [String]$c
            ,
            [String]$r
            ,
            [String]$u
            ,
            [String]$p
            ,
            [String]$f
            ,
            [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
            [String[]]$Commands
        )
    }

    ## TODO: Handle commands and contexts

    $netshCommandInfo = Get-Command netshexeparameters
    Register-TabExpansion netsh.exe -Type CommandInfo {
        param($Context)
        $netshCommandInfo
    }.GetNewClosure()

    Register-TabExpansion netsh.exe -Type ParameterName {
        param($Context, $Parameter)
        $Parameters = "-a","-c","-r","-u","-p","-f"
        $Parameters | Where-Object {$_ -like "$Parameter*"} | New-TabItem -Value {$_} -Text {$_} -ResultType ParameterName
    }.GetNewClosure()
}

## reg
& {
    Register-TabExpansion reg.exe -Type Command {
        param($Context, [ref]$TabExpansionHasOutput)
        <#
        $Argument = $Context.Argument
        switch -exact ($Context.Parameter) {
            'r' {
                $TabExpansionHasOutput.Value = $true
                Get-TabExpansion "$Argument*" Computer | New-TabItem {$_.Text} {$_.Text} -ResultType ParameterValue
            }
        }
        #>

    }.GetNewClosure()

    Function regexeparameters {
        param(
            [Parameter(Position = 0)]
            [ValidateSet("QUERY","ADD","DELETE","COPY","SAVE","RESTORE","LOAD","UNLOAD","COMPARE","EXPORT","IMPORT","FLAGS")]
            [String]$Command
        )
    }

    ## TODO: Handle options

    $regCommandInfo = Get-Command regexeparameters
    Register-TabExpansion reg.exe -Type CommandInfo {
        param($Context)
        $regCommandInfo
    }.GetNewClosure()
}