Skip to content

Commit 31d2cf1

Browse files
general refactoring
1 parent 850f911 commit 31d2cf1

File tree

16 files changed

+126
-132
lines changed

16 files changed

+126
-132
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
'Get-PSMDArgumentCompleter',
7373
'Get-PSMDAssembly',
7474
'Get-PSMDConstructor',
75-
'Get-PSMDHelpEx',
75+
'Get-PSMDHelp',
7676
'Get-PSMDMember',
7777
'Get-PSMDModuleDebug',
7878
'Get-PSMDTemplate',
@@ -136,7 +136,7 @@
136136
Tags = @('Development', 'Module')
137137

138138
# A URL to the license for this module.
139-
# LicenseUri = ''
139+
LicenseUri = 'https://github.com/PowershellFrameworkCollective/PSModuleDevelopment/blob/development/LICENSE'
140140

141141
# A URL to the main website for this project.
142142
ProjectUri = 'http://psframework.org'

PSModuleDevelopment/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22
##
33
- New: Export-PSMDString - Parses strings from modules using the PSFramework localization feature.
4+
- Upd: Refactored and updated the ModuleDebug component
5+
- Upd: Renamed Get-PSMDHelpEx to Get-PSMDHelp
46
- Upd: Template PSFProject - Adding `-IncludAZ` switch parameter to `vsts-packageFunction.ps1`, making the template include the AZ module as managed dependency.
57
- Upd: Refactored module structure to comply with current Fred Reference Architecture
68
- Upd: Template PSFTests - Added localization string tests

PSModuleDevelopment/functions/assembly/Find-PSMDType.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,4 @@
127127
}
128128
}
129129
}
130-
end
131-
{
132-
133-
}
134130
}

PSModuleDevelopment/functions/assembly/Get-PSMDAssembly.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
$Filter = "*"
2828
)
2929

30-
[appdomain]::CurrentDomain.GetAssemblies() | Where-Object FullName -Like $Filter
30+
process
31+
{
32+
[appdomain]::CurrentDomain.GetAssemblies() | Where-Object FullName -Like $Filter
33+
}
3134
}

PSModuleDevelopment/functions/help/Get-PSMDHelpEx.ps1 renamed to PSModuleDevelopment/functions/help/Get-PSMDHelp.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Function Get-PSMDHelpEx
1+
Function Get-PSMDHelp
22
{
33
<#
44
.SYNOPSIS
55
Displays localized information about Windows PowerShell commands and concepts.
66
77
.DESCRIPTION
8-
The Get-PSMDHelpEx function is a wrapper around get-help that allows localizing help queries.
8+
The Get-PSMDHelp function is a wrapper around get-help that allows localizing help queries.
99
This is especially useful when developing modules with help in multiple languages.
1010
1111
.PARAMETER Category
@@ -110,7 +110,7 @@
110110
This parameter is introduced in Windows PowerShell 3.0.
111111
112112
.EXAMPLE
113-
PS C:\> Get-PSMDHelpEx Get-Help "en-us" -Detailed
113+
PS C:\> Get-PSMDHelp Get-Help "en-us" -Detailed
114114
115115
Gets the detailed help text of Get-Help in English
116116
@@ -188,9 +188,7 @@
188188
}
189189

190190
# Prepare Splat for splatting a steppable pipeline
191-
$splat = $PSBoundParameters
192-
if ($splat.ContainsKey("Language")) { $null = $splat.Remove("Language") }
193-
if ($splat.ContainsKey("SetLanguage")) { $null = $splat.Remove("SetLanguage") }
191+
$splat = $PSBoundParameters | ConvertTo-PSFHashtable -Exclude Language, SetLanguage
194192

195193
try
196194
{
@@ -212,4 +210,4 @@
212210
catch { throw }
213211
}
214212
}
215-
New-Alias -Name hex -Value Get-PSMDHelpEx -Scope Global -Option AllScope
213+
New-Alias -Name hex -Value Get-PSMDHelp -Scope Global -Option AllScope

PSModuleDevelopment/functions/moduledebug/Get-PSMDModuleDebug.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
PS C:\> Get-PSMDModuleDebug -Filter *net*
1616
1717
Returns the module debugging configuration for all modules with a name that contains "net"
18-
19-
.NOTES
20-
Version 1.1.0.0
21-
Author: Friedrich Weinmann
22-
Created on: August 7th, 2016
2318
#>
2419
[CmdletBinding()]
2520
Param (
2621
[string]
2722
$Filter = "*"
2823
)
2924

30-
Import-Clixml $PSModuleDevelopment_ModuleConfigPath | Where-Object { ($_.Name -like $Filter) -and ($_.Name.Length -gt 0) }
25+
process
26+
{
27+
Import-Clixml -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath') | Where-Object {
28+
($_.Name -like $Filter) -and ($_.Name.Length -gt 0)
29+
}
30+
}
3131
}

