From 0d0b600e496431356d3c62cdd8879a09826601b4 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Sep 2025 13:52:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80[Feature]:=20Add=20a=20config=20for?= =?UTF-8?q?=20how=20to=20match=20argument=20completers=20(#512)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pull request introduces a new configurable completion mode for argument completers, allowing users to choose between 'StartsWith' and 'Contains' matching for tab completion throughout the module. It also improves the config initialization logic to better synchronize stored configuration objects with the current class definition, ensuring obsolete properties are removed and new ones are added automatically. - Fixes #509 **Configurable Completion Mode:** * Added a new `CompletionMode` property to the `GitHubConfig` class, allowing users to select between 'StartsWith' and 'Contains' matching for argument completion. This property is now included in the config display format. * Updated all argument completer scripts to use the `CompletionMode` from config, switching between prefix and substring matching as specified. This affects completers for contexts, organizations, environments, gitignore, licenses, permissions, and repository permissions. * Added a value completer for the `CompletionMode` property itself, suggesting 'StartsWith' and 'Contains' when setting the config. **Configuration Management Improvements:** * Enhanced the `Initialize-GitHubConfig` function to automatically add new properties and remove obsolete ones from stored configs, ensuring the config object stays in sync with the class definition. **Minor Usability Improvement:** * Made the `Context` parameter in `Get-GitHubContext` positional for easier use. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> Co-authored-by: Marius Storhaug --- src/classes/public/Config/GitHubConfig.ps1 | 3 ++ src/completers.ps1 | 12 ++--- src/formats/GitHubConfig.Format.ps1xml | 3 ++ .../Config/Initialize-GitHubConfig.ps1 | 52 +++++++++++++------ .../public/Auth/Context/Get-GitHubContext.ps1 | 3 +- .../public/Auth/Context/completers.ps1 | 4 +- src/functions/public/Config/completers.ps1 | 14 ++++- .../public/Environments/completers.ps1 | 6 ++- src/functions/public/Gitignore/completers.ps1 | 3 +- src/functions/public/License/completers.ps1 | 3 +- .../public/Organization/completers.ps1 | 9 ++-- .../public/Permission/completers.ps1 | 12 +++-- .../Repositories/Permissions/completers.ps1 | 4 +- .../public/Repositories/completers.ps1 | 18 ++++--- src/functions/public/Secrets/completers.ps1 | 3 +- src/functions/public/Teams/completers.ps1 | 6 ++- src/functions/public/Variables/completers.ps1 | 3 +- src/functions/public/Workflows/completers.ps1 | 6 ++- src/variables/private/GitHub.ps1 | 1 + 19 files changed, 114 insertions(+), 51 deletions(-) diff --git a/src/classes/public/Config/GitHubConfig.ps1 b/src/classes/public/Config/GitHubConfig.ps1 index ac8ffd8b8..b0289ce68 100644 --- a/src/classes/public/Config/GitHubConfig.ps1 +++ b/src/classes/public/Config/GitHubConfig.ps1 @@ -38,6 +38,9 @@ # The environment type, which is used to determine the context of the GitHub API calls. [string] $EnvironmentType + # The completion mode for argument completers. Options: 'StartsWith', 'Contains'. + [string] $CompletionMode + # Simple parameterless constructor GitHubConfig() {} diff --git a/src/completers.ps1 b/src/completers.ps1 index 1491a5b8a..901d1de8e 100644 --- a/src/completers.ps1 +++ b/src/completers.ps1 @@ -1,39 +1,39 @@ Register-ArgumentCompleter -CommandName Connect-GitHubApp -ParameterName User -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'User' -and $_.Target.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'User' -and $_.Target.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Target.Name, $_.Target.Name, 'ParameterValue', $_.Target.Name) } } Register-ArgumentCompleter -CommandName Connect-GitHubApp -ParameterName Organization -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'Organization' -and $_.Target.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'Organization' -and $_.Target.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Target.Name, $_.Target.Name, 'ParameterValue', $_.Target.Name) } } Register-ArgumentCompleter -CommandName Connect-GitHubApp -ParameterName Enterprise -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'Enterprise' -and $_.Target.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'Enterprise' -and $_.Target.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Target.Name, $_.Target.Name, 'ParameterValue', $_.Target.Name) } } diff --git a/src/formats/GitHubConfig.Format.ps1xml b/src/formats/GitHubConfig.Format.ps1xml index cd556ceb4..807943b93 100644 --- a/src/formats/GitHubConfig.Format.ps1xml +++ b/src/formats/GitHubConfig.Format.ps1xml @@ -46,6 +46,9 @@ RetryInterval + + CompletionMode + diff --git a/src/functions/private/Config/Initialize-GitHubConfig.ps1 b/src/functions/private/Config/Initialize-GitHubConfig.ps1 index 651445856..c8d733fa4 100644 --- a/src/functions/private/Config/Initialize-GitHubConfig.ps1 +++ b/src/functions/private/Config/Initialize-GitHubConfig.ps1 @@ -32,43 +32,64 @@ Write-Debug "Force: [$Force]" if ($Force) { Write-Debug 'Forcing initialization of GitHubConfig.' - $context = Set-Context -Context $script:GitHub.DefaultConfig -Vault $script:GitHub.ContextVault -PassThru - $script:GitHub.Config = [GitHubConfig]$context + $config = Set-Context -Context $script:GitHub.DefaultConfig -Vault $script:GitHub.ContextVault -PassThru + $script:GitHub.Config = [GitHubConfig]$config return } - Write-Debug "GitHubConfig ID: [$($script:GitHub.Config.ID)]" if ($null -ne $script:GitHub.Config) { Write-Debug 'GitHubConfig already initialized and available in memory.' return } Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault' - $context = Get-Context -ID $script:GitHub.DefaultConfig.ID -Vault $script:GitHub.ContextVault - if ($context) { + $config = Get-Context -ID $script:GitHub.DefaultConfig.ID -Vault $script:GitHub.ContextVault + if ($config) { Write-Debug 'GitHubConfig loaded into memory.' - Write-Debug 'Checking if new default properties are available in the stored context.' + Write-Debug 'Synchronizing stored context with GitHubConfig class definition.' $needsUpdate = $false - $defaultProperties = $script:GitHub.DefaultConfig.PSObject.Properties.Name - foreach ($propName in $defaultProperties) { - if (-not $context.PSObject.Properties.Name.Contains($propName)) { + $validProperties = [GitHubConfig].GetProperties().Name + $storedProperties = $config.PSObject.Properties.Name + + # Add missing properties from DefaultConfig + foreach ($propName in $validProperties) { + Write-Debug "Validating property [$propName]" + if (-not $storedProperties.Contains($propName)) { Write-Debug "Adding missing property [$propName] from DefaultConfig" - $context | Add-Member -MemberType NoteProperty -Name $propName -Value $script:GitHub.DefaultConfig.$propName + $defaultValue = $script:GitHub.DefaultConfig.$propName + $config | Add-Member -MemberType NoteProperty -Name $propName -Value $defaultValue + $needsUpdate = $true + } + } + + # Remove obsolete properties that are no longer supported + $propertiesToRemove = @() + foreach ($propName in $storedProperties) { + Write-Debug "Checking property [$propName] for obsolescence" + if (-not $validProperties.Contains($propName)) { + Write-Debug "Removing obsolete property [$propName] from stored context" + $propertiesToRemove += $propName $needsUpdate = $true } } + + # Remove the obsolete properties + foreach ($propName in $propertiesToRemove) { + $config.PSObject.Properties.Remove($propName) + } + if ($needsUpdate) { - Write-Debug 'Updating stored context with new default properties' - $context = Set-Context -Context $context -Vault $script:GitHub.ContextVault -PassThru + Write-Debug 'Updating stored context with synchronized properties' + $config = Set-Context -Context $config -Vault $script:GitHub.ContextVault -PassThru } - $script:GitHub.Config = [GitHubConfig]$context + $script:GitHub.Config = [GitHubConfig]$config return } Write-Debug 'Initializing GitHubConfig from defaults' - $context = Set-Context -Context $script:GitHub.DefaultConfig -Vault $script:GitHub.ContextVault -PassThru - $script:GitHub.Config = [GitHubConfig]$context + $config = Set-Context -Context $script:GitHub.DefaultConfig -Vault $script:GitHub.ContextVault -PassThru + $script:GitHub.Config = [GitHubConfig]$config } end { @@ -76,4 +97,3 @@ } } #Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '8.1.3' } - diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index 6ff8aecc1..03ff7be82 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -24,7 +24,8 @@ # The name of the context. [Parameter( Mandatory, - ParameterSetName = 'Get a named context' + ParameterSetName = 'Get a named context', + Position = 0 )] [Alias('Name')] [string] $Context, diff --git a/src/functions/public/Auth/Context/completers.ps1 b/src/functions/public/Auth/Context/completers.ps1 index e263e354b..9f4c2752d 100644 --- a/src/functions/public/Auth/Context/completers.ps1 +++ b/src/functions/public/Auth/Context/completers.ps1 @@ -1,7 +1,7 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Context -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $contexts = @() $hasAnonymousParameter = $false $command = Get-Command -Name $commandName -ErrorAction SilentlyContinue @@ -14,7 +14,7 @@ $contexts += Get-GitHubContext -ListAvailable -Verbose:$false -Debug:$false $contexts = $contexts | Sort-Object -Property Name - $contexts | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + $contexts | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Config/completers.ps1 b/src/functions/public/Config/completers.ps1 index 4e91daea9..1165d3170 100644 --- a/src/functions/public/Config/completers.ps1 +++ b/src/functions/public/Config/completers.ps1 @@ -1,7 +1,19 @@ Register-ArgumentCompleter -CommandName Set-GitHubConfig, Get-GitHubConfig, Remove-GitHubConfig -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - ([GitHubConfig]).GetProperties().Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + ([GitHubConfig]).GetProperties().Name | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_ ) } } + +Register-ArgumentCompleter -CommandName Set-GitHubConfig -ParameterName Value -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + if ($fakeBoundParameters.Name -eq 'CompletionMode') { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + @('StartsWith', 'Contains') | Where-Object { $_ -like $pattern } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } +} diff --git a/src/functions/public/Environments/completers.ps1 b/src/functions/public/Environments/completers.ps1 index 6ae810de2..e2f9422f4 100644 --- a/src/functions/public/Environments/completers.ps1 +++ b/src/functions/public/Environments/completers.ps1 @@ -2,6 +2,7 @@ Where-Object { $_ -like '*GitHubEnvironment' }) -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner Repository = $fakeBoundParameters.Repository @@ -10,7 +11,7 @@ Debug = $false } $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubEnvironment @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubEnvironment @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } @@ -18,6 +19,7 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Environment -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner Repository = $fakeBoundParameters.Repository @@ -26,7 +28,7 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) Debug = $false } $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubEnvironment @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubEnvironment @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Gitignore/completers.ps1 b/src/functions/public/Gitignore/completers.ps1 index 53a53dac1..86d7df84e 100644 --- a/src/functions/public/Gitignore/completers.ps1 +++ b/src/functions/public/Gitignore/completers.ps1 @@ -1,12 +1,13 @@ Register-ArgumentCompleter -CommandName Get-GitHubGitignore -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubGitignore @params | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubGitignore @params | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } diff --git a/src/functions/public/License/completers.ps1 b/src/functions/public/License/completers.ps1 index 8349d3be3..a4c5a4f10 100644 --- a/src/functions/public/License/completers.ps1 +++ b/src/functions/public/License/completers.ps1 @@ -1,12 +1,13 @@ Register-ArgumentCompleter -CommandName Get-GitHubLicense -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubLicense @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubLicense @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Organization/completers.ps1 b/src/functions/public/Organization/completers.ps1 index cf44acaa8..2994f0240 100644 --- a/src/functions/public/Organization/completers.ps1 +++ b/src/functions/public/Organization/completers.ps1 @@ -2,12 +2,13 @@ Where-Object { $_ -like '*GitHubOrganization' }) -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubOrganization @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubOrganization @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } @@ -15,12 +16,13 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Owner -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubOrganization @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubOrganization @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } @@ -28,12 +30,13 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Organization -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubOrganization @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubOrganization @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Permission/completers.ps1 b/src/functions/public/Permission/completers.ps1 index a8e8f50ea..4586354f0 100644 --- a/src/functions/public/Permission/completers.ps1 +++ b/src/functions/public/Permission/completers.ps1 @@ -1,7 +1,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubPermissionDefinition -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - $script:GitHub.Permissions.Name | Sort-Object -Unique | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + $script:GitHub.Permissions.Name | Sort-Object -Unique | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } @@ -9,7 +10,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubPermissionDefinition -ParameterName DisplayName -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - $script:GitHub.Permissions.DisplayName | Sort-Object -Unique | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + $script:GitHub.Permissions.DisplayName | Sort-Object -Unique | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } @@ -17,7 +19,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubPermissionDefinition -Paramete Register-ArgumentCompleter -CommandName Get-GitHubPermissionDefinition -ParameterName Type -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - $script:GitHub.Permissions.Type | Sort-Object -Unique | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + $script:GitHub.Permissions.Type | Sort-Object -Unique | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } @@ -25,7 +28,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubPermissionDefinition -Paramete Register-ArgumentCompleter -CommandName Get-GitHubPermissionDefinition -ParameterName Scope -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - $script:GitHub.Permissions.Scope | Sort-Object -Unique | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + $script:GitHub.Permissions.Scope | Sort-Object -Unique | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } diff --git a/src/functions/public/Repositories/Permissions/completers.ps1 b/src/functions/public/Repositories/Permissions/completers.ps1 index cd99774b6..cdb1e0c2e 100644 --- a/src/functions/public/Repositories/Permissions/completers.ps1 +++ b/src/functions/public/Repositories/Permissions/completers.ps1 @@ -1,8 +1,8 @@ Register-ArgumentCompleter -CommandName Set-GitHubRepositoryPermission -ParameterName Permission -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - $permissions = @('None', 'Pull', 'Triage', 'Push', 'Maintain', 'Admin', 'Read', 'Write') - $permissions | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + @('None', 'Pull', 'Triage', 'Push', 'Maintain', 'Admin', 'Read', 'Write') | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } diff --git a/src/functions/public/Repositories/completers.ps1 b/src/functions/public/Repositories/completers.ps1 index 01d39da7b..43ac6a7c7 100644 --- a/src/functions/public/Repositories/completers.ps1 +++ b/src/functions/public/Repositories/completers.ps1 @@ -1,12 +1,13 @@ Register-ArgumentCompleter -CommandName New-GitHubRepository -ParameterName Gitignore -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubGitignore @params | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubGitignore @params | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } @@ -14,12 +15,13 @@ Register-ArgumentCompleter -CommandName New-GitHubRepository -ParameterName License -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubLicense @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubLicense @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } @@ -27,7 +29,8 @@ Register-ArgumentCompleter -CommandName New-GitHubRepository -ParameterName Lice Register-ArgumentCompleter -CommandName Get-GitHubRepository -ParameterName AdditionalProperty -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - [GitHubRepository].GetProperties().Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + [GitHubRepository].GetProperties().Name | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } @@ -35,7 +38,8 @@ Register-ArgumentCompleter -CommandName Get-GitHubRepository -ParameterName Addi Register-ArgumentCompleter -CommandName Get-GitHubRepository -ParameterName Property -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters - [GitHubRepository].GetProperties().Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } + [GitHubRepository].GetProperties().Name | Where-Object { $_ -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } @@ -43,13 +47,14 @@ Register-ArgumentCompleter -CommandName Get-GitHubRepository -ParameterName Prop Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Repository -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner ?? $fakeBoundParameters.Organization Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubRepository @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubRepository @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } @@ -58,13 +63,14 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport Where-Object { $_ -like '*GitHubRepository' }) -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner ?? $fakeBoundParameters.Organization Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubRepository @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubRepository @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Secrets/completers.ps1 b/src/functions/public/Secrets/completers.ps1 index b15f6d0cd..411ed8ace 100644 --- a/src/functions/public/Secrets/completers.ps1 +++ b/src/functions/public/Secrets/completers.ps1 @@ -2,6 +2,7 @@ Where-Object { $_ -like '*GitHubSecret' }) -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner Repository = $fakeBoundParameters.Repository @@ -11,7 +12,7 @@ Debug = $false } $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubSecret @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubSecret @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Teams/completers.ps1 b/src/functions/public/Teams/completers.ps1 index a91ce2502..64d643909 100644 --- a/src/functions/public/Teams/completers.ps1 +++ b/src/functions/public/Teams/completers.ps1 @@ -2,13 +2,14 @@ Where-Object { $_ -like '*GitHubTeam' }) -ParameterName Slug -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Organization = $fakeBoundParameters.Organization Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubTeam @params | Where-Object { $_.Slug -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubTeam @params | Where-Object { $_.Slug -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Slug, $_.Slug, 'ParameterValue', $_.Slug) } } @@ -16,13 +17,14 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Team -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Organization = $fakeBoundParameters.Organization ?? $fakeBoundParameters.Owner Context = $fakeBoundParameters.Context Verbose = $false Debug = $false } - Get-GitHubTeam @params | Where-Object { $_.Slug -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubTeam @params | Where-Object { $_.Slug -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Slug, $_.Slug, 'ParameterValue', $_.Slug) } } diff --git a/src/functions/public/Variables/completers.ps1 b/src/functions/public/Variables/completers.ps1 index 1f6a39ae5..c897efa47 100644 --- a/src/functions/public/Variables/completers.ps1 +++ b/src/functions/public/Variables/completers.ps1 @@ -2,6 +2,7 @@ Where-Object { $_ -like '*GitHubVariable' }) -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner Repository = $fakeBoundParameters.Repository @@ -11,7 +12,7 @@ Debug = $false } $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubVariable @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubVariable @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } diff --git a/src/functions/public/Workflows/completers.ps1 b/src/functions/public/Workflows/completers.ps1 index cebb7ed67..29a8fb0e4 100644 --- a/src/functions/public/Workflows/completers.ps1 +++ b/src/functions/public/Workflows/completers.ps1 @@ -2,6 +2,7 @@ Where-Object { $_ -like '*GitHubWorkflow' }) -ParameterName Name -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner Repository = $fakeBoundParameters.Repository @@ -10,7 +11,7 @@ Debug = $false } $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubWorkflow @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubWorkflow @params | Where-Object { $_.Name -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) } } @@ -18,6 +19,7 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport Where-Object { $_ -like '*GitHubWorkflow' }) -ParameterName ID -ScriptBlock { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + $pattern = switch (Get-GitHubConfig -Name CompletionMode) { 'Contains' { "*$wordToComplete*" } default { "$wordToComplete*" } } $params = @{ Owner = $fakeBoundParameters.Owner Repository = $fakeBoundParameters.Repository @@ -26,7 +28,7 @@ Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport Debug = $false } $params | Remove-HashtableEntry -NullOrEmptyValues - Get-GitHubWorkflow @params | Where-Object { $_.ID -like "$wordToComplete*" } | ForEach-Object { + Get-GitHubWorkflow @params | Where-Object { $_.ID -like $pattern } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.ID, "$($_.Name) ($($_.ID))", 'ParameterValue', "$($_.Name) ($($_.ID))" ) } } diff --git a/src/variables/private/GitHub.ps1 b/src/variables/private/GitHub.ps1 index 917d0be14..190de6d2d 100644 --- a/src/variables/private/GitHub.ps1 +++ b/src/variables/private/GitHub.ps1 @@ -19,6 +19,7 @@ $script:GitHub = [pscustomobject]@{ RetryCount = 0 RetryInterval = 1 EnvironmentType = Get-GitHubEnvironmentType + CompletionMode = 'StartsWith' } Config = $null Event = $null