Skip to content

Commit dd71d61

Browse files
authored
Merge pull request #100 from mdgrs-mei/add-value-from-pipeline
Add ValueFromPipeline and ValueFromPipelineByPropertyName
2 parents e3c3c28 + a03e237 commit dd71d61

20 files changed

Lines changed: 161 additions & 55 deletions

module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The parent entry group object where this new entry group is added.
2828
Returns the added entry group if specified.
2929
3030
.INPUTS
31-
None.
31+
The Name parameter.
3232
3333
.OUTPUTS
3434
An object that represents an entry group if PassThru is specified. None otherwise.
@@ -46,7 +46,7 @@ function Add-PSRunEntryGroup {
4646
[Parameter(ValueFromPipelineByPropertyName = $true)]
4747
[String]$Icon,
4848

49-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
49+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
5050
[String]$Name,
5151

5252
[Parameter(ValueFromPipelineByPropertyName = $true)]

module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The custom preview string.
2424
The parent entry group object where this new entry is added.
2525
2626
.INPUTS
27-
None.
27+
The Path parameter.
2828
2929
.OUTPUTS
3030
None.
@@ -38,7 +38,7 @@ Add-PSRunFavoriteFile -Path 'D:\PowerShellRun\Build.ps1' -Icon '🧪' -Name 'Bui
3838
function Add-PSRunFavoriteFile {
3939
[CmdletBinding()]
4040
param (
41-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
41+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
4242
[String]$Path,
4343

4444
[Parameter(ValueFromPipelineByPropertyName = $true)]

module/PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The custom preview string.
2424
The parent entry group object where this new entry is added.
2525
2626
.INPUTS
27-
None.
27+
The Path parameter.
2828
2929
.OUTPUTS
3030
None.
@@ -38,7 +38,7 @@ Add-PSRunFavoriteFolder -Path 'D:/Download' -Icon '🌐'
3838
function Add-PSRunFavoriteFolder {
3939
[CmdletBinding()]
4040
param (
41-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
41+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
4242
[String]$Path,
4343

4444
[Parameter(ValueFromPipelineByPropertyName = $true)]

module/PowerShellRun/Public/Add-PSRunFunction.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The custom preview string.
2525
The parent entry group object where this new entry is added.
2626
2727
.INPUTS
28-
None.
28+
The FunctionName parameter.
2929
3030
.OUTPUTS
3131
None.
@@ -41,7 +41,7 @@ Add-PSRunFunction -FunctionName TestFunction -Icon '🍏' -Name 'Test Function'
4141
function Add-PSRunFunction {
4242
[CmdletBinding()]
4343
param (
44-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
44+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
4545
[String]$FunctionName,
4646

4747
[Parameter(ValueFromPipelineByPropertyName = $true)]

module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The custom preview string. The definition of the ScriptBlock is used by default.
2727
The parent entry group object where this new entry is added.
2828
2929
.INPUTS
30-
None.
30+
The ScriptBlock parameter.
3131
3232
.OUTPUTS
3333
None.
@@ -43,7 +43,7 @@ Add-PSRunScriptBlock -Icon '🥏' -Name 'GitPullRebase' -Description 'git pull w
4343
function Add-PSRunScriptBlock {
4444
[CmdletBinding()]
4545
param (
46-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
46+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
4747
[ScriptBlock]$ScriptBlock,
4848

4949
[Parameter(ValueFromPipelineByPropertyName = $true)]

module/PowerShellRun/Public/Add-PSRunScriptFile.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The custom preview string. The content of the script file is used by default.
2727
The parent entry group object where this new entry is added.
2828
2929
.INPUTS
30-
None.
30+
The Path parameter.
3131
3232
.OUTPUTS
3333
None.
@@ -41,7 +41,7 @@ Add-PSRunScriptFile -Path 'D:\PowerShellRun\Build.ps1' -Icon '🧪' -Name 'Build
4141
function Add-PSRunScriptFile {
4242
[CmdletBinding()]
4343
param (
44-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
44+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
4545
[String]$Path,
4646

4747
[Parameter(ValueFromPipelineByPropertyName = $true)]

module/PowerShellRun/Public/Enable-PSRunEntry.ps1

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ By default, all categories are enabled.
1010
Specifies a category or an array of categories to enable.
1111
1212
.INPUTS
13-
None.
13+
The Category parameter.
1414
1515
.OUTPUTS
1616
None.
@@ -24,17 +24,36 @@ Enable-PSRunEntry -Category Application, Function, Utility
2424
function Enable-PSRunEntry {
2525
[CmdletBinding()]
2626
param (
27+
[Parameter(ValueFromPipeline = $true)]
2728
[ValidateSet('All', 'Application', 'Executable', 'Function', 'Utility', 'Favorite', 'Script', 'EntryGroup')]
2829
[String[]]$Category = 'All'
2930
)
3031

31-
if ($script:globalStore.IsEntriesInitialized()) {
32-
Write-Error -Message 'Entries already initialized. This function must be called only once.' -Category InvalidOperation
33-
return
34-
}
32+
begin {
33+
if ($script:globalStore.IsEntriesInitialized()) {
34+
Write-Error -Message 'Entries already initialized. This function must be called only once.' -Category InvalidOperation
35+
return
36+
}
3537

36-
if ($Category -contains 'All') {
37-
$Category = $script:globalStore.allCategoryNames
38+
$categories = [System.Collections.Generic.List[String]]::new()
39+
}
40+
process {
41+
if ($script:globalStore.IsEntriesInitialized()) {
42+
return
43+
}
44+
45+
foreach ($c in $Category) {
46+
$categories.Add($c)
47+
}
48+
}
49+
end {
50+
if ($script:globalStore.IsEntriesInitialized()) {
51+
return
52+
}
53+
54+
if ($categories -contains 'All') {
55+
$categories = $script:globalStore.allCategoryNames
56+
}
57+
$script:globalStore.InitializeEntries($categories)
3858
}
39-
$script:globalStore.InitializeEntries($Category)
4059
}

module/PowerShellRun/Public/Invoke-PSRun.ps1

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,47 @@ Invoke-PSRun
2020
function Invoke-PSRun {
2121
[CmdletBinding()]
2222
param (
23+
[Parameter(ValueFromPipelineByPropertyName = $true)]
2324
[String]$InitialQuery
2425
)
2526

26-
$script:globalStore.UpdateEntries()
27-
if ($script:globalStore.entries.Count -eq 0) {
28-
Write-Error -Message 'There is no entry.' -Category InvalidOperation
29-
return
30-
}
27+
process {
28+
$script:globalStore.UpdateEntries()
29+
if ($script:globalStore.entries.Count -eq 0) {
30+
Write-Error -Message 'There is no entry.' -Category InvalidOperation
31+
return
32+
}
3133

32-
if ($InitialQuery) {
33-
$prevContext = [PowerShellRun.SelectorContext]::new()
34-
$prevContext.Query = $InitialQuery
35-
} else {
36-
$prevContext = $null
37-
}
34+
if ($InitialQuery) {
35+
$prevContext = [PowerShellRun.SelectorContext]::new()
36+
$prevContext.Query = $InitialQuery
37+
} else {
38+
$prevContext = $null
39+
}
3840

39-
while ($true) {
40-
$mode = [PowerShellRun.SelectorMode]::SingleSelection
41-
$result = [PowerShellRun.Selector]::Open($script:globalStore.entries, $mode, $script:globalStore.psRunSelectorOption, $prevContext)
42-
$prevContext = $result.Context
41+
while ($true) {
42+
$mode = [PowerShellRun.SelectorMode]::SingleSelection
43+
$result = [PowerShellRun.Selector]::Open($script:globalStore.entries, $mode, $script:globalStore.psRunSelectorOption, $prevContext)
44+
$prevContext = $result.Context
4345

44-
if ($result.FocusedEntry) {
45-
$callback = $result.FocusedEntry.UserData.ScriptBlock
46-
$argumentList = @{
47-
Result = $result
48-
ArgumentList = $result.FocusedEntry.UserData.ArgumentList
46+
if ($result.FocusedEntry) {
47+
$callback = $result.FocusedEntry.UserData.ScriptBlock
48+
$argumentList = @{
49+
Result = $result
50+
ArgumentList = $result.FocusedEntry.UserData.ArgumentList
51+
}
52+
& $callback $argumentList
53+
54+
if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) {
55+
continue
56+
}
4957
}
50-
& $callback $argumentList
5158

52-
if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) {
59+
if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::Restart) {
60+
$prevContext = $null
5361
continue
5462
}
63+
break
5564
}
56-
57-
if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::Restart) {
58-
$prevContext = $null
59-
continue
60-
}
61-
break
6265
}
6366
}

module/PowerShellRun/Public/Invoke-PSRunPrompt.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ function Invoke-PSRunPrompt {
3131
[CmdletBinding()]
3232
[OutputType([PowerShellRun.PromptResult])]
3333
param (
34+
[Parameter(ValueFromPipelineByPropertyName = $true)]
3435
[PowerShellRun.SelectorOption]$Option = $script:globalStore.defaultSelectorOption,
3536

37+
[Parameter(ValueFromPipelineByPropertyName = $true)]
3638
[PowerShellRun.PromptContext]$Context
3739
)
3840

39-
$result = [PowerShellRun.Prompt]::Open($Option, $Context)
40-
$result
41+
process {
42+
$result = [PowerShellRun.Prompt]::Open($Option, $Context)
43+
$result
44+
}
4145
}

module/PowerShellRun/Public/Set-PSRunDefaultEditorScript.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following script is used by default:
1515
}
1616
1717
.INPUTS
18-
None.
18+
The ScriptBlock parameter.
1919
2020
.OUTPUTS
2121
None.
@@ -30,7 +30,7 @@ function Set-PSRunDefaultEditorScript {
3030
[CmdletBinding()]
3131
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
3232
param (
33-
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
33+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
3434
[ScriptBlock]$ScriptBlock
3535
)
3636

0 commit comments

Comments
 (0)