Skip to content

Change -Repositories param to -Repository in Register-PSResourceRepository #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions help/Register-PSResourceRepository.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Register-PSResourceRepository [-PSGallery] [-Trusted] [-Priority <Int32>] [-Pass

### RepositoriesParameterSet
```
Register-PSResourceRepository -Repositories <Hashtable[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Register-PSResourceRepository -Repository <Hashtable[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -59,7 +59,7 @@ This example registers the "PSGallery" repository, with the 'PSGallery' paramete
### Example 3
```
PS C:\> $arrayOfHashtables = @{Name = "psgettestlocal"; Uri = "c:/code/testdir"}, @{PSGallery = $True}
PS C:\> Register-PSResourceRepository -Repositories $arrayOfHashtables
PS C:\> Register-PSResourceRepository -Repository $arrayOfHashtables
PS C:\> Get-PSResourceRepository
Name Uri Trusted Priority
---- --- ------- --------
Expand All @@ -68,7 +68,7 @@ PS C:\> Get-PSResourceRepository

```

This example registers multiple repositories at once. To do so, we use the `-Repositories` parameter and provide an array of hashtables. Each hashtable can only have keys associated with parameters for the NameParameterSet or the PSGalleryParameterSet. Upon running the command we can see that the "psgettestlocal" and "PSGallery" repositories have been succesfully registered.
This example registers multiple repositories at once. To do so, we use the `-Repository` parameter and provide an array of hashtables. Each hashtable can only have keys associated with parameters for the NameParameterSet or the PSGalleryParameterSet. Upon running the command we can see that the "psgettestlocal" and "PSGallery" repositories have been succesfully registered.

## PARAMETERS

Expand Down Expand Up @@ -119,7 +119,7 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Repositories
### -Repository
Specifies an array of hashtables which contains repository information and is used to register multiple repositories at once.

```yaml
Expand Down
6 changes: 3 additions & 3 deletions help/Set-PSResourceRepository.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Set-PSResourceRepository [-Name] <String> [-Uri <String>] [-Trusted] [-Priority

### RepositoriesParameterSet
```
Set-PSResourceRepository -Repositories <Hashtable[]> [-Priority <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-PSResourceRepository -Repository <Hashtable[]> [-Priority <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -65,14 +65,14 @@ PS C:\> Get-PSResourceRepository -Name "*"

PS C:\> $arrayOfHashtables = @{Name = "PSGallery"; Trusted = $True}, @{Name = "PoshTestGallery"; Uri = "c:/code/testdir"}

PS C:\> Set-PSResourceRepository -Repositories $arrayOfHashtables -PassThru
PS C:\> Set-PSResourceRepository -Repository $arrayOfHashtables -PassThru
Name Uri Trusted Priority
---- --- ------- --------
PSGallery https://www.powershellgallery.com/api/v2 True 50
PoshTestGallery file:///c:/code/testdir False 50
```

This example first checks for all registered repositories. We wish to set the properties for multiple repositories at once (i.e the PSGallery and PoshTestGallery repositories), so we run Set-PSResourceRepository with the `-Repositories` parameter. This parameter takes an array of hashtables, where each hashtable contains information for a repository we wish to set information for. We also use the `-PassThru` parameter to see the changed repositories.
This example first checks for all registered repositories. We wish to set the properties for multiple repositories at once (i.e the PSGallery and PoshTestGallery repositories), so we run Set-PSResourceRepository with the `-Repository` parameter. This parameter takes an array of hashtables, where each hashtable contains information for a repository we wish to set information for. We also use the `-PassThru` parameter to see the changed repositories.

## PARAMETERS

Expand Down
4 changes: 2 additions & 2 deletions src/code/RegisterPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class RegisterPSResourceRepository : PSCmdlet
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = RepositoriesParameterSet)]
[ValidateNotNullOrEmpty]
public Hashtable[] Repositories {get; set;}
public Hashtable[] Repository {get; set;}

