Skip to content

Commit

Permalink
New 'make completions' target
Browse files Browse the repository at this point in the history
Generate shell completion files for podman and podman-remote
and for all known shells (bash, fish, zsh). Fix Readme file
in completions dir: it suggested running 'make completion',
singular; no such target existed. Since the install target
is plural, I choose to make the new target plural also.

This is intended for use in CI some day, in a check such as:

  (in contrib/cirrus/runner.sh):

    make completions
    SUGGESTION="run 'make completions' and commit all changes" ./hack/tree_status.sh

The goal would be to make sure that any new podman subcommands
or flags are accompanied by their corresponding shell helpers
on all commits.

IT IS NOT POSSIBLE TO ENFORCE THIS NOW. As I understand it,
Cobra is slow to incorporate community PRs, so the podman team
has chosen to sneak in completion files generated by an
unreleased and un-vendored version of Cobra. Running 'make
completions' right now would clobber those and result in
a diminished user experience.

I'm submitting this anyway as a stepping-stone toward that
future day when we can create such a CI hook.

[NO TESTS NEEDED]

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Feb 1, 2021
1 parent 182e841 commit ee8ee65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ install.libseccomp.sudo:
cd ../../seccomp/libseccomp && git checkout --detach $(LIBSECCOMP_COMMIT) && ./autogen.sh && ./configure --prefix=/usr && make all && make install


.PHONY: completions
completions: podman podman-remote
# key = shell, value = completion filename
declare -A outfiles=([bash]=%s [zsh]=_%s [fish]=%s.fish);\
for shell in $${!outfiles[*]}; do \
for remote in "" "-remote"; do \
podman="podman$$remote"; \
outfile=$$(printf "completions/$$shell/$${outfiles[$$shell]}" $$podman); \
./bin/$$podman completion $$shell >| $$outfile; \
done;\
done

.PHONY: validate.completions
validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
validate.completions:
Expand Down
2 changes: 1 addition & 1 deletion completions/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Podman offers shell completion scripts for bash, zsh and fish. The completion scripts are available for both `podman` and `podman-remote`.

The shell completion scripts are generated by `make completion`, do not edit these files directly. To install them you can run `sudo make install.completions`.
The shell completion scripts are generated by `make completions`; do not edit these files directly. To install them you can run `sudo make install.completions`.

For information about these scripts see [`man podman-completion`](../docs/source/markdown/podman-completion.1.md)

0 comments on commit ee8ee65

Please sign in to comment.