Skip to content

Commit

Permalink
Merge pull request docker#5770 from thaJeztah/build_completion
Browse files Browse the repository at this point in the history
Makefile: add "shell-completion" target
  • Loading branch information
thaJeztah authored Jan 24, 2025
2 parents 17c5fe6 + 6ab9b92 commit b8879a4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
33 changes: 25 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,31 @@ authors: ## generate AUTHORS file from git history
scripts/docs/generate-authors.sh

.PHONY: completion
completion: binary
completion: /etc/bash_completion.d/docker
completion: ## generate and install the completion scripts

.PHONY: /etc/bash_completion.d/docker
/etc/bash_completion.d/docker: ## generate and install the bash-completion script
mkdir -p /etc/bash_completion.d
docker completion bash > /etc/bash_completion.d/docker
completion: shell-completion
completion: ## generate and install the shell-completion scripts
# Note: this uses system-wide paths, and so may overwrite completion
# scripts installed as part of deb/rpm packages.
#
# Given that this target is intended to debug/test updated versions, we could
# consider installing in per-user (~/.config, XDG_DATA_DIR) paths instead, but
# this will add more complexity.
#
# See https://github.com/docker/cli/pull/5770#discussion_r1927772710
install -D -p -m 0644 ./build/completion/bash/docker /usr/share/bash-completion/completions/docker
install -D -p -m 0644 ./build/completion/fish/docker.fish debian/docker-ce-cli/usr/share/fish/vendor_completions.d/docker.fish
install -D -p -m 0644 ./build/completion/zsh/_docker debian/docker-ce-cli/usr/share/zsh/vendor-completions/_docker


build/docker:
# This target is used by the "shell-completion" target, which requires either
# "binary" or "dynbinary" to have been built. We don't want to trigger those
# to prevent replacing a static binary with a dynamic one, or vice-versa.
@echo "Run 'make binary' or 'make dynbinary' first" && exit 1

.PHONY: shell-completion
shell-completion: build/docker # requires either "binary" or "dynbinary" to be built.
shell-completion: ## generate shell-completion scripts
@ ./scripts/build/shell-completion

.PHONY: manpages
manpages: ## generate man pages from go source and markdown
Expand Down
21 changes: 21 additions & 0 deletions scripts/build/shell-completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env sh
#
# Build the shell completion scripts
#

set -eu

. ./scripts/build/.variables

# generate the shell completion scripts and store them in build/completion.
if [ "$(go env GOOS)" != "windows" ]; then
if [ ! -f ./build/docker ]; then
echo "Run 'make binary' or 'make dynbinary' first"
exit 1
fi

mkdir -p build/completion/bash build/completion/fish build/completion/zsh
./build/docker completion bash > build/completion/bash/docker
./build/docker completion fish > build/completion/fish/docker.fish
./build/docker completion zsh > build/completion/zsh/_docker
fi

0 comments on commit b8879a4

Please sign in to comment.