Public/Disconnect-Dune.ps1

<#
.SYNOPSIS
End the current Dune session.

.DESCRIPTION
Removes the in-memory Dune session and optionally clears any cached session data. Use this to sign out and remove stored session state used by Dune cmdlets.

.PARAMETER KeepCachedSession
If present, the cached session data is preserved; only the in-memory script-level session is removed. When not specified, cached sessions are removed as well.

.EXAMPLE
PS> Disconnect-Dune
Removes the current script-level Dune session and clears cached session data.

.EXAMPLE
PS> Disconnect-Dune -KeepCachedSession
Removes only the in-memory session but preserves cached session data.
#>

function Disconnect-Dune {
    [CmdletBinding()]
    param(
        [Parameter()]
        [switch]$KeepCachedSession
    )

    begin {}

    process {
        if ($script:DuneSession) { Remove-Variable -Name DuneSession -Scope Script }
        if (-not $KeepCachedSession) { Remove-CachedDuneSession }
    }

    end {}
}