/// <summary>
/// Specifies whether the repository should be trusted.
Expand Down Expand Up @@ -270,7 +270,7 @@ private PSRepositoryInfo PSGalleryParameterSetHelper(int repoPriority, bool repo
private List<PSRepositoryInfo> RepositoriesParameterSetHelper()
{
List<PSRepositoryInfo> reposAddedFromHashTable = new List<PSRepositoryInfo>();
foreach (Hashtable repo in Repositories)
foreach (Hashtable repo in Repository)
{
if (repo.ContainsKey(PSGalleryRepoName))
{
Expand Down
4 changes: 2 additions & 2 deletions src/code/SetPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public sealed class SetPSResourceRepository : PSCmdlet
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = RepositoriesParameterSet)]
[ValidateNotNullOrEmpty]
public Hashtable[] Repositories { get; set; }
public Hashtable[] Repository { get; set; }

/// <summary>
/// Specifies whether the repository should be trusted.
Expand Down Expand Up @@ -236,7 +236,7 @@ private PSRepositoryInfo UpdateRepositoryStoreHelper(string repoName, Uri repoUr
private List<PSRepositoryInfo> RepositoriesParameterSetHelper()
{
List<PSRepositoryInfo> reposUpdatedFromHashtable = new List<PSRepositoryInfo>();
foreach (Hashtable repo in Repositories)
foreach (Hashtable repo in Repository)
{
if (!repo.ContainsKey("Name") || repo["Name"] == null || String.IsNullOrEmpty(repo["Name"].ToString()))
{
Expand Down
16 changes: 8 additions & 8 deletions test/RegisterPSResourceRepository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ Describe "Test Register-PSResourceRepository" {
$res.Priority | Should -Be 20
}

It "register repositories with Repositories parameter, all name parameter style repositories (RepositoriesParameterSet)" {
It "register repositories with -Repository parameter, all name parameter style repositories (RepositoriesParameterSet)" {
$hashtable1 = @{Name = $TestRepoName1; Uri = $tmpDir1Path}
$hashtable2 = @{Name = $TestRepoName2; Uri = $tmpDir2Path; Trusted = $True}
$hashtable3 = @{Name = $TestRepoName3; Uri = $tmpDir3Path; Trusted = $True; Priority = 20}
$hashtable4 = @{Name = $TestRepoName4; Uri = $tmpDir4Path; Trusted = $True; Priority = 30; CredentialInfo = (New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ("testvault", "testsecret"))}
$arrayOfHashtables = $hashtable1, $hashtable2, $hashtable3, $hashtable4

Register-PSResourceRepository -Repositories $arrayOfHashtables
Register-PSResourceRepository -Repository $arrayOfHashtables
$res = Get-PSResourceRepository -Name $TestRepoName1
$Res.Uri.LocalPath | Should -Contain $tmpDir1Path
$res.Trusted | Should -Be False
Expand All @@ -130,17 +130,17 @@ Describe "Test Register-PSResourceRepository" {
$res4.CredentialInfo.Credential | Should -BeNullOrEmpty
}

It "register repositories with Repositories parameter, psgallery style repository (RepositoriesParameterSet)" {
It "register repositories with -Repository parameter, psgallery style repository (RepositoriesParameterSet)" {
Unregister-PSResourceRepository -Name $PSGalleryName
$hashtable1 = @{PSGallery = $True}
Register-PSResourceRepository -Repositories $hashtable1
Register-PSResourceRepository -Repository $hashtable1
$res = Get-PSResourceRepository -Name $PSGalleryName
$res.Uri | Should -Be $PSGalleryUri
$res.Trusted | Should -Be False
$res.Priority | Should -Be 50
}

It "register repositories with Repositories parameter, name and psgallery parameter styles (RepositoriesParameterSet)" {
It "register repositories with -Repository parameter, name and psgallery parameter styles (RepositoriesParameterSet)" {
Unregister-PSResourceRepository -Name $PSGalleryName
$hashtable1 = @{PSGallery = $True}
$hashtable2 = @{Name = $TestRepoName1; Uri = $tmpDir1Path}
Expand All @@ -149,7 +149,7 @@ Describe "Test Register-PSResourceRepository" {
$hashtable5 = @{Name = $TestRepoName4; Uri = $tmpDir4Path; Trusted = $True; Priority = 30; CredentialInfo = (New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ("testvault", "testsecret"))}
$arrayOfHashtables = $hashtable1, $hashtable2, $hashtable3, $hashtable4, $hashtable5

Register-PSResourceRepository -Repositories $arrayOfHashtables
Register-PSResourceRepository -Repository $arrayOfHashtables

$res1 = Get-PSResourceRepository -Name $PSGalleryName
$res1.Uri | Should -Be $PSGalleryUri
Expand Down Expand Up @@ -220,7 +220,7 @@ Describe "Test Register-PSResourceRepository" {
$arrayOfHashtables = $correctHashtable1, $correctHashtable2, $IncorrectHashTable, $correctHashtable3

Unregister-PSResourceRepository -Name $PSGalleryName
Register-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
Register-PSResourceRepository -Repository $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "NotProvideNameUriCredentialInfoForPSGalleryRepositoriesParameterSetRegistration,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository"

Expand Down Expand Up @@ -248,7 +248,7 @@ Describe "Test Register-PSResourceRepository" {

$arrayOfHashtables = $correctHashtable1, $correctHashtable2, $IncorrectHashTable, $correctHashtable3
Unregister-PSResourceRepository -Name $PSGalleryName
Register-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
Register-PSResourceRepository -Repository $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly $ErrorId

Expand Down
8 changes: 4 additions & 4 deletions test/SetPSResourceRepository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Describe "Test Set-PSResourceRepository" {
$incorrectHashTable = @{Name = $Name; Trusted = $True}
$arrayOfHashtables = $hashtable1, $incorrectHashTable, $hashtable2

Set-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
Set-PSResourceRepository -Repository $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository"

Expand All @@ -138,7 +138,7 @@ Describe "Test Set-PSResourceRepository" {
$hashtable4 = @{Name = $PSGalleryName; Trusted = $True};
$arrayOfHashtables = $hashtable1, $hashtable2, $hashtable3, $hashtable4

Set-PSResourceRepository -Repositories $arrayOfHashtables
Set-PSResourceRepository -Repository $arrayOfHashtables
$res = Get-PSResourceRepository -Name $TestRepoName1
$res.Name | Should -Be $TestRepoName1
$Res.Uri.LocalPath | Should -Contain $tmpDir2Path
Expand Down Expand Up @@ -192,7 +192,7 @@ Describe "Test Set-PSResourceRepository" {
$hashtable2 = @{Name = $TestRepoName1; Priority = 25}
$arrayOfHashtables = $hashtable1, $hashtable2

Set-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
Set-PSResourceRepository -Repository $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorSettingIndividualRepoFromRepositories,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository"

Expand Down Expand Up @@ -222,7 +222,7 @@ Describe "Test Set-PSResourceRepository" {
$hashtable2 = @{Name = $TestRepoName1; Priority = 25}
$arrayOfHashtables = $hashtable1, $hashtable2

Set-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
Set-PSResourceRepository -Repository $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorSettingIndividualRepoFromRepositories,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository"

Expand Down