Skip to content

Commit 6ab9b92

Browse files
committed
Makefile: add "shell-completion" target
Add a target to build the (cobra) generated completion and store them inside build/completions. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 17c5fe6 commit 6ab9b92

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

Makefile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,31 @@ authors: ## generate AUTHORS file from git history
8787
scripts/docs/generate-authors.sh
8888

8989
.PHONY: completion
90-
completion: binary
91-
completion: /etc/bash_completion.d/docker
92-
completion: ## generate and install the completion scripts
93-
94-
.PHONY: /etc/bash_completion.d/docker
95-
/etc/bash_completion.d/docker: ## generate and install the bash-completion script
96-
mkdir -p /etc/bash_completion.d
97-
docker completion bash > /etc/bash_completion.d/docker
90+
completion: shell-completion
91+
completion: ## generate and install the shell-completion scripts
92+
# Note: this uses system-wide paths, and so may overwrite completion
93+
# scripts installed as part of deb/rpm packages.
94+
#
95+
# Given that this target is intended to debug/test updated versions, we could
96+
# consider installing in per-user (~/.config, XDG_DATA_DIR) paths instead, but
97+
# this will add more complexity.
98+
#
99+
# See https://github.com/docker/cli/pull/5770#discussion_r1927772710
100+
install -D -p -m 0644 ./build/completion/bash/docker /usr/share/bash-completion/completions/docker
101+
install -D -p -m 0644 ./build/completion/fish/docker.fish debian/docker-ce-cli/usr/share/fish/vendor_completions.d/docker.fish
102+
install -D -p -m 0644 ./build/completion/zsh/_docker debian/docker-ce-cli/usr/share/zsh/vendor-completions/_docker
103+
104+
105+
build/docker:
106+
# This target is used by the "shell-completion" target, which requires either
107+
# "binary" or "dynbinary" to have been built. We don't want to trigger those
108+
# to prevent replacing a static binary with a dynamic one, or vice-versa.
109+
@echo "Run 'make binary' or 'make dynbinary' first" && exit 1
110+
111+
.PHONY: shell-completion
112+
shell-completion: build/docker # requires either "binary" or "dynbinary" to be built.
113+
shell-completion: ## generate shell-completion scripts
114+
@ ./scripts/build/shell-completion
98115

99116
.PHONY: manpages
100117
manpages: ## generate man pages from go source and markdown

scripts/build/shell-completion

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Build the shell completion scripts
4+
#
5+
6+
set -eu
7+
8+
. ./scripts/build/.variables
9+
10+
# generate the shell completion scripts and store them in build/completion.
11+
if [ "$(go env GOOS)" != "windows" ]; then
12+
if [ ! -f ./build/docker ]; then
13+
echo "Run 'make binary' or 'make dynbinary' first"
14+
exit 1
15+
fi
16+
17+
mkdir -p build/completion/bash build/completion/fish build/completion/zsh
18+
./build/docker completion bash > build/completion/bash/docker
19+
./build/docker completion fish > build/completion/fish/docker.fish
20+
./build/docker completion zsh > build/completion/zsh/_docker
21+
fi

0 commit comments

Comments
 (0)