Public/Get-ActiveBudget.ps1

function Get-ActiveBudget {
    <#
    .SYNOPSIS
        Gets the currently active budget.
     
    .DESCRIPTION
        Returns information about the current active budget from preferences.
     
    .PARAMETER Detailed
        Include full metadata for the active budget.
     
    .PARAMETER WorkspacePath
        Optional custom workspace path.
     
    .EXAMPLE
        Get-ActiveBudget
         
        Shows the active budget name
     
    .EXAMPLE
        Get-ActiveBudget -Detailed
         
        Shows the active budget with full metadata
     
    .OUTPUTS
        PSCustomObject - Active budget information
    #>

    [CmdletBinding()]
    param(
        [Parameter()]
        [switch]$Detailed,
        
        [Parameter()]
        [string]$WorkspacePath
    )
    
    # Check if workspace is initialized
    if (-not (Test-WorkspaceInitialized -WorkspacePath $WorkspacePath)) {
        Write-Warning "Budget workspace not initialized. Run Initialize-BudgetWorkspace first."
        return
    }
    
    # Get workspace path
    if (-not $WorkspacePath) {
        $WorkspacePath = Get-WorkspacePath
    }
    
    # Load preferences
    $preferences = Get-Preferences -WorkspacePath $WorkspacePath
    
    if (-not $preferences.activeBudget) {
        Write-Warning "No active budget set. Use Set-ActiveBudget to set one."
        return
    }
    
    $budgetName = $preferences.activeBudget
    $budgetPath = Get-BudgetPath -BudgetName $budgetName -WorkspacePath $WorkspacePath
    
    # Verify budget still exists
    if (-not (Test-Path $budgetPath)) {
        Write-Warning "Active budget '$budgetName' no longer exists"
        return
    }
    
    if ($Detailed) {
        $metadata = Get-BudgetMetadata -BudgetPath $budgetPath
        
        if ($metadata) {
            $metadata | Add-Member -NotePropertyName 'IsActive' -NotePropertyValue $true -Force
            return $metadata
        }
    }
    else {
        return [PSCustomObject]@{
            Name = $budgetName
            Path = $budgetPath
            IsActive = $true
        }
    }
}