PSModuleDevelopment/functions/moduledebug/Import-PSMDModuleDebug.ps1

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,31 @@
1414
PS C:\> Import-PSMDModuleDebug -Name 'cPSNetwork'
1515
1616
Imports the cPSNetwork module as it was configured to be imported using Set-ModuleDebug.
17-
18-
.NOTES
19-
Version 1.0.0.0
20-
Author: Friedrich Weinmann
21-
Created on: August 7th, 2016
2217
#>
2318
[CmdletBinding()]
24-
Param (
19+
param (
2520
[string]
2621
$Name
2722
)
2823

29-
# Get original module configuration
30-
$____module = $null
31-
$____module = Import-Clixml $PSModuleDevelopment_ModuleConfigPath | Where-Object { $_.Name -eq $Name }
32-
if (-not $____module) { throw "No matching module configuration found" }
33-
34-
# Process entry
35-
if ($____module.DebugMode) { Set-Variable -Scope Global -Name "$($____module.Name)_DebugMode" -Value $____module.DebugMode -Force }
36-
if ($____module.PreImportAction)
24+
process
3725
{
38-
[System.Management.Automation.ScriptBlock]::Create($____module.PreImportAction).Invoke()
39-
}
40-
Import-Module -Name $____module.Name -Scope Global
41-
if ($____module.PostImportAction)
42-
{
43-
[System.Management.Automation.ScriptBlock]::Create($____module.PostImportAction).Invoke()
26+
# Get original module configuration
27+
$____module = $null
28+
$____module = Import-Clixml -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath') | Where-Object { $_.Name -eq $Name }
29+
if (-not $____module) { throw "No matching module configuration found" }
30+
31+
# Process entry
32+
if ($____module.DebugMode) { Set-Variable -Scope Global -Name "$($____module.Name)_DebugMode" -Value $____module.DebugMode -Force }
33+
if ($____module.PreImportAction)
34+
{
35+
[System.Management.Automation.ScriptBlock]::Create($____module.PreImportAction).Invoke()
36+
}
37+
Import-Module -Name $____module.Name -Scope Global
38+
if ($____module.PostImportAction)
39+
{
40+
[System.Management.Automation.ScriptBlock]::Create($____module.PostImportAction).Invoke()
41+
}
4442
}
4543
}
4644
New-Alias -Name ipmod -Value Import-ModuleDebug -Option AllScope -Scope Global

PSModuleDevelopment/functions/moduledebug/Remove-PSMDModuleDebug.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535

