Skip to content

Commit

Permalink
Merge pull request #6442 from Luap99/podman-autocomplete
Browse files Browse the repository at this point in the history
Shell completion
  • Loading branch information
openshift-merge-robot committed Nov 13, 2020
2 parents 6d9d9fe + ae38166 commit 2993e97
Show file tree
Hide file tree
Showing 169 changed files with 5,975 additions and 5,988 deletions.
28 changes: 27 additions & 1 deletion Makefile
Expand Up @@ -48,6 +48,7 @@ OCI_RUNTIME ?= ""

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

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

Expand Down Expand Up @@ -474,6 +475,15 @@ changelog: ## Generate changelog
$(shell cat $(TMPFILE) >> changelog.txt)
$(shell rm $(TMPFILE))

completions: binaries
install ${SELINUXOPT} -d -m 755 completions/{bash,zsh,fish}
./bin/podman completion bash --no-desc -f completions/bash/podman
./bin/podman-remote completion bash --no-desc -f completions/bash/podman-remote
./bin/podman completion zsh -f completions/zsh/_podman
./bin/podman-remote completion zsh -f completions/zsh/_podman-remote
./bin/podman completion fish -f completions/fish/podman.fish
./bin/podman-remote completion fish -f completions/fish/podman-remote.fish

.PHONY: install
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations

Expand Down Expand Up @@ -512,8 +522,13 @@ install.man: docs install.man-nobuild
install.completions:
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
install ${SELINUXOPT} -m 644 completions/bash/podman ${DESTDIR}${BASHINSTALLDIR}
install ${SELINUXOPT} -m 644 completions/bash/podman-remote ${DESTDIR}${BASHINSTALLDIR}
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
install ${SELINUXOPT} -m 644 completions/zsh/_podman ${DESTDIR}${ZSHINSTALLDIR}
install ${SELINUXOPT} -m 644 completions/zsh/_podman-remote ${DESTDIR}${ZSHINSTALLDIR}
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${FISHINSTALLDIR}
install ${SELINUXOPT} -m 644 completions/fish/podman.fish ${DESTDIR}${FISHINSTALLDIR}
install ${SELINUXOPT} -m 644 completions/fish/podman-remote.fish ${DESTDIR}${FISHINSTALLDIR}

.PHONY: install.cni
install.cni:
Expand Down Expand Up @@ -656,9 +671,20 @@ API.md: pkg/varlink/io.podman.varlink
$(GO) generate ./docs/...

.PHONY: validate.completions
validate.completions: completions/bash/podman
validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
validate.completions:
# Check that nobody has manually edited the completion scripts
# If this check fails run make completions to restore the correct scripts
diff completions/bash/podman <(./bin/podman completion --no-desc bash)
diff completions/zsh/_podman <(./bin/podman completion zsh)
diff completions/fish/podman.fish <(./bin/podman completion fish)
diff completions/bash/podman-remote <(./bin/podman-remote completion --no-desc bash)
diff completions/zsh/_podman-remote <(./bin/podman-remote completion zsh)
diff completions/fish/podman-remote.fish <(./bin/podman-remote completion fish)
# Check if the files can be loaded by the shell
. completions/bash/podman
if [ -x /bin/zsh ]; then /bin/zsh completions/zsh/_podman; fi
if [ -x /bin/fish ]; then /bin/fish completions/fish/podman.fish; fi

.PHONY: validate
validate: gofmt lint .gitvalidation validate.completions man-page-check swagger-check
Expand Down
15 changes: 10 additions & 5 deletions cmd/podman/auto-update.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

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

flags := autoUpdateCommand.Flags()
flags.StringVar(&autoUpdateOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path to the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")

authfileFlagName := "authfile"
flags.StringVar(&autoUpdateOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path to the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
_ = autoUpdateCommand.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
}

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

0 comments on commit 2993e97

Please sign in to comment.