|
1 | 1 | function Invoke-NovaUpdateNotificationPreferenceChange { |
2 | 2 | [CmdletBinding()] |
3 | 3 | param( |
4 | | - [Parameter(Mandatory)][pscustomobject]$WorkflowContext |
| 4 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext, |
| 5 | + [switch]$ShouldRun |
5 | 6 | ) |
6 | 7 |
|
| 8 | + $whatIfEnabled = Test-NovaUpdateNotificationPreferenceChangeWhatIfEnabled -WorkflowContext $WorkflowContext |
| 9 | + if (-not $ShouldRun) { |
| 10 | + if ($whatIfEnabled) { |
| 11 | + Write-NovaUpdateNotificationPreferenceChangeResult -WorkflowContext $WorkflowContext -WhatIfEnabled |
| 12 | + } |
| 13 | + |
| 14 | + return |
| 15 | + } |
| 16 | + |
7 | 17 | Write-NovaUpdateNotificationPreference -PrereleaseNotificationsEnabled:$WorkflowContext.PrereleaseNotificationsEnabled |
8 | | - return Get-NovaUpdateNotificationPreferenceStatus |
| 18 | + $status = Get-NovaUpdateNotificationPreferenceStatus |
| 19 | + Write-NovaUpdateNotificationPreferenceChangeResult -WorkflowContext $WorkflowContext -Status $status |
| 20 | + return $status |
| 21 | +} |
| 22 | + |
| 23 | +function Test-NovaUpdateNotificationPreferenceChangeWhatIfEnabled { |
| 24 | + [CmdletBinding()] |
| 25 | + param( |
| 26 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext |
| 27 | + ) |
| 28 | + |
| 29 | + return $WorkflowContext.WorkflowParams.ContainsKey('WhatIf') -and $WorkflowContext.WorkflowParams.WhatIf |
| 30 | +} |
| 31 | + |
| 32 | +function Write-NovaUpdateNotificationPreferenceChangeResult { |
| 33 | + [CmdletBinding()] |
| 34 | + param( |
| 35 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext, |
| 36 | + [AllowNull()][pscustomobject]$Status, |
| 37 | + [switch]$WhatIfEnabled |
| 38 | + ) |
| 39 | + |
| 40 | + Write-Message (Get-NovaUpdateNotificationPreferenceChangeStatusMessage -WorkflowContext $WorkflowContext -WhatIfEnabled:$WhatIfEnabled) -color Green |
| 41 | + Write-Message "Settings file: $( Get-NovaUpdateNotificationPreferenceChangeSettingsPath -WorkflowContext $WorkflowContext -Status $Status )" |
| 42 | + Write-Message (Get-NovaUpdateNotificationPreferenceChangeAvailabilityMessage -WhatIfEnabled:$WhatIfEnabled) |
| 43 | + |
| 44 | + foreach ($line in (Get-NovaUpdateNotificationPreferenceChangeNextStepLine -WorkflowContext $WorkflowContext -WhatIfEnabled:$WhatIfEnabled)) { |
| 45 | + Write-Message $line |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +function Get-NovaUpdateNotificationPreferenceChangeStatusMessage { |
| 50 | + [CmdletBinding()] |
| 51 | + param( |
| 52 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext, |
| 53 | + [switch]$WhatIfEnabled |
| 54 | + ) |
| 55 | + |
| 56 | + $stateText = Get-NovaUpdateNotificationPreferenceChangeStateText -PrereleaseNotificationsEnabled:$WorkflowContext.PrereleaseNotificationsEnabled |
| 57 | + if ($WhatIfEnabled) { |
| 58 | + return "Notification preference plan ready: prerelease self-updates $stateText" |
| 59 | + } |
| 60 | + |
| 61 | + return "Prerelease self-updates are now $stateText." |
| 62 | +} |
| 63 | + |
| 64 | +function Get-NovaUpdateNotificationPreferenceChangeSettingsPath { |
| 65 | + [CmdletBinding()] |
| 66 | + param( |
| 67 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext, |
| 68 | + [AllowNull()][pscustomobject]$Status |
| 69 | + ) |
| 70 | + |
| 71 | + if ($null -ne $Status -and ($Status.PSObject.Properties.Name -contains 'SettingsPath')) { |
| 72 | + return $Status.SettingsPath |
| 73 | + } |
| 74 | + |
| 75 | + return $WorkflowContext.Target |
| 76 | +} |
| 77 | + |
| 78 | +function Get-NovaUpdateNotificationPreferenceChangeAvailabilityMessage { |
| 79 | + [CmdletBinding()] |
| 80 | + param( |
| 81 | + [switch]$WhatIfEnabled |
| 82 | + ) |
| 83 | + |
| 84 | + if ($WhatIfEnabled) { |
| 85 | + return 'Stable self-updates would remain available.' |
| 86 | + } |
| 87 | + |
| 88 | + return 'Stable self-updates remain available.' |
| 89 | +} |
| 90 | + |
| 91 | +function Get-NovaUpdateNotificationPreferenceChangeNextStepLine { |
| 92 | + [CmdletBinding()] |
| 93 | + param( |
| 94 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext, |
| 95 | + [switch]$WhatIfEnabled |
| 96 | + ) |
| 97 | + |
| 98 | + if ($WhatIfEnabled) { |
| 99 | + return @( |
| 100 | + 'Next step:' |
| 101 | + "Run $( Get-NovaUpdateNotificationPreferenceChangeCommandLine -WorkflowContext $WorkflowContext ) without -WhatIf when you are ready to store the preference." |
| 102 | + ) |
| 103 | + } |
| 104 | + |
| 105 | + return @( |
| 106 | + 'Next step:' |
| 107 | + 'Get-NovaUpdateNotificationPreference' |
| 108 | + ) |
| 109 | +} |
| 110 | + |
| 111 | +function Get-NovaUpdateNotificationPreferenceChangeCommandLine { |
| 112 | + [CmdletBinding()] |
| 113 | + param( |
| 114 | + [Parameter(Mandatory)][pscustomobject]$WorkflowContext |
| 115 | + ) |
| 116 | + |
| 117 | + if ($WorkflowContext.PrereleaseNotificationsEnabled) { |
| 118 | + return 'Set-NovaUpdateNotificationPreference -EnablePrereleaseNotifications' |
| 119 | + } |
| 120 | + |
| 121 | + return 'Set-NovaUpdateNotificationPreference -DisablePrereleaseNotifications' |
| 122 | +} |
| 123 | + |
| 124 | +function Get-NovaUpdateNotificationPreferenceChangeStateText { |
| 125 | + [CmdletBinding()] |
| 126 | + param( |
| 127 | + [Parameter(Mandatory)][bool]$PrereleaseNotificationsEnabled |
| 128 | + ) |
| 129 | + |
| 130 | + if ($PrereleaseNotificationsEnabled) { |
| 131 | + return 'enabled' |
| 132 | + } |
| 133 | + |
| 134 | + return 'disabled' |
9 | 135 | } |
0 commit comments