@@ -44,25 +44,45 @@ Get-Command *-GitHub* | Where-Object { $_.Parameters -and $_.Parameters.Contains
44
44
45
45
$repositoryNameCompleter = {
46
46
[CmdletBinding ()]
47
- param ([string ]$command , [string ]$parameter , [string ]$wordToComplete , [CommandAst ]$commandAst , [Hashtable ]$params )
48
- Add-DefaultParameterValues - Command $command - Parameters $params
47
+ param ($commandName , $parameterName , $wordToComplete , $commandAst , $fakeBoundParameter )
48
+
49
+ # Add-DefaultParameterValues -Command $commandName -Parameters $fakeBoundParameter
50
+ $RepoArray = [System.Object []]::new(40 )
51
+
49
52
$findRepoParams = @ {
50
- Query = $wordToComplete
53
+ Query = $wordToComplete
54
+ }
55
+ if ($fakeBoundParameter.ContainsKey (' Owner' )) {
56
+ $findRepoParams.Query += ' user:{0}' -f $fakeBoundParameter.Owner
51
57
}
52
- if ($params.ContainsKey (' Token' )) {
53
- $findRepoParams.Token = $params.Token
58
+ try {
59
+ Find-GitHubRepository @findRepoParams | ForEach-Object - Begin { $i = 0 } - Process {
60
+ $RepoArray [$i ] = $PSItem
61
+ $i ++
62
+ }
54
63
}
55
- if ( $params .ContainsKey ( ' Owner ' )) {
56
- $findRepoParams .Query += " user: $ ( $params .Owner ) "
64
+ catch {
65
+ # Once array is filled up, stop execution
57
66
}
58
- Find-GitHubRepository @findRepoParams |
59
- Where-Object { $_.Name -like " $wordToComplete *" } |
60
- Select-Object - First 5 |
61
- ForEach-Object {
62
- $tooltip = if ($_.Description ) { $_.Description } else { $_.Name }
63
- [CompletionResult ]::new($_.Name , $_.Name , [CompletionResultType ]::ParameterValue, $tooltip )
67
+
68
+ try {
69
+ foreach ($Repo in $RepoArray ) {
70
+ $tooltip = if ($Repo.Description ) { $Repo.Description } else { $Repo.Name }
71
+ if (! $fakeBoundParameter.ContainsKey (' Owner' )) {
72
+ $CompletionText = ' {0} -Owner {1}' -f $Repo.Name , $Repo.Owner
73
+ [CompletionResult ]::new($CompletionText , $Repo.Name , [CompletionResultType ]::ParameterValue, $tooltip )
74
+ }
75
+ else {
76
+ [CompletionResult ]::new($Repo.Name , $Repo.Name , [CompletionResultType ]::ParameterValue, $tooltip )
77
+ }
64
78
}
79
+ }
80
+ catch {
81
+ # Set-Content -Path $HOME/psgithub.error.log -Value $PSItem
82
+ # Add-Content -Path $HOME/psgithub.error.log -Value ($RepoArray.SyncRoot | ConvertTo-Json)
83
+ }
65
84
}
85
+
66
86
Get-Command *- GitHub* | Where-Object { $_.Parameters -and $_.Parameters.ContainsKey (' RepositoryName' ) } | ForEach-Object {
67
87
Register-ArgumentCompleter - CommandName $_.Name - ParameterName RepositoryName - ScriptBlock $repositoryNameCompleter
68
88
}
0 commit comments