diff --git a/doc/repositorymanager/01-Add-Existing-Repositories.md b/doc/repositorymanager/01-Add-Existing-Repositories.md index 15d7369..8770081 100644 --- a/doc/repositorymanager/01-Add-Existing-Repositories.md +++ b/doc/repositorymanager/01-Add-Existing-Repositories.md @@ -16,6 +16,7 @@ The best way to demonstrate on how to add new repositories, you can use the defa | --- |--- | --- | | Name | String | The unique name of the repository. This name can only exist once on your system | | RemotePath | String | The path pointing to the location on where the repository is located at. It can either point to the root directory of the folder containing the `ifw.repo.json` or directly to this file. Accepts web, local or network share path. | +| Force | Switch | Will remove an existing repository with the same name and override it with the new configuration | ### Icinga for Windows Stable diff --git a/lib/core/repository/Add-IcingaRepository.psm1 b/lib/core/repository/Add-IcingaRepository.psm1 index 670d221..d0c317f 100644 --- a/lib/core/repository/Add-IcingaRepository.psm1 +++ b/lib/core/repository/Add-IcingaRepository.psm1 @@ -2,7 +2,8 @@ function Add-IcingaRepository() { param ( [string]$Name = $null, - [string]$RemotePath = $null + [string]$RemotePath = $null, + [switch]$Force = $FALSE ); if ([string]::IsNullOrEmpty($Name)) { @@ -21,9 +22,16 @@ function Add-IcingaRepository() $CurrentRepositories = New-Object -TypeName PSObject; } - if (Test-IcingaPowerShellConfigItem -ConfigObject $CurrentRepositories -ConfigKey $Name) { - Write-IcingaConsoleError 'A repository with the given name "{0}" does already exist.' -Objects $Name; + $RepoExists = Test-IcingaPowerShellConfigItem -ConfigObject $CurrentRepositories -ConfigKey $Name; + + if ($RepoExists -And $Force -eq $FALSE) { + Write-IcingaConsoleError 'A repository with the given name "{0}" does already exist. Use "-Force" to overwrite the current repository' -Objects $Name; return; + } elseif ($RepoExists -And $Force) { + Write-IcingaConsoleNotice 'Repository "{0}" is already registered. Forcing removal and re-adding it.' -Objects $Name; + Remove-IcingaRepository -Name $Name; + + $CurrentRepositories = Get-IcingaPowerShellConfig -Path 'Framework.Repository.Repositories'; } [array]$RepoCount = $CurrentRepositories.PSObject.Properties.Count;