Skip to content

Commit ee5b116

Browse files
author
FriedrichWeinmann
committed
Added new command
1 parent edc2376 commit ee5b116

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
# Functions to export from this module
6464
FunctionsToExport = @(
6565
'Expand-PSMDTypeName',
66+
'Find-PSMDFileContent',
6667
'Get-HelpEx',
6768
'Get-ModuleDebug',
6869
'Import-ModuleDebug',
@@ -88,8 +89,9 @@
8889

8990
# Aliases to export from this module
9091
AliasesToExport = @(
91-
'hex',
92+
'find',
9293
'Get-ExHelp',
94+
'hex',
9395
'Restart-Shell',
9496
'rss',
9597
'ipmod',

PSModuleDevelopment/PSModuleDevelopment.psproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
<File Build="2" Shared="True" ReferenceFunction="Invoke-Split-PSMDScriptFile_ps1">functions\refactor\Split-PSMDScriptFile.ps1</File>
5353
<File Build="2">bin\PSModuleDevelopment.dll</File>
5454
<File Build="2" Shared="True" ReferenceFunction="Invoke-New-PSMDHeader_ps1">functions\utility\New-PSMDHeader.ps1</File>
55+
<File Build="2" Shared="True" ReferenceFunction="Invoke-Find-PSMDFileContent_ps1">functions\utility\Find-PSMDFileContent.ps1</File>
56+
<File Build="2" Shared="True" ReferenceFunction="Invoke-utility_ps1">internal\configurations\utility.ps1</File>
5557
</Files>
5658
<StartupScript>F:\Synchronized Data\Scripte\Powershell Studio\Projects\PSModuleDevelopment\Test-Module.ps1</StartupScript>
5759
</Project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
function Find-PSMDFileContent
2+
{
3+
<#
4+
.SYNOPSIS
5+
Used to quickly search in module files.
6+
7+
.DESCRIPTION
8+
This function can be used to quickly search files in your module's path.
9+
By using Set-PSMDModulePath (or Set-PSFConfig 'PSModuleDevelopment.Module.Path' '<path>') you can set the default path to search in.
10+
Using
11+
Register-PSFConfig -FullName 'PSModuleDevelopment.Module.Path'
12+
allows you to persist this setting across sessions.
13+
14+
.PARAMETER Pattern
15+
The text to search for, can be any regex pattern
16+
17+
.PARAMETER Extension
18+
The extension of files to consider.
19+
Only files with this extension will be searched.
20+
21+
.PARAMETER Path
22+
The path to use as search base.
23+
Defaults to the path found in the setting 'PSModuleDevelopment.Module.Path'
24+
25+
.PARAMETER EnableException
26+
Replaces user friendly yellow warnings with bloody red exceptions of doom!
27+
Use this if you want the function to throw terminating errors you want to catch.
28+
29+
.EXAMPLE
30+
PS C:\> Find-PSMDFileContent -Pattern 'Get-Test'
31+
32+
Searches all module files for the string 'Get-Test'.
33+
#>
34+
[CmdletBinding()]
35+
Param (
36+
[Parameter(Mandatory = $true, Position = 0)]
37+
[string]
38+
$Pattern,
39+
40+
[string[]]
41+
$Extension = @(".ps1", ".psd1", ".psm1"),
42+
43+
[string]
44+
$Path = (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Module.Path'),
45+
46+
[switch]
47+
$EnableException
48+
)
49+
50+
begin
51+
{
52+
if (-not (Test-Path -Path $Path))
53+
{
54+
Stop-PSFFunction -Message "Path not found: $Path" -EnableException $EnableException -Category InvalidArgument -Tag "fail", "path", "argument"
55+
return
56+
}
57+
}
58+
process
59+
{
60+
if (Test-PSFFunctionInterrupt) { return }
61+
62+
Get-ChildItem -Path $Path -Recurse | Where-Object Extension -In $Extension | Select-String -Pattern $Pattern
63+
}
64+
end
65+
{
66+
if (Test-PSFFunctionInterrupt) { return }
67+
}
68+
}
69+
New-Alias -Name find -Value Find-PSMDFileContent -Scope Global -Option AllScope

PSModuleDevelopment/functions/utility/New-PssModuleProject.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
$Force
6969
)
7070

71-
if (-not $PSBoundParameters.ContainsKey("Path"))
71+
if (Test-PSFParameterBinding -ParameterName "Path" -Not)
7272
{
7373
try
7474
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value "" -Initialize -Validation "string" -Handler { } -Description "The path to the module currently under development. Used as default path by commnds that work within a module directory."

0 commit comments

Comments
 (0)