Skip to content

Commit

Permalink
Makefile: build completion scripts as part of (dyn)binary
Browse files Browse the repository at this point in the history
Build the (cobra) generated completion scripts when building
the binaries, and store them inside build/completions.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jan 23, 2025
1 parent 17c5fe6 commit 485bc7d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ fmt: ## run gofumpt (if present) or gofmt
.PHONY: binary
binary: ## build executable for Linux
./scripts/build/binary
./scripts/build/completion

.PHONY: dynbinary
dynbinary: ## build dynamically linked binary
GO_LINKMODE=dynamic ./scripts/build/binary
./scripts/build/completion

.PHONY: plugins
plugins: ## build example CLI plugins
Expand All @@ -88,13 +90,18 @@ authors: ## generate AUTHORS file from git history

.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
# 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

.PHONY: manpages
manpages: ## generate man pages from go source and markdown
Expand Down
19 changes: 19 additions & 0 deletions scripts/build/completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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"
fi

./build/docker completion bash | install -D /dev/stdin build/completion/bash/docker
./build/docker completion zsh | install -D /dev/stdin build/completion/zsh/_docker
./build/docker completion fish | install -D /dev/stdin build/completion/fish/docker.fish
fi

0 comments on commit 485bc7d

Please sign in to comment.