Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The parent entry group object where this new entry group is added.
Returns the added entry group if specified.

.INPUTS
None.
The Name parameter.

.OUTPUTS
An object that represents an entry group if PassThru is specified. None otherwise.
Expand All @@ -46,7 +46,7 @@ function Add-PSRunEntryGroup {
[Parameter(ValueFromPipelineByPropertyName = $true)]
[String]$Icon,

[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$Name,

[Parameter(ValueFromPipelineByPropertyName = $true)]
Expand Down
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The custom preview string.
The parent entry group object where this new entry is added.

.INPUTS
None.
The Path parameter.

.OUTPUTS
None.
Expand All @@ -38,7 +38,7 @@ Add-PSRunFavoriteFile -Path 'D:\PowerShellRun\Build.ps1' -Icon '🧪' -Name 'Bui
function Add-PSRunFavoriteFile {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$Path,

[Parameter(ValueFromPipelineByPropertyName = $true)]
Expand Down
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The custom preview string.
The parent entry group object where this new entry is added.

.INPUTS
None.
The Path parameter.

.OUTPUTS
None.
Expand All @@ -38,7 +38,7 @@ Add-PSRunFavoriteFolder -Path 'D:/Download' -Icon '🌐'
function Add-PSRunFavoriteFolder {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$Path,

[Parameter(ValueFromPipelineByPropertyName = $true)]
Expand Down
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Add-PSRunFunction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The custom preview string.
The parent entry group object where this new entry is added.

.INPUTS
None.
The FunctionName parameter.

.OUTPUTS
None.
Expand All @@ -41,7 +41,7 @@ Add-PSRunFunction -FunctionName TestFunction -Icon '🍏' -Name 'Test Function'
function Add-PSRunFunction {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$FunctionName,

[Parameter(ValueFromPipelineByPropertyName = $true)]
Expand Down
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The custom preview string. The definition of the ScriptBlock is used by default.
The parent entry group object where this new entry is added.

.INPUTS
None.
The ScriptBlock parameter.

.OUTPUTS
None.
Expand All @@ -43,7 +43,7 @@ Add-PSRunScriptBlock -Icon '🥏' -Name 'GitPullRebase' -Description 'git pull w
function Add-PSRunScriptBlock {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ScriptBlock]$ScriptBlock,

[Parameter(ValueFromPipelineByPropertyName = $true)]
Expand Down
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Add-PSRunScriptFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The custom preview string. The content of the script file is used by default.
The parent entry group object where this new entry is added.

.INPUTS
None.
The Path parameter.

.OUTPUTS
None.
Expand All @@ -41,7 +41,7 @@ Add-PSRunScriptFile -Path 'D:\PowerShellRun\Build.ps1' -Icon '🧪' -Name 'Build
function Add-PSRunScriptFile {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$Path,

[Parameter(ValueFromPipelineByPropertyName = $true)]
Expand Down
35 changes: 27 additions & 8 deletions module/PowerShellRun/Public/Enable-PSRunEntry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ By default, all categories are enabled.
Specifies a category or an array of categories to enable.

.INPUTS
None.
The Category parameter.

.OUTPUTS
None.
Expand All @@ -24,17 +24,36 @@ Enable-PSRunEntry -Category Application, Function, Utility
function Enable-PSRunEntry {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true)]
[ValidateSet('All', 'Application', 'Executable', 'Function', 'Utility', 'Favorite', 'Script', 'EntryGroup')]
[String[]]$Category = 'All'
)

if ($script:globalStore.IsEntriesInitialized()) {
Write-Error -Message 'Entries already initialized. This function must be called only once.' -Category InvalidOperation
return
}
begin {
if ($script:globalStore.IsEntriesInitialized()) {
Write-Error -Message 'Entries already initialized. This function must be called only once.' -Category InvalidOperation
return
}

if ($Category -contains 'All') {
$Category = $script:globalStore.allCategoryNames
$categories = [System.Collections.Generic.List[String]]::new()
}
process {
if ($script:globalStore.IsEntriesInitialized()) {
return
}

foreach ($c in $Category) {
$categories.Add($c)
}
}
end {
if ($script:globalStore.IsEntriesInitialized()) {
return
}

if ($categories -contains 'All') {
$categories = $script:globalStore.allCategoryNames
}
$script:globalStore.InitializeEntries($categories)
}
$script:globalStore.InitializeEntries($Category)
}
59 changes: 31 additions & 28 deletions module/PowerShellRun/Public/Invoke-PSRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,47 @@ Invoke-PSRun
function Invoke-PSRun {
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName = $true)]
[String]$InitialQuery
)

$script:globalStore.UpdateEntries()
if ($script:globalStore.entries.Count -eq 0) {
Write-Error -Message 'There is no entry.' -Category InvalidOperation
return
}
process {
$script:globalStore.UpdateEntries()
if ($script:globalStore.entries.Count -eq 0) {
Write-Error -Message 'There is no entry.' -Category InvalidOperation
return
}

if ($InitialQuery) {
$prevContext = [PowerShellRun.SelectorContext]::new()
$prevContext.Query = $InitialQuery
} else {
$prevContext = $null
}
if ($InitialQuery) {
$prevContext = [PowerShellRun.SelectorContext]::new()
$prevContext.Query = $InitialQuery
} else {
$prevContext = $null
}

while ($true) {
$mode = [PowerShellRun.SelectorMode]::SingleSelection
$result = [PowerShellRun.Selector]::Open($script:globalStore.entries, $mode, $script:globalStore.psRunSelectorOption, $prevContext)
$prevContext = $result.Context
while ($true) {
$mode = [PowerShellRun.SelectorMode]::SingleSelection
$result = [PowerShellRun.Selector]::Open($script:globalStore.entries, $mode, $script:globalStore.psRunSelectorOption, $prevContext)
$prevContext = $result.Context

if ($result.FocusedEntry) {
$callback = $result.FocusedEntry.UserData.ScriptBlock
$argumentList = @{
Result = $result
ArgumentList = $result.FocusedEntry.UserData.ArgumentList
if ($result.FocusedEntry) {
$callback = $result.FocusedEntry.UserData.ScriptBlock
$argumentList = @{
Result = $result
ArgumentList = $result.FocusedEntry.UserData.ArgumentList
}
& $callback $argumentList

if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) {
continue
}
}
& $callback $argumentList

if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) {
if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::Restart) {
$prevContext = $null
continue
}
break
}

if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::Restart) {
$prevContext = $null
continue
}
break
}
}
8 changes: 6 additions & 2 deletions module/PowerShellRun/Public/Invoke-PSRunPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ function Invoke-PSRunPrompt {
[CmdletBinding()]
[OutputType([PowerShellRun.PromptResult])]
param (
[Parameter(ValueFromPipelineByPropertyName = $true)]
[PowerShellRun.SelectorOption]$Option = $script:globalStore.defaultSelectorOption,

[Parameter(ValueFromPipelineByPropertyName = $true)]
[PowerShellRun.PromptContext]$Context
)

$result = [PowerShellRun.Prompt]::Open($Option, $Context)
$result
process {
$result = [PowerShellRun.Prompt]::Open($Option, $Context)
$result
}
}
4 changes: 2 additions & 2 deletions module/PowerShellRun/Public/Set-PSRunDefaultEditorScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following script is used by default:
}

