Skip to content

Conversation

@aeriksson
Copy link

This fixes a few issues with the zsh autocomplete script, and brings it up to date with the current docker-compose commands.

Changes:

  • Uses docker-compose config instead of manually trying to find and parse the docker-compose file. This fixes a few issues:
    • Now works for version 2 docker-compose files.
    • Will work correctly even if the current working directory is a subdirectory of the folder with the docker-compose file.
  • Now has all the flags for all the docker-compose commands.
  • Command help texts are now in line with what docker-compose help x produces (fixed some typos and outdated/incorrect help texts).
  • Now passes all relevant flags when shelling out to docker-compose and docker, so autocomplete works even if --tls, --tlskey, etc are set.
  • Fixed issue where autocomplete for build, pull would only show some services.
  • Fixed issue with filtering on already selected services when service names are substrings of one another.
  • All functions are now prefixed with the same number of underscores.

@aeriksson
Copy link
Author

So I realized this PR conflicts with #3214 #3215 #3216 #3217 #3218. They weren't there when I set out to work on this :)

Anyway, 4201da9 contains the changes in those PRs, as well as other flag-related stuff.

If those PRs get merged first, I can rebase this branch accordingly.

@dnephin
Copy link

dnephin commented Mar 28, 2016

cc @sdurrheimer

@sdurrheimer
Copy link

@dnephin @aeriksson Yes, we should merge others PRs before considering merging this one in order to have a clear state (#3214 #3215 #3216 #3217 #3218).

I would then be able to proper review this after a rebase.

@aeriksson aeriksson force-pushed the fix-zsh-autocomplete branch 2 times, most recently from 56c0e6f to 2075944 Compare March 30, 2016 04:32
@aeriksson aeriksson force-pushed the fix-zsh-autocomplete branch from 2075944 to 1bce90f Compare March 30, 2016 04:33
@aeriksson aeriksson force-pushed the fix-zsh-autocomplete branch from 1bce90f to 7e80ab4 Compare March 30, 2016 04:34
@aeriksson
Copy link
Author

@sdurrheimer rebased!

| sed -n -e '/^services:/,/^[^ ]/p' \
| sed -n 's/^ //p' \
| awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' \
| awk -F: -v key=": +$1:" '$0 ~ key {print $1}' \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you squash that changed with @cbfe6d0 ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @albers This might interest you given that we are using the same services parsing method.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdurrheimer Yes, that's identical with my version.
It improves readibility at the cost of one extra command invocation. I think that's OK.
I have two suggestions, though which i'll add below.
@aeriksson would you mind to adjust this function in the bash completion as well so that both completions stay aligned?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albers sure, I'll create a bash PR too

@sdurrheimer
Copy link

LGTM

docker-compose 2>/dev/null $compose_options "$@"
}

# Extracts all service names from docker-compose.yml.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albers what should the comment say?

I removed it to be in line with the bash script:
https://github.com/docker/compose/blob/master/contrib/completion/bash/docker-compose#L20-L22

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with removing the comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aeriksson Can you do that change ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdurrheimer not sure what the change is…

Maybe I misunderstood something, but I think @albers asked me to update that comment rather than removing it.

I then pointed out that I removed it because it was no longer needed, and there is no corresponding comment on the same function in the bash script.

I take what @albers wrote after to mean that after some deliberation, he was okay with the comment being removed.

Again, I might be wrong here, and I'd gladly add a comment if there's a need for one :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aeriksson The comment refers to the previous way of harvesting the service names from docker-compose.yml. The comment pointed out that the service list had some limitations: it did not take into account several other configuration files that were added over time.

Now, we use an official API for that task: docker-compose config. We let docker-compose combine all the configuration sources. But the comment was not updated and now is wrong.

There are two ways to resolve this mismatch:

  1. change the comment to "Extracts all service names from the output of docker-compose config"
  2. drop the comment

I favour solution 2 because the comment from solution 1 is trivial. The new code does not need a comment any more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and solution 2 is what is implemented in this PR, so no further changes should be required, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aeriksson: @albers is talking about the comment line 26/36

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Updated that comment to say "All services defined in docker-compose.yml" rather than "Extracts all service names from docker-compose.yml".

@sdurrheimer
Copy link

Hello, what is the state of this PR ?

@aeriksson
Copy link
Author

AFAICT it's ready to merge.

aeriksson and others added 13 commits June 27, 2016 11:00
This has the added benefit of making autocompletion work when the
docker-compose config file is in a parent directory.

Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
For autocomplete to work properly, we need to pass along some flags when
calling docker (--host, --tls, …) and docker-compose (--file, --tls, …).

Previously flags would only be passed to docker-compose, and the only
flags passed were --file and --project-name.

This commit makes sure that all relevant flags are passed to both
docker-compose and docker.

Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Previously, the autocomplete for the build/pull commands would only add
services for which build/image were the _first_ keys, respectively, in
the docker-compose file.

This commit fixes this, so the appropriate services are listed
regardless of the order in which they appear

Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Previously, the filtering on already selected services would break when
one service was a substring of another.

This commit fixes that.

Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
Signed-off-by: Andre Eriksson <aepubemail@gmail.com>
@aeriksson aeriksson force-pushed the fix-zsh-autocomplete branch from 2211d2f to c3247e7 Compare June 27, 2016 18:08
@sdurrheimer
Copy link

Ok LGTM

@sdurrheimer
Copy link

@dnephin @aanand Can we get this merged soon ? This PR fixes the version: 2 support and is kinda blocking me my upcoming PRs for new docker-compose command like bundle or push.

@dnephin
Copy link

dnephin commented Jun 29, 2016

LGTM

@aanand
Copy link

aanand commented Jun 29, 2016

LGTM, thanks!

@aanand aanand merged commit c0237a4 into docker:master Jun 29, 2016
@aanand aanand added this to the 1.8.0 milestone Jun 29, 2016
aanand added a commit to aanand/fig that referenced this pull request Jul 6, 2016
Fix zsh autocomplete
(cherry picked from commit c0237a4)

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants