Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichWeinmann committed Dec 30, 2024
1 parent c34d96c commit e653d5d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
35 changes: 32 additions & 3 deletions PSFramework.NuGet/functions/Get/Install-PSFModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@
begin {
throw "Not implemented yet!"

$killIt = $ErrorActionPreference -eq 'Stop'
$cleanedUp = $false

# Resolution only happens to early detect impossible parameterization. Will be called again in Save-PSFModule.
$null = Resolve-Repository -Name $Repository -Type $Type -Cmdlet $PSCmdlet # Terminates if no repositories found
$managedSessions = New-ManagedSession -ComputerName $ComputerName -Credential $RemotingCredential -Cmdlet $PSCmdlet -Type Temporary
if ($ComputerName -and -not $managedSessions) {
Stop-PSFFunction -String 'Install-PSFModule.Error.NoComputerValid' -EnableException ($ErrorActionPreference -eq 'Stop') -Cmdlet $PSCmdlet
Stop-PSFFunction -String 'Install-PSFModule.Error.NoComputerValid' -EnableException $killIt -Cmdlet $PSCmdlet
return
}
$resolvedPaths = Resolve-ModuleScopePath -Scope $Scope -ManagedSession $managedSessions -TargetHandling Any -Cmdlet $PSCmdlet # Errors for bad paths, terminates if no path
Expand All @@ -76,9 +79,35 @@
process {
if (Test-PSFFunctionInterrupt) { return }

#TODO: Implement
#region Start Nested Save-PSFModule
if (-not $command) {
$command = { Save-PSFModule @saveParam -PathInternal $resolvedPaths -Cmdlet $PSCmdlet -ErrorAction $ErrorActionPreference }.GetSteppablePipeline()
try { $command.Begin((-not $Name)) }
catch {
if (-not $cleanedUp -and $managedSessions) { $managedSessions | Where-Object Type -EQ 'Temporary' | ForEach-Object Session | Remove-PSSession }
$cleanedUp = $true
Stop-PSFFunction -String 'Install-PSFModule.Error.Setup' -ErrorRecord $_ -EnableException $killIt -Cmdlet $PSCmdlet
return
}
}
#endregion Start Nested Save-PSFModule

#region Execute Process
try {
if ($Name) { $command.Process() }
else { $command.Process($InputObject) }
}
catch {
if (-not $cleanedUp -and $managedSessions) { $managedSessions | Where-Object Type -EQ 'Temporary' | ForEach-Object Session | Remove-PSSession }
$cleanedUp = $true
Stop-PSFFunction -String 'Install-PSFModule.Error.Installation' -ErrorRecord $_ -EnableException $killIt -Cmdlet $PSCmdlet
return
}
#endregion Execute Process
}
end {

if (-not $cleanedUp -and $managedSessions) { $managedSessions | Where-Object Type -EQ 'Temporary' | ForEach-Object Session | Remove-PSSession }
if (Test-PSFFunctionInterrupt) { return }
$null = $command.End()
}
}
29 changes: 19 additions & 10 deletions PSFramework.NuGet/functions/Get/Save-PSFModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
For internal use only.
Used to pass scope-based path resolution from Install-PSFModule into Save-PSFModule.
.PARAMETER Cmdlet
The $PSCmdlet variable of the calling command, used to ensure errors happen within the scope of the caller, hiding this command from the user.
Should be used when trying to hide Save-PSFModule - e.g. when called from Install-PSFModule.
.PARAMETER WhatIf
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
Expand Down Expand Up @@ -206,21 +210,26 @@
$InputObject,

[Parameter(DontShow = $true)]
$PathInternal
$PathInternal,

[Parameter(DontShow = $true)]
$Cmdlet = $PSCmdlet
)

