Skip to content

Commit 568ce32

Browse files
Merge pull request #63 from PowershellFrameworkCollective/Set-PSMDModulePath
Update Set-PSModulePath
2 parents c142946 + 1a3a964 commit 568ce32

File tree

2 files changed

+60
-34
lines changed

2 files changed

+60
-34
lines changed

PSModuleDevelopment/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22
## 2.2.?.?
3+
- Upd: Set-PSMDModulePath - add `-Module` parameter to persist the setting
4+
- Upd: Set-PSMDModulePath - add `-Register` parameter for integrated persistence
35
- Upd: Set-PSMDEncoding - use `PSFEncoding` parameter class & tabcompletion
46
- Upd: Template PSFProject - build directly into psm1
57
- Upd: Template PSFProject, PSFModule - automatically read version in psm1 from psd1, rather than requiring explicit maintenance.
Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,80 @@
11
function Set-PSMDModulePath
22
{
3-
<#
4-
.SYNOPSIS
5-
Sets the path of the module currently being developed.
6-
7-
.DESCRIPTION
8-
Sets the path of the module currently being developed.
9-
This is used by several utility commands in order to not require any path input.
3+
<#
4+
.SYNOPSIS
5+
Sets the path of the module currently being developed.
106
11-
This is a wrapper around the psframework configuration system, the same action can be taken by running this command:
12-
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Path
13-
14-
.PARAMETER Path
15-
The path to set as currently developed module.
7+
.DESCRIPTION
8+
Sets the path of the module currently being developed.
9+
This is used by several utility commands in order to not require any path input.
1610
17-
.PARAMETER EnableException
18-
Replaces user friendly yellow warnings with bloody red exceptions of doom!
19-
Use this if you want the function to throw terminating errors you want to catch.
20-
21-
.EXAMPLE
22-
Set-PSMDModulePath -Path "C:\github\dbatools"
11+
This is a wrapper around the psframework configuration system, the same action can be taken by running this command:
12+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Path
13+
14+
.PARAMETER Module
15+
The module, the path of which to register.
2316
24-
Sets the current module path to "C:\github\dbatools"
17+
.PARAMETER Path
18+
The path to set as currently developed module.
2519
26-
.EXAMPLE
27-
Set-PSMDModulePath -Path "C:\github\dbatools"
28-
Register-PSFConfig -FullName 'PSModuleDevelopment.Module.Path'
20+
.PARAMETER Register
21+
Register the specified path, to have it persist across sessions
22+
23+
.PARAMETER EnableException
24+
Replaces user friendly yellow warnings with bloody red exceptions of doom!
25+
Use this if you want the function to throw terminating errors you want to catch.
26+
27+
.EXAMPLE
28+
Set-PSMDModulePath -Path "C:\github\dbatools"
29+
30+
Sets the current module path to "C:\github\dbatools"
2931
30-
Sets the current module path to "C:\github\dbatools"
31-
Then stores the setting in registry, causing it to be persisted acros multiple sessions.
32-
#>
32+
.EXAMPLE
33+
Set-PSMDModulePath -Path "C:\github\dbatools" -Register
34+
35+
Sets the current module path to "C:\github\dbatools"
36+
Then stores the setting in registry, causing it to be persisted acros multiple sessions.
37+
#>
3338
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
3439
[CmdletBinding()]
35-
Param (
36-
[Parameter(Mandatory = $true)]
40+
param (
41+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Module')]
42+
[System.Management.Automation.PSModuleInfo]
43+
$Module,
44+
45+
[Parameter(Mandatory = $true, ParameterSetName = 'Path')]
3746
[string]
3847
$Path,
3948

49+
[switch]
50+
$Register,
51+
4052
[switch]
4153
$EnableException
4254
)
4355

44-
$resolvedPath = Resolve-Path -Path $Path
45-
if (Test-Path -Path $resolvedPath)
56+
process
4657
{
47-
if ((Get-Item $resolvedPath).PSIsContainer)
58+
if ($Path)
4859
{
49-
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $resolvedPath
60+
$resolvedPath = Resolve-PSFPath -Path $Path -Provider FileSystem -SingleItem
61+
if (Test-Path -Path $resolvedPath)
62+
{
63+
if ((Get-Item $resolvedPath).PSIsContainer)
64+
{
65+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $resolvedPath
66+
if ($Register) { Register-PSFConfig -Module 'PSModuleDevelopment' -Name 'Module.Path' }
67+
return
68+
}
69+
}
70+
71+
Stop-PSFFunction -Target $Path -Message "Could not validate/resolve path: $Path" -EnableException $EnableException -Category InvalidArgument
5072
return
5173
}
74+
else
75+
{
76+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Module.ModuleBase
77+
if ($Register) { Register-PSFConfig -Module 'PSModuleDevelopment' -Name 'Module.Path' }
78+
}
5279
}
53-
54-
Stop-PSFFunction -Target $Path -Message "Could not validate/resolve path: $Path" -EnableException $EnableException -Category InvalidArgument
55-
return
5680
}

0 commit comments

Comments
 (0)