Skip to content

Commit 2993e97

Browse files
Merge pull request #6442 from Luap99/podman-autocomplete
Shell completion
2 parents 6d9d9fe + ae38166 commit 2993e97

File tree

169 files changed

+5975
-5988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+5975
-5988
lines changed

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ OCI_RUNTIME ?= ""
4848

4949
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
5050
ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
51+
FISHINSTALLDIR=${PREFIX}/share/fish/vendor_completions.d
5152

5253
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
5354

@@ -474,6 +475,15 @@ changelog: ## Generate changelog
474475
$(shell cat $(TMPFILE) >> changelog.txt)
475476
$(shell rm $(TMPFILE))
476477

478+
completions: binaries
479+
install ${SELINUXOPT} -d -m 755 completions/{bash,zsh,fish}
480+
./bin/podman completion bash --no-desc -f completions/bash/podman
481+
./bin/podman-remote completion bash --no-desc -f completions/bash/podman-remote
482+
./bin/podman completion zsh -f completions/zsh/_podman
483+
./bin/podman-remote completion zsh -f completions/zsh/_podman-remote
484+
./bin/podman completion fish -f completions/fish/podman.fish
485+
./bin/podman-remote completion fish -f completions/fish/podman-remote.fish
486+
477487
.PHONY: install
478488
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations
479489

@@ -512,8 +522,13 @@ install.man: docs install.man-nobuild
512522
install.completions:
513523
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
514524
install ${SELINUXOPT} -m 644 completions/bash/podman ${DESTDIR}${BASHINSTALLDIR}
525+
install ${SELINUXOPT} -m 644 completions/bash/podman-remote ${DESTDIR}${BASHINSTALLDIR}
515526
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
516527
install ${SELINUXOPT} -m 644 completions/zsh/_podman ${DESTDIR}${ZSHINSTALLDIR}
528+
install ${SELINUXOPT} -m 644 completions/zsh/_podman-remote ${DESTDIR}${ZSHINSTALLDIR}
529+
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${FISHINSTALLDIR}
530+
install ${SELINUXOPT} -m 644 completions/fish/podman.fish ${DESTDIR}${FISHINSTALLDIR}
531+
install ${SELINUXOPT} -m 644 completions/fish/podman-remote.fish ${DESTDIR}${FISHINSTALLDIR}
517532

518533
.PHONY: install.cni
519534
install.cni:
@@ -656,9 +671,20 @@ API.md: pkg/varlink/io.podman.varlink
656671
$(GO) generate ./docs/...
657672

658673
.PHONY: validate.completions
659-
validate.completions: completions/bash/podman
674+
validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
675+
validate.completions:
676+
# Check that nobody has manually edited the completion scripts
677+
# If this check fails run make completions to restore the correct scripts
678+
diff completions/bash/podman <(./bin/podman completion --no-desc bash)
679+
diff completions/zsh/_podman <(./bin/podman completion zsh)
680+
diff completions/fish/podman.fish <(./bin/podman completion fish)
681+
diff completions/bash/podman-remote <(./bin/podman-remote completion --no-desc bash)
682+
diff completions/zsh/_podman-remote <(./bin/podman-remote completion zsh)
683+
diff completions/fish/podman-remote.fish <(./bin/podman-remote completion fish)
684+
# Check if the files can be loaded by the shell
660685
. completions/bash/podman
661686
if [ -x /bin/zsh ]; then /bin/zsh completions/zsh/_podman; fi
687+
if [ -x /bin/fish ]; then /bin/fish completions/fish/podman.fish; fi
662688

663689
.PHONY: validate
664690
validate: gofmt lint .gitvalidation validate.completions man-page-check swagger-check

cmd/podman/auto-update.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/containers/common/pkg/auth"
7+
"github.com/containers/common/pkg/completion"
78
"github.com/containers/podman/v2/cmd/podman/registry"
89
"github.com/containers/podman/v2/pkg/domain/entities"
910
"github.com/containers/podman/v2/pkg/errorhandling"
@@ -20,10 +21,11 @@ var (
2021
or similar units that create new containers in order to run the updated images.
2122
Please refer to the podman-auto-update(1) man page for details.`
2223
autoUpdateCommand = &cobra.Command{
23-
Use: "auto-update [options]",
24-
Short: "Auto update containers according to their auto-update policy",
25-
Long: autoUpdateDescription,
26-
RunE: autoUpdate,
24+
Use: "auto-update [options]",
25+
Short: "Auto update containers according to their auto-update policy",
26+
Long: autoUpdateDescription,
27+
RunE: autoUpdate,
28+
ValidArgsFunction: completion.AutocompleteNone,
2729
Example: `podman auto-update
2830
podman auto-update --authfile ~/authfile.json`,
2931
}
@@ -36,7 +38,10 @@ func init() {
3638
})
3739

3840
flags := autoUpdateCommand.Flags()
39-
flags.StringVar(&autoUpdateOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path to the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
41+
42+
authfileFlagName := "authfile"
43+
flags.StringVar(&autoUpdateOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path to the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
44+
_ = autoUpdateCommand.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
4045
}
4146

4247
func autoUpdate(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)