Private/Set-Config.ps1
|
<#
.SYNOPSIS Saves the configuration to config.json .DESCRIPTION Saves the configuration object to the workspace config.json file .PARAMETER Config Configuration object to save .PARAMETER WorkspacePath Path to the workspace folder. If not provided, uses the stored workspace path. #> function Set-Config { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [PSCustomObject]$Config, [string]$WorkspacePath ) try { # Get workspace path from module variable or parameter if (-not $WorkspacePath) { $WorkspacePath = $script:NLBaselineWorkspacePath } if (-not $WorkspacePath) { throw "Workspace path not configured. Please run Initialize-NLBaseline first." } $configPath = Join-Path -Path $WorkspacePath -ChildPath "config.json" # Convert to JSON with proper formatting $json = $Config | ConvertTo-Json -Depth 10 # Save to file Set-Content -Path $configPath -Value $json -Force Write-Verbose "Configuration saved to: $configPath" return $true } catch { Write-Error "Failed to save configuration: $_" return $false } } |