Skip to content
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

Make shell completion DRYer and less hacky #1498

Closed
1 of 4 tasks
aanand opened this issue Jun 2, 2015 · 9 comments
Closed
1 of 4 tasks

Make shell completion DRYer and less hacky #1498

aanand opened this issue Jun 2, 2015 · 9 comments

Comments

@aanand
Copy link

aanand commented Jun 2, 2015

Thanks to @albers and @sdurrheimer, we now have both bash and zsh completion, which is fantastic. However, they (understandably) both do a lot of hacky stuff to read the YAML file without actually parsing YAML properly, and they both implement this separately.

We could potentially add some commands/flags to Compose that would give them the information they need in a simple shell-parseable format. Going off a quick scan of the bash script, it looks like it'd be useful to be able to list:

  • names of all services in the file
  • names of all services that have a given configuration option set - here, we'd even be able to evaluate extends to get the correct configuration, which I doubt would be any fun at all to implement in shell script
  • names of services that have at least one running container
  • names of services that have at least one stopped container

Perhaps a docker-compose services command:

$ docker-compose services
web
redis

$ docker-compose services --with-option="build"
web

$ docker-compose services --with-running-container
redis
@albers
Copy link

albers commented Jun 2, 2015

Wow! That's fantastic. I'm happy to see completion growing in weight (I didn't dare to ask about such features before).

Another difficult to implement feature that this proposal solves (taken from the releasenotes):

When invoked in a subdirectory of a project, docker-compose will now climb up through parent directories until it finds a docker-compose.yml.

@thaJeztah
Copy link
Member

Nice thinking!

$ docker-compose services --with-option="build"
$ docker-compose services --with-running-container

How about using a --filter .... flag for this, which is a closer match to the way this works in "Docker like", e.g.

$ docker-compose services --filter option=build
$ docker-compose services --filter status=running

(Going off-topic alert);
To be useful for other purposes, docker-compose services could output all information of the services by default (similar to docker inspect), and feature a --format .. flag that accepts a Go-template. However, I realize python !== golang, so that would involve implementing go-templates in Python (which is probably a bad idea, unless someone did that already)

@tpounds
Copy link

tpounds commented Jun 2, 2015

+1 to provide a --filter flag since it's consistent with many docker list resource commands.

@albers
Copy link

albers commented Jun 3, 2015

+1 for the --filter syntax.

@sdurrheimer
Copy link

--filter sounds good 👍

@albers
Copy link

albers commented Sep 21, 2015

With the addition of multiple compose files (#2051), and the recently introduced search of compose.yml in parent directories, this feature is gaining weight.

I think it would also be useful if Compose could output the "effective configuration", i.e. the actual result of combining the yaml files. Maven got the notion of an "effective POM" that is the result of an internal bas POM and the user provided pom.xml.

@dnephin
Copy link

dnephin commented Sep 21, 2015

I think it would also be useful if Compose could output the "effective configuration", i.e. the actual result of combining the yaml files.

I think so too. The proposal for that is #1953

@ilinum
Copy link

ilinum commented Nov 6, 2017

I would be interested in working on this. Is there still interest in having this implemented?

@albers
Copy link

albers commented Nov 7, 2017

Yes, that is still relevant. You're welcome!

Bash completion needs to enumerate services with several states (paused, stopped, running). It currently does so by getting the list of containers and then inspecting each one, collecting matching service names:
https://github.com/docker/compose/blob/master/contrib/completion/bash/docker-compose#L87-L109.

There's also code that enumerates services defined by a build or an image key. It parses the yaml output manually with shell means: https://github.com/docker/compose/blob/master/contrib/completion/bash/docker-compose#L87-L109

It would be really nice to get native support by docker-compose for both use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants