mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #329 from Icinga:feature/force_repo_adding
Feature: Allow force adding of repository Extends repository feature, by allowing to force add new repositories with the same name, overriding current configuration.
This commit is contained in:
commit
f62f0043ae
2 changed files with 12 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue