Skip to content

Commit 1f4cf7c

Browse files
🪲 [Fix]: Fix argument completers for Context:ID and ContextVault:Name (#96)
## Description This pull request refactors the argument completer functionality for context vaults and context IDs. It consolidates and simplifies the completers by replacing inline completers with centralized script blocks and registering them dynamically. The changes improve maintainability and reduce redundancy across multiple files. ### Refactoring Argument Completers: * **Centralized Context Vault Name Completer**: Created a reusable `$contextVaultNameCompleter` script block and registered it for relevant commands and parameters (`Vault` and `Name`). This replaces inline completers for context vault names across various functions. * **Centralized Context ID Completer**: Refactored the context ID completer into a `$contextIDCompleter` script block and registered it dynamically for commands using the `ID` parameter. The file `Complete-ContextID.ps1` was renamed to `completers.ps1` and updated accordingly. ### Removal of Inline Completers: * **Context Vault Name Completers**: Removed inline `Complete-ContextVaultName` argument completers from functions such as `Get-Context`, `Set-Context`, `Remove-ContextVault`, and others. These are now handled by the centralized completer. * **Context ID Completers**: Removed inline `Complete-ContextID` argument completers from functions like `Get-Context`, `Remove-Context`, and `Rename-Context`. These are now managed by the centralized completer. ### Code Cleanup: * **Removed Obsolete Completer Functions**: Deleted the `Complete-ContextVaultName` function as its functionality is now encapsulated in the `$contextVaultNameCompleter` script block. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 66e6fe9 commit 1f4cf7c

12 files changed

+17
-54
lines changed

src/functions/private/Completers/Complete-ContextVaultName.ps1

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/functions/public/Get-Context.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ function Get-Context {
9595
ValueFromPipeline,
9696
ValueFromPipelineByPropertyName
9797
)]
98-
[ArgumentCompleter({ Complete-ContextID @args })]
9998
[SupportsWildcards()]
10099
[string[]] $ID = '*',
101100

102101
# The name of the vault to store the context in.
103102
[Parameter()]
104-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
105103
[SupportsWildcards()]
106104
[string[]] $Vault = '*'
107105
)

src/functions/public/Get-ContextInfo.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@
6565
param(
6666
# The name of the context to retrieve from the vault. Supports wildcards.
6767
[Parameter()]
68-
[ArgumentCompleter({ Complete-ContextID @args })]
6968
[SupportsWildcards()]
7069
[string[]] $ID = '*',
7170

7271
# The name of the vault to retrieve context info from. Supports wildcards.
7372
[Parameter()]
74-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
7573
[string[]] $Vault = '*'
7674
)
7775

src/functions/public/Remove-Context.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@
8282
ValueFromPipeline,
8383
ValueFromPipelineByPropertyName
8484
)]
85-
[ArgumentCompleter({ Complete-ContextID @args })]
8685
[SupportsWildcards()]
8786
[string[]] $ID,
8887

8988
# The name of the vault to remove contexts from.
9089
[Parameter()]
91-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
9290
[string] $Vault
9391
)
9492

src/functions/public/Rename-Context.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
ValueFromPipeline,
4848
ValueFromPipelineByPropertyName
4949
)]
50-
[ArgumentCompleter({ Complete-ContextID @args })]
5150
[string] $ID,
5251

5352
# The new ID of the context.
@@ -60,7 +59,6 @@
6059

6160
# The name of the vault containing the context.
6261
[Parameter()]
63-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
6462
[string] $Vault,
6563

6664
# Pass the context through the pipeline.

src/functions/public/Set-Context.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ function Set-Context {
6666

6767
# The name of the vault to store the context in.
6868
[Parameter(Mandatory)]
69-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
7069
[string] $Vault,
7170

7271
# Pass the context through the pipeline.

src/functions/public/Vault/Get-ContextVault.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
param(
3333
# The name of the vault to retrieve. Supports wildcards.
3434
[Parameter()]
35-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
3635
[SupportsWildcards()]
3736
[string[]] $Name = '*'
3837
)

src/functions/public/Vault/Remove-ContextVault.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
param(
2020
# The name of the vault to remove.
2121
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName = 'By Name')]
22-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
2322
[SupportsWildcards()]
2423
[string[]] $Name,
2524

src/functions/public/Vault/Reset-ContextVault.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
param(
2424
# The name of the vault to reset.
2525
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName = 'By Name')]
26-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
2726
[SupportsWildcards()]
2827
[string[]] $Name = '*',
2928

src/functions/public/Vault/Set-ContextVault.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function Set-ContextVault {
2424
param(
2525
# The name of the vault to create or update.
2626
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
27-
[ArgumentCompleter({ Complete-ContextVaultName @args })]
2827
[string[]] $Name,
2928

3029
# Pass the context through the pipeline.

0 commit comments

Comments
 (0)