Skip to content

Commit

Permalink
feat: add autocompletion for Title2, Title3, & DisplayPriority
Browse files Browse the repository at this point in the history
Add autocompletion for -Title2, -Title3, and -DisplayPriority

This is done through a [ValidateSet()] attribute on these parameters for
both the Add and Update functions. These are already validated to be in
the correct range through a [ValidateRange()] attribute, but having
[ValidateSet()] also allows PowerShell to autocomplete the expected
range for these parameters.
  • Loading branch information
desjardinsm committed Feb 14, 2024
1 parent 386c457 commit aa999cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Module/RicohAddressBook.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'RicohAddressBook.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'
ModuleVersion = '1.1.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
6 changes: 6 additions & 0 deletions Module/RicohAddressBook.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ function Update-AddressBookEntry {

[byte]
[ValidateRange(1, 10)]
[ValidateSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]
[Parameter(ValueFromPipelineByPropertyName)]
$DisplayPriority,

Expand All @@ -851,11 +852,13 @@ function Update-AddressBookEntry {

[byte]
[ValidateRange(1, 10)]
[ValidateSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]
[Parameter(ValueFromPipelineByPropertyName)]
$Title2,

[byte]
[ValidateRange(1, 5)]
[ValidateSet(1, 2, 3, 4, 5)]
[Parameter(ValueFromPipelineByPropertyName)]
$Title3,

Expand Down Expand Up @@ -1193,6 +1196,7 @@ function Add-AddressBookEntry {

[byte]
[ValidateRange(1, 10)]
[ValidateSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]
[Parameter(ValueFromPipelineByPropertyName)]
$DisplayPriority = 5,

Expand All @@ -1206,11 +1210,13 @@ function Add-AddressBookEntry {

[byte]
[ValidateRange(1, 10)]
[ValidateSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]
[Parameter(ValueFromPipelineByPropertyName)]
$Title2,

[byte]
[ValidateRange(1, 5)]
[ValidateSet(1, 2, 3, 4, 5)]
[Parameter(ValueFromPipelineByPropertyName)]
$Title3,

Expand Down
4 changes: 2 additions & 2 deletions Tests/RicohAddressBook.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ Describe 'Parameter validation' {
}

& "$functionName-AddressBookEntry" @commonParameters @otherParameters @invalidParameters -ErrorAction SilentlyContinue
} | Should -Throw "Cannot validate argument on parameter '$ParameterName'. The $($MaximumValue + 1) argument is greater than the maximum allowed range of $MaximumValue. Supply an argument that is less than or equal to $MaximumValue and then try the command again."
} | Should -Throw "Cannot validate argument on parameter '$ParameterName'. The argument `"$($MaximumValue + 1)`" does not belong to the set `"*,$MaximumValue`" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again."
}

It -ForEach @('DisplayPriority', 'Title2', 'Title3') 'Throws a validation exception when <_> is less than 1' {
Expand All @@ -2355,7 +2355,7 @@ Describe 'Parameter validation' {
}

& "$functionName-AddressBookEntry" @commonParameters @otherParameters @invalidParameters -ErrorAction SilentlyContinue
} | Should -Throw "Cannot validate argument on parameter '$_'. The 0 argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again."
} | Should -Throw "Cannot validate argument on parameter '$_'. The argument `"0`" does not belong to the set `"1,*`" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again."
}

It 'Does not throw a validation exception when UserCode is number-like' {
Expand Down

0 comments on commit aa999cf

Please sign in to comment.