Public/Set-SpotifyControlsConfig.ps1
|
<# .SYNOPSIS Sets the SpotifyControls module configuration .PARAMETER ClientId The ClientId configured for the Spotify application you set up in the Spotify developer portal. .PARAMETER RedirectUri The RedirectUri configured for the Spotify application you set up in the Spotify developer portal. #> function Set-SpotifyControlsConfig { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string] $ClientId, [Parameter(Mandatory=$true)] [string] $RedirectUri, [System.Boolean] $Force ) $dirExists = Test-Path $script:CONFIGDIR -ErrorAction SilentlyContinue if (! $dirExists) { New-Item -ItemType Directory -Path $script:CONFIGDIR | Out-Null } $fsInfo = Get-Item -Path $script:CONFIGDIR if ($fsInfo.Attributes -ne 'Directory') { throw "$script:CONFIGDIR exists and is not a directory" } $fileExists = Test-Path $script:CONFIGFILE -ErrorAction SilentlyContinue if ($fileExists -and ! $Force) { throw "$script:CONFIGFILE already exists. Use -Force to overwrite" } @{ ClientId = $ClientId RedirectUri = $RedirectUri } | ConvertTo-Json | Set-Content -Path $script:CONFIGFILE Write-Output "${script:GREEN}Configuration written${script:RESETANSI}" } |