compose
compose copied to clipboard
Command-line completion?
Should be easy to generate one, as Cobra command library includes support for generating completion scripts https://github.com/spf13/cobra/blob/master/shell_completions.md
Are we looking to reach parity with docker-compose or is this not a requirement?
@mat007 we don't have any shell completion support for docker compose yet, so we can start with a minimal one, then would be nice we can rely on cobra's BashCompletionFunction or ValidArgsFunction. This would require the backend to be involved providing valid values, so maybe not as simple as it sounds with the current "backend-neutral" architecture.
In the mean time, does anyone know if there's a way to configure docker compose completion to fall back to the old docker-compose completion?
In the mean time, does anyone know if there's a way to configure
docker composecompletion to fall back to the olddocker-composecompletion?
This might suggest a way to do that: https://stackoverflow.com/questions/55447023/how-do-i-defer-shell-completion-to-another-command-in-bash-and-zsh
There was some completion but it was removed in https://github.com/docker/compose/commit/c28aec2308a24f589814cf4ac55a225d144f557d
AFAICT offering command line completion for docker compose (space) isn't trivial due to the CLI plugin architecture, but we could automatically produce completion for docker-compose (when used standalone) using Cobra command support for this feature. Wdyt @ulyssessouza @mat007 ?
I was pretty sure this was already in place, but apparently it’s either not fully implemented or not working. We’ll have a look: internally tracked as https://docker.atlassian.net/browse/IL-768
IIRC @ulyssessouza experimented with this, but he was blocked by docker CLI plugin architecture (we can't extend the docker CLI completion script) But for direct use of docker-compose binary, we could adopt https://gist.github.com/jsteenb2/0973c838b00940ee8ccdf958a79756af and also add support for completion functions to auto-complete flags / args values.
This is very strange indeed. What happened with the bash auto completion. Otherwise I would have created a PR for upgrading docker-compose to v2.2.2 on https://github.com/docker/docker.github.io/
Please note the existing docker-compose bash completion still works with compose v2 when used as a standalone binary. But it would beed some update to add support for additional commands and flags
This problem has been solved? in some version?
Should be easy to generate one, as Cobra command library includes support for generating completion scripts https://github.com/spf13/cobra/blob/master/shell_completions.md @ndeloof were you able to generate completion scripts? for compose v2?
This problem has been solved? in some version?
No, this doesn't seem to be solved yet.
Ok i think i missed something :thinking: : Is docker compose invoking docker-compose or is it compiled into the docker binary?
docker compose aka docker-compose v2 is a plugin for the docker command written in go and is not using any python stuff from docker-compose v1.
@SuperSandro2000 thanks. I got the shift from python to go, but I didn't catch that it is integrated as plugin.
for completeness: under the hood, docker's cli-plugins handling does invoke a docker-compose executable (which happens to be written in golang these days indeed), which typically lives in /usr/lib/docker/cli-plugins/docker-compose and should not be called directly. (this is similar to how git handles subcommand ‘plugins’)
docker-composeexecutable (which happens to be written in golang these days indeed), which typically lives in/usr/lib/docker/cli-plugins/docker-composeand should not be called directly. (this is similar to howgithandles subcommand ‘plugins’)
Yeah, I was worried about that as I've been invoking docker-compose (which still exists in my PATH) for the completions - should be docker compose then.
IIRC @ulyssessouza experimented with this, but he was blocked by docker CLI plugin architecture (we can't extend the docker CLI completion script)
@ndeloof i think this should be possible if you can update the docker cli to a newer cobra version. It changed in recent versions from full completion script generation to invoking the binary.
In docker cli you just add a subcommand for each (installed) plugin with flag parsing disabled like here.
Then in the ValidArgsFunction invoke the __complete subcommand of the plugin with args and toComplete as arguments similar to this (ignore the directive handling as it is not needed in this case).
The __complete command outputs sth. like this:
value
value\twithDescription
:4
# empty line
So just return lines[:len(lines)-2] and :4 parsed as integer (ShellCompDirecive).
Started experimenting with cobra 1.3.0 to adopt cobra (dynamic) completion v2 : https://github.com/docker/cli/pull/3429
Nice. If it's any help for anyone in the meantime: got my completer at carapace-bin.
Just source the script from carapace docker and it should work with the compose and buildx subcommands.
As temporal workaround I have installed compose switch and applied v1 completion. it requires me to use it as docker-compose (not as docker compose) but completion works
(Not sure if a new issue needs to be opned but i am adding it here since it's a related thing).
The documentation provides bash script for auto-completion (for version 2.4) but the link to the script (https://docs.docker.com/compose/completion/) is broken.
Place the completion script in /etc/bash_completion.d/.
$ sudo curl \
-L https://raw.githubusercontent.com/docker/compose/v2.4.1/contrib/completion/bash/docker-compose \
-o /etc/bash_completion.d/docker-compose
$ cat /etc/bash_completion.d/docker-compose
404: Not Found
Also, as a quick fix, adding aliases to ~/.bash_aliases worked for me (on Linux Mint OS):
alias dc='docker compose'
alias dcf='docker compose -f'
After this, auto-complete atleast for file names worked:
// hit tab after typing dcf
dcf <start typing first few letters of file-name& hit TAB>
Command line completion for docker compose as a docker CLI plugin will be enabled by https://github.com/docker/cli/pull/3429
https://docs.docker.com/compose/completion/ states that sudo curl -L https://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose is a valid way to go, but https://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/bash/docker-compose is a 404.
@konstruktoid thanks for reporting. I guess doc was updated for v2.5 release but this is actually link for docker-compose 1.x completion
https://docs.docker.com/compose/completion/ states that
sudo curl -L https://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-composeis a valid way to go, buthttps://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/bash/docker-composeis a 404.
Ran into this today, still not fixed... Can you link to the Issue?
https://github.com/docker/docker.github.io/issues/14692
Updating the Docker CLI completion ( curl -L https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker -o /usr/share/bash-completion/completions/docker ) did the tirck while waiting for https://github.com/docker/cli/pull/3429 become releesed (v20.10.17?).