From a40d7b53aa6fdab53ea6974816d2c4fb07cf5161 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Thu, 11 Aug 2016 08:43:23 -0500 Subject: [PATCH] add support for completions Signed-off-by: Mike Brown --- Makefile | 12 ++++++------ cmd/skopeo/main.go | 1 + hack/make/bash_autocomplete | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 hack/make/bash_autocomplete diff --git a/Makefile b/Makefile index b69b540d..19bd3962 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,11 @@ -.PHONY: all binary build-container build-local clean install install-binary shell test-integration +.PHONY: all binary build-container build-local clean install install-binary install-completions shell test-integration export GO15VENDOREXPERIMENT=1 PREFIX ?= ${DESTDIR}/usr INSTALLDIR=${PREFIX}/bin MANINSTALLDIR=${PREFIX}/share/man -# TODO(runcom) -#BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions +BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions GO_MD2MAN ?= /usr/bin/go-md2man ifeq ($(DEBUG), 1) @@ -60,9 +59,7 @@ docs: $(MANPAGES_MD:%.md=%) clean: rm -f skopeo docs/*.1 -install: install-binary install-docs - # TODO(runcom) - #install -m 644 completion/bash/skopeo ${BASHINSTALLDIR}/ +install: install-binary install-docs install-completions install-binary: ./skopeo install -d -m 0755 ${INSTALLDIR} @@ -72,6 +69,9 @@ install-docs: docs/skopeo.1 install -d -m 0755 ${MANINSTALLDIR}/man1 install -m 644 docs/skopeo.1 ${MANINSTALLDIR}/man1/ +install-completions: + install -m 644 -T hack/make/bash_autocomplete ${BASHINSTALLDIR}/skopeo + shell: build-container $(DOCKER_RUN_DOCKER) bash diff --git a/cmd/skopeo/main.go b/cmd/skopeo/main.go index b56eee0a..3c791076 100644 --- a/cmd/skopeo/main.go +++ b/cmd/skopeo/main.go @@ -16,6 +16,7 @@ var gitCommit = "" // createApp returns a cli.App to be run or tested. func createApp() *cli.App { app := cli.NewApp() + app.EnableBashCompletion = true app.Name = "skopeo" if gitCommit != "" { app.Version = fmt.Sprintf("%s commit: %s", version.Version, gitCommit) diff --git a/hack/make/bash_autocomplete b/hack/make/bash_autocomplete new file mode 100644 index 00000000..b2b871d0 --- /dev/null +++ b/hack/make/bash_autocomplete @@ -0,0 +1,14 @@ +#! /bin/bash + +: ${PROG:=$(basename ${BASH_SOURCE})} + +_cli_bash_autocomplete() { + local cur opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + } + + complete -F _cli_bash_autocomplete $PROG