.INPUTS
None.
The ScriptBlock parameter.

.OUTPUTS
None.
Expand All @@ -30,7 +30,7 @@ function Set-PSRunDefaultEditorScript {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ScriptBlock]$ScriptBlock
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Use this command to see what properties are available:
[PowerShellRun.SelectorOption]::new() | Get-Member -MemberType Properties

.INPUTS
None.
The Option parameter.

.OUTPUTS
None.
Expand All @@ -26,7 +26,7 @@ function Set-PSRunDefaultSelectorOption {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[PowerShellRun.SelectorOption]$Option
)

Expand Down
9 changes: 9 additions & 0 deletions tests/Public/Add-PSRunEntryGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
$group | Should -Not -BeNullOrEmpty
}

It 'should accept a pipeline input' {
Enable-PSRunEntry -Category EntryGroup
'Custom Name' | Add-PSRunEntryGroup
InModuleScope 'PowerShellRun' {
$registry = $script:globalStore.GetRegistry('EntryGroupRegistry')
$registry.entries.Count | Should -Be 1
}
}

AfterEach {
Remove-Module PowerShellRun -Force
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Public/Add-PSRunFavoriteFile.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
}
}

It 'should accept a pipeline input' {
Enable-PSRunEntry -Category Favorite
'C:/folder/test.txt' | Add-PSRunFavoriteFile
InModuleScope 'PowerShellRun' {
$registry = $script:globalStore.GetRegistry('FileSystemRegistry')
$registry.favoritesEntries.Count | Should -Be 1
}
}

AfterEach {
Remove-Module PowerShellRun -Force
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Public/Add-PSRunFavoriteFolder.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
}
}

It 'should accept a pipeline input' {
Enable-PSRunEntry -Category Favorite
'C:/folder' | Add-PSRunFavoriteFolder
InModuleScope 'PowerShellRun' {
$registry = $script:globalStore.GetRegistry('FileSystemRegistry')
$registry.favoritesEntries.Count | Should -Be 1
}
}

AfterEach {
Remove-Module PowerShellRun -Force
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Public/Add-PSRunFunction.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
$function:Test = $null
}

It 'should accept a pipeline input' {
Enable-PSRunEntry -Category Function
function global:Test {}
'Test' | Add-PSRunFunction
InModuleScope 'PowerShellRun' {
$registry = $script:globalStore.GetRegistry('FunctionRegistry')
$registry.entries.Count | Should -Be 1
}
$function:Test = $null
}

AfterEach {
Remove-Module PowerShellRun -Force
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Public/Add-PSRunScriptBlock.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
}
}

It 'should accept a pipeline input' {
Enable-PSRunEntry -Category Script
{ 'hello' } | Add-PSRunScriptBlock -Name 'Custom Name'
InModuleScope 'PowerShellRun' {
$registry = $script:globalStore.GetRegistry('ScriptRegistry')
$registry.entries.Count | Should -Be 1
}
}

AfterEach {
Remove-Module PowerShellRun -Force
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Public/Add-PSRunScriptFile.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
}
}

It 'should accept a pipeline input' {
Enable-PSRunEntry -Category Script
'D:/test.ps1' | Add-PSRunScriptFile
InModuleScope 'PowerShellRun' {
$registry = $script:globalStore.GetRegistry('ScriptRegistry')
$registry.entries.Count | Should -Be 1
}
}

AfterEach {
Remove-Module PowerShellRun -Force
}
Expand Down
Loading