Esempio n. 1
0
    public static DockerClient CreateClient(IDictionary fakeBoundParameters)
    {
        var hostAddress         = fakeBoundParameters["HostAddress"] as string;
        var certificateLocation = fakeBoundParameters["CertificateLocation"] as string;

        return(DockerFactory.CreateClient(hostAddress, certificateLocation));
    }
    public IEnumerable <CompletionResult> CompleteArgument(string commandName,
                                                           string parameterName,
                                                           string wordToComplete,
                                                           CommandAst commandAst,
                                                           IDictionary fakeBoundParameters)
    {
        var client = DockerFactory.CreateClient(fakeBoundParameters);

        var task = client.Containers.ListContainersAsync(new ContainersListParameters
        {
            All = true
        });

        task.Wait();

        return(task.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.
            if (wordToComplete == "")
            {
                return container.Names;
            }
            else
            {
                return container.Names.Concat(new List <string> {
                    container.ID
                });
            }
        })
               .Select(name => name.StartsWith("/") && !wordToComplete.StartsWith("/") ? name.Substring(1) : name)
               .Where(name => name.StartsWith(wordToComplete, StringComparison.CurrentCultureIgnoreCase))
               .OrderBy(name => name)
               .Select(name => new CompletionResult(name, name, CompletionResultType.Text, name)));
    }
Esempio n. 3
0
    public IEnumerable <CompletionResult> CompleteArgument(string commandName,
                                                           string parameterName,
                                                           string wordToComplete,
                                                           CommandAst commandAst,
                                                           IDictionary fakeBoundParameters)
    {
        var client = DockerFactory.CreateClient(fakeBoundParameters);

        var task = client.Images.ListImagesAsync(new ImagesListParameters()
        {
            All = true
        });

        task.Wait();

        return(task.Result.SelectMany(image =>
        {
            var repoTags = image.RepoTags.Where(repoTag => repoTag != "<none>:<none>");

            // If the user has already typed part of the name and this isn't for push, then include IDs that start
            // with that portion. Otherwise, just let the user tab through the names.
            if (wordToComplete == "" || commandName == "Submit-ContainerImage")
            {
                return repoTags;
            }
            else
            {
                // Most of the time users will want to write IDs without the sha256: prefix.
                // Autocomplete based on this unless they have typed sha256:.
                var id = image.ID;
                var idParts = id.Split(':');
                if (idParts.Length >= 2 && !wordToComplete.StartsWith(idParts[0] + ":"))
                {
                    id = id.Substring(idParts[0].Length + 1);
                }
                return repoTags.Concat(new List <string> {
                    id
                });
            }
        })
               .Where(name => name.StartsWith(wordToComplete, StringComparison.CurrentCultureIgnoreCase))
               .Select(name =>
        {
            // Hide ":latest" unless the user has started typing it.
            if (name.EndsWith(LatestSuffix) && wordToComplete.Length <= name.Length - LatestSuffix.Length)
            {
                name = name.Remove(name.Length - LatestSuffix.Length);
            }

            return name;
        })
               .OrderBy(name => name)
               .Select(repoTag => new CompletionResult(repoTag, repoTag, CompletionResultType.Text, repoTag)));
    }
Esempio n. 4
0
    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)));
    }
    public IEnumerable <CompletionResult> CompleteArgument(string commandName,
                                                           string parameterName,
                                                           string wordToComplete,
                                                           CommandAst commandAst,
                                                           IDictionary fakeBoundParameters)
    {
        var client = DockerFactory.CreateClient(fakeBoundParameters);

        var result = client.Networks.ListNetworksAsync().Result;

        return(result.SelectMany(network =>
        {
            // 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-networkNetwork, where Id an Name are separate parameters.
            if (commandName == "Get-ContainerNet" && parameterName == "Id")
            {
                return new List <string> {
                    network.ID
                };
            }
            else if (wordToComplete == "" || parameterName == "Name")
            {
                return new List <string> {
                    network.Name
                };
            }
            else
            {
                return new List <string> {
                    network.Name, network.ID
                };
            }
        })
               .Distinct()
               .Where(name => name.StartsWith(wordToComplete, StringComparison.CurrentCultureIgnoreCase))
               .OrderBy(name => name)
               .Select(name => name.Contains(" ") ? "\"" + name + "\"" : name)
               .Select(name => new CompletionResult(name, name, CompletionResultType.Text, name)));
    }