begin {
$repositories = Resolve-Repository -Name $Repository -Type $Type -Cmdlet $PSCmdlet # Terminates if no repositories found
$repositories = Resolve-Repository -Name $Repository -Type $Type -Cmdlet $Cmdlet # Terminates if no repositories found
if ($PathInternal) {
$resolvedPaths = $PathInternal
$shouldProcessMessage = "Saving modules to $(@($PathInternal)[0].Scope)"
}
else {
$managedSessions = New-ManagedSession -ComputerName $ComputerName -Credential $RemotingCredential -Cmdlet $PSCmdlet -Type Temporary
$shouldProcessMessage = "Saving modules to $Path"
$managedSessions = New-ManagedSession -ComputerName $ComputerName -Credential $RemotingCredential -Cmdlet $Cmdlet -Type Temporary
if ($ComputerName -and -not $managedSessions) {
Stop-PSFFunction -String 'Save-PSFModule.Error.NoComputerValid' -EnableException ($ErrorActionPreference -eq 'Stop') -Cmdlet $PSCmdlet
Stop-PSFFunction -String 'Save-PSFModule.Error.NoComputerValid' -EnableException ($ErrorActionPreference -eq 'Stop') -Cmdlet $Cmdlet
return
}
$resolvedPaths = Resolve-RemotePath -Path $Path -ComputerName $managedSessions.Session -ManagedSession $managedSessions -TargetHandling Any -Cmdlet $PSCmdlet # Errors for bad paths, terminates if no path
$resolvedPaths = Resolve-RemotePath -Path $Path -ComputerName $managedSessions.Session -ManagedSession $managedSessions -TargetHandling Any -Cmdlet $Cmdlet # Errors for bad paths, terminates if no path
}

$tempDirectory = New-PSFTempDirectory -Name Staging -ModuleName PSFramework.NuGet
Expand All @@ -230,15 +239,15 @@

try {
$installData = switch ($PSCmdlet.ParameterSetName) {
ByObject { Resolve-ModuleTarget -InputObject $InputObject -Cmdlet $PSCmdlet }
ByName { Resolve-ModuleTarget -Name $Name -Version $Version -Prerelease:$Prerelease -Cmdlet $PSCmdlet }
ByObject { Resolve-ModuleTarget -InputObject $InputObject -Cmdlet $Cmdlet }
ByName { Resolve-ModuleTarget -Name $Name -Version $Version -Prerelease:$Prerelease -Cmdlet $Cmdlet }
}
if (-not $PSCmdlet.ShouldProcess(($installData.TargetName -join ', '), "Saving modules to $Path")) {
if (-not $Cmdlet.ShouldProcess(($installData.TargetName -join ', '), $shouldProcessMessage)) {
return
}

Save-StagingModule -InstallData $installData -Path $tempDirectory -Repositories $repositories -Cmdlet $PSCmdlet -Credential $Credential -SkipDependency:$SkipDependency -AuthenticodeCheck:$AuthenticodeCheck
Publish-StagingModule -Path $tempDirectory -TargetPath $resolvedPaths -Force:$Force -Cmdlet $PSCmdlet -ThrottleLimit $ThrottleLimit
Save-StagingModule -InstallData $installData -Path $tempDirectory -Repositories $repositories -Cmdlet $Cmdlet -Credential $Credential -SkipDependency:$SkipDependency -AuthenticodeCheck:$AuthenticodeCheck
Publish-StagingModule -Path $tempDirectory -TargetPath $resolvedPaths -Force:$Force -Cmdlet $Cmdlet -ThrottleLimit $ThrottleLimit
}
finally {
# Cleanup Managed sessions only if created locally. With -PathInternal, managed sessions are managed by the caller.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
function Resolve-ModuleScopePath {
[CmdletBinding()]
param (

[string]
$Scope,

$ManagedSession,

[ValidateSet('All', 'Any', 'None')]
[string]
$TargetHandling = 'None',

$Cmdlet
)
process {
throw "Not Implemented Yet!"
Expand Down

0 comments on commit e653d5d

Please sign in to comment.