-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathGetPSResourceRepository.cs
More file actions
68 lines (58 loc) · 2.41 KB
/
GetPSResourceRepository.cs
File metadata and controls
68 lines (58 loc) · 2.41 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
/// <summary>
/// The Get-PSResourceRepository cmdlet replaces the Get-PSRepository cmdlet from V2.
/// It searches for the PowerShell module repositories that are registered for the current user.
/// By default it will return all registered repositories, or if the -Name parameter argument is specified then it wil return the repository with that name.
/// It returns PSRepositoryInfo objects which describe each resource item found.
/// </summary>
[Cmdlet(VerbsCommon.Get, "PSResourceRepository")]
[OutputType(typeof(PSRepositoryInfo))]
public sealed class GetPSResourceRepository : PSCmdlet
{
#region Parameters
/// <summary>
/// Specifies the name(s) of a registered repository to find.
/// Supports wild card characters.
/// </summary>
[SupportsWildcards]
[Parameter(Position = 0, ValueFromPipeline = true)]
[ArgumentCompleter(typeof(RepositoryNameCompleter))]
[ValidateNotNullOrEmpty]
public string[] Name { get; set; } = Utils.EmptyStrArray;
#endregion
#region Methods
protected override void BeginProcessing()
{
RepositorySettings.CheckRepositoryStore();
}
protected override void ProcessRecord()
{
string nameArrayAsString = (Name == null || !Name.Any() || string.Equals(Name[0], "*") || Name[0] == null)
? "all" : string.Join(", ", Name);
WriteDebug($"Reading repository info for '{nameArrayAsString}'");
List<PSRepositoryInfo> items = RepositorySettings.Read(Name, out string[] errorList);
// handle non-terminating errors
foreach (string error in errorList)
{
WriteError(new ErrorRecord(
new PSInvalidOperationException(error),
"ErrorGettingSpecifiedRepo",
ErrorCategory.InvalidOperation,
this));
}
foreach (PSRepositoryInfo repo in items)
{
WriteObject(repo);
}
}
#endregion
}
}