This repository was archived by the owner on Apr 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathGetContainer.cs
59 lines (55 loc) · 1.93 KB
/
GetContainer.cs
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
using System.Management.Automation;
using Docker.DotNet.Models;
using System.Threading.Tasks;
using Docker.PowerShell.Objects;
namespace Docker.PowerShell.Cmdlets
{
[Cmdlet(VerbsCommon.Get, "Container",
DefaultParameterSetName = CommonParameterSetNames.ContainerName)]
[OutputType(typeof(ContainerListResponse))]
public class GetContainer : DkrCmdlet
{
[Parameter(ParameterSetName = CommonParameterSetNames.Default,
ValueFromPipeline = true,
Position = 0)]
[ValidateNotNullOrEmpty]
[ArgumentCompleter(typeof(ContainerArgumentCompleter))]
public string[] Id { get; set; }
[Parameter(ParameterSetName = CommonParameterSetNames.ContainerName,
ValueFromPipeline = true,
Position = 0)]
[ValidateNotNullOrEmpty]
[ArgumentCompleter(typeof(ContainerArgumentCompleter))]
public string[] Name { get; set; }
#region Overrides
/// <summary>
/// Outputs container objects for each container matching the provided parameters.
/// </summary>
protected override async Task ProcessRecordAsync()
{
if (Id != null)
{
foreach (var id in Id)
{
WriteObject(await ContainerOperations.GetContainersById(id, DkrClient));
}
}
else if (Name != null)
{
foreach (var name in Name)
{
WriteObject(await ContainerOperations.GetContainersByName(name, DkrClient));
}
}
else
{
foreach (var c in await DkrClient.Containers.ListContainersAsync(
new ContainersListParameters() { All = true }))
{
WriteObject(c);
}
}
}
#endregion
}
}