3636
Begin
3737
{
38-
$allModules = Import-Clixml -Path $PSModuleDevelopment_ModuleConfigPath
38+
$allModules = Import-Clixml -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
3939
}
4040
Process
4141
{
42-
foreach ($n in $Name)
42+
foreach ($nameItem in $Name)
4343
{
44-
($allModules) | Where-Object { $_.Name -like $n } | ForEach-Object {
45-
if ($PSCmdlet.ShouldProcess($_.Name, "Remove from list of modules configured for debugging"))
44+
($allModules) | Where-Object { $_.Name -like $nameItem } | ForEach-Object {
45+
if (Test-PSFShouldProcess -Target $_.Name -Action 'Remove from list of modules configured for debugging' -PSCmdlet $PSCmdlet)
4646
{
4747
$Module = $_
4848
$allModules = $allModules | Where-Object { $_ -ne $Module }
@@ -52,6 +52,6 @@
5252
}
5353
End
5454
{
55-
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath -Depth 99
55+
Export-Clixml -InputObject $allModules -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath') -Depth 99
5656
}
5757
}

PSModuleDevelopment/functions/moduledebug/Set-PSMDModuleDebug.ps1

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,10 @@
6464
6565
Note: Using Write-Host is generally - but not always - bad practice
6666
Note: Verbose output during module import is generally discouraged (doesn't apply to tests of course)
67-
68-
.NOTES
69-
Version 1.1.0.0
70-
Author: Friedrich Weinmann
71-
Created on: August 7th, 2016
7267
#>
73-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
7468
[CmdletBinding(DefaultParameterSetName = "Name", SupportsShouldProcess = $true)]
7569
Param (
76-
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Name")]
70+
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = "Name", ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
7771
[Alias('n')]
7872
[string]
7973
$Name,
@@ -113,68 +107,74 @@
113107
$NoneAutoImport
114108
)
115109

116-
#region AllAutoImport
117-
if ($AllAutoImport)
110+
process
118111
{
119-
$allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
120-
if ($PSCmdlet.ShouldProcess(($allModules.Name -join ", "), "Configuring modules to automatically import"))
112+
#region AllAutoImport
113+
if ($AllAutoImport)
121114
{
122-
foreach ($module in $allModules)
115+
$allModules = Import-Clixml (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
116+
if (Test-PSFShouldProcess -Target ($allModules.Name -join ", ") -Action "Configuring modules to automatically import" -PSCmdlet $PSCmdlet)
123117
{
124-
$module.AutoImport = $true
118+
foreach ($module in $allModules)
119+
{
120+
$module.AutoImport = $true
121+
}
122+
Export-Clixml -InputObject $allModules -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
125123
}
126-
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath
124+
return
127125
}
128-
}
129-
#endregion AllAutoImport
130-
131-
#region NoneAutoImport
132-
if ($NoneAutoImport)
133-
{
134-
$allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
135-
if ($PSCmdlet.ShouldProcess(($allModules.Name -join ", "), "Configuring modules to not automatically import"))
126+
#endregion AllAutoImport
127+
128+
#region NoneAutoImport
129+
if ($NoneAutoImport)
136130
{
137-
foreach ($module in $allModules)
131+
$allModules = Import-Clixml -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
132+
if (Test-PSFShouldProcess -Target ($allModules.Name -join ", ") -Action "Configuring modules to not automatically import" -PSCmdlet $PSCmdlet)
138133
{
139-
$module.AutoImport = $false
134+
foreach ($module in $allModules)
135+
{
136+
$module.AutoImport = $false
137+
}
138+
Export-Clixml -InputObject $allModules -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
140139
}
141-
Export-Clixml -InputObject $allModules -Path $PSModuleDevelopment_ModuleConfigPath
140+
return
142141
}
143-
}
144-
#endregion NoneAutoImport
145-
146-
#region Name
147-
# Import all module-configurations
148-
$allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
149-
150-
# If a configuration already exists, change only those values that were specified
151-
if ($module = $allModules | Where-Object { $_.Name -eq $Name })
152-
{
153-
if (Test-PSFParameterBinding -ParameterName "AutoImport") { $module.AutoImport = $AutoImport.ToBool() }
154-
if (Test-PSFParameterBinding -ParameterName "DebugMode") { $module.DebugMode = $DebugMode.ToBool() }
155-
if (Test-PSFParameterBinding -ParameterName "PreImportAction") { $module.PreImportAction = $PreImportAction }
156-
if (Test-PSFParameterBinding -ParameterName "PostImportAction") { $module.PostImportAction = $PostImportAction }
157-
if (Test-PSFParameterBinding -ParameterName "Priority") { $module.Priority = $Priority }
158-
}
159-
# If no configuration exists yet, create a new one with all parameters as specified
160-
else
161-
{
162-
$module = New-Object PSObject -Property @{
163-
Name = $Name
164-
AutoImport = $AutoImport.ToBool()
165-
DebugMode = $DebugMode.ToBool()
166-
PreImportAction = $PreImportAction
167-
PostImportAction = $PostImportAction
168-
Priority = $Priority
142+
#endregion NoneAutoImport
143+
144+
#region Name
145+
# Import all module-configurations
146+
$allModules = Import-Clixml -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
147+
148+
# If a configuration already exists, change only those values that were specified
149+
if ($module = $allModules | Where-Object Name -eq $Name)
150+
{
151+
if (Test-PSFParameterBinding -ParameterName "AutoImport") { $module.AutoImport = $AutoImport.ToBool() }
152+
if (Test-PSFParameterBinding -ParameterName "DebugMode") { $module.DebugMode = $DebugMode.ToBool() }
153+
if (Test-PSFParameterBinding -ParameterName "PreImportAction") { $module.PreImportAction = $PreImportAction }
154+
if (Test-PSFParameterBinding -ParameterName "PostImportAction") { $module.PostImportAction = $PostImportAction }
155+
if (Test-PSFParameterBinding -ParameterName "Priority") { $module.Priority = $Priority }
169156
}
170-
}
171-
172-
# Add new module configuration to all (if any) other previous configurations and export it to config file
173-
$newModules = @(($allModules | Where-Object { $_.Name -ne $Name }), $module)
174-
if ($PSCmdlet.ShouldProcess($name, "Changing debug settings for module"))
175-
{
176-
Export-Clixml -InputObject $newModules -Path $PSModuleDevelopment_ModuleConfigPath
177-
}
178-
#endregion Name
157+
# If no configuration exists yet, create a new one with all parameters as specified
158+
else
159+
{
160+
$module = [pscustomobject]@{
161+
Name = $Name
162+
AutoImport = $AutoImport.ToBool()
163+
DebugMode = $DebugMode.ToBool()
164+
PreImportAction = $PreImportAction
165+
PostImportAction = $PostImportAction
166+
Priority = $Priority
167+
}
168+
}
169+
170+
# Add new module configuration to all (if any) other previous configurations and export it to config file
171+
$newModules = @(($allModules | Where-Object Name -ne $Name), $module)
172+
173+
if (Test-PSFShouldProcess -Target $name -Action "Changing debug settings for module" -PSCmdlet $PSCmdlet)
174+
{
175+
Export-Clixml -InputObject $newModules -Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.ConfigPath')
176+
}
177+
#endregion Name
178+
}
179179
}
180180
Set-Alias -Name smd -Value Set-PSMDModuleDebug -Option AllScope -Scope Global
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-

1+
Set-PSFConfig -Module PSModuleDevelopment -Name 'Debug.ConfigPath' -Value "$($path_FileUserShared)\InfernalAssociates\PowerShell\PSModuleDevelopment\config.xml" -Initialize -Validation string -Description 'The path to where the module debugging information is being stored. Used in the *-PSMDModuleDebug commands.'

0 commit comments

Comments
 (0)