Private/Register-OriAzBopInternalPSRepository.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<#
.DESCRIPTION
Since is not possible to Mock Get-Package due dynamic block should be the function sparated for unit test resons
Note: See more on https://github.com/pester/Pester/issues/604
 
.SYNOPSIS
Since is not possible to Mock Get-Package due dynamic block should be the function sparated for unit test resons
Note: See more on https://github.com/pester/Pester/issues/604
 
.PARAMETER RegisterPackageSourceParam
Parameters for one Register-PSRepository
 
.PARAMETER RegisterViaPSRepository
When is set register via Register-PSRepository, otherwise use Register-PackageSource.
 
.EXAMPLE
Use exactly the same like for Register-PSRepository
#>


function Register-OriAzBopInternalPSRepository {
    
  [CmdletBinding()]
  param
  (   
    
    [parameter(Mandatory=$true, HelpMessage='Parameters for Register-PSRepository')]
    [Hashtable] $RegisterRepositoryParams,

    [Parameter(Mandatory = $false, HelpMessage = "When is set register via Register-PSRepository, otherwise use Register-PackageSource.")]
    [switch] $RegisterViaPSRepository

  )

    #in case of any error we want to stop execution, in stderr having the error. Use try-catch to handle errors if needed.
    $ErrorActionPreference = "Stop";
    Write-Verbose "-- Register-OriAzBopInternalPSRepository --"
    Write-Verbose "RegisterRepositoryParams: $(ConvertTo-Json $RegisterRepositoryParams) "
    Write-Verbose "-- End of Register-OriAzBopInternalPSRepository --"    
    if($RegisterViaPSRepository.IsPresent) {
      Write-Verbose " Register via Register-PSRepository"
    return(Register-PSRepository @RegisterRepositoryParams)
    } 
    else {
      Write-Verbose " Register via Register-PackageSource"
      return(Register-PackageSource @RegisterRepositoryParams)
    }

}