/// <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); } } }
public IEnumerable <CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters) { var client = DockerFactory.CreateClient(fakeBoundParameters); IList <ContainerListResponse> result; if (wordToComplete == "") { result = client.Containers.ListContainersAsync(new ContainersListParameters { All = true }).Result; } else { result = ContainerOperations.GetContainersById(wordToComplete, client).Result; result = result.Concat(ContainerOperations.GetContainersByName(wordToComplete, client).Result).ToList(); } return(result.SelectMany(container => { // If the user has already typed part of the name, then include IDs that start // with that portion. Otherwise, just let the user tab through the names. // Special handling for Get-Container, where Id an Name are separate parameters. if (commandName == "Get-Container" && parameterName == "Id") { return new List <string> { container.ID }; } else if (wordToComplete == "" || parameterName == "Name") { return container.Names; } else { return container.Names.Concat(new List <string> { container.ID }); } }) .Select(name => name.StartsWith("/") && !wordToComplete.StartsWith("/") ? name.Substring(1) : name) .Distinct() .Where(name => name.StartsWith(wordToComplete, StringComparison.CurrentCultureIgnoreCase)) .OrderBy(name => name) .Select(name => new CompletionResult(name, name, CompletionResultType.Text, name))); }