diff options
author | Padraig Connolly <padraig.connolly@intel.com> | 2017-01-10 17:10:39 +0000 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2017-01-13 20:18:18 +0000 |
commit | 69915cba2d6e169343c03c8eef48e6b2d2296e3a (patch) | |
tree | 6fdee21681dd342170ffe94da9890a7a651b726b | |
parent | c3af7bf104919be668d696fc1ac05893712dae06 (diff) |
vppctl: new bash completion for vppctl commands
Bash completion for vppctl
*vppctl_completion uses generated list vppctl-cmd-list to provide bash completion
*List of commands generated using grep, then moved by vpp packaging
*Once vpp package installed restart bash to use
Change-Id: I3b25e55a432c395af421231cf7c37c2e243fee61
Signed-off-by: Padraig Connolly <padraig.connolly@intel.com>
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | build-data/platforms.mk | 8 | ||||
-rw-r--r-- | build-root/rpm/vpp.spec | 6 | ||||
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/scripts/vppctl_completion | 30 |
5 files changed, 55 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 61c407ff857..ab997faab36 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,6 @@ GTAGS # Build files in the test directory /test/*.ok + +# vppctl command list +/src/scripts/vppctl-cmd-list diff --git a/build-data/platforms.mk b/build-data/platforms.mk index e192155ba5a..4183675042b 100644 --- a/build-data/platforms.mk +++ b/build-data/platforms.mk @@ -75,6 +75,14 @@ install-deb: $(patsubst %,%-find-source,$(ROOT_PACKAGES)) echo ../../src/vpp/conf/80-vpp.conf /etc/sysctl.d \ >> deb/debian/vpp.install ; \ \ + : bash completion for vppctl ; \ + echo ../../src/scripts/vppctl_completion /etc/bash_completion.d \ + >> deb/debian/vpp.install ; \ + \ + : move dictionary of vppctl commands ; \ + echo ../../src/scripts/vppctl-cmd-list /usr/share/vpp \ + >> deb/debian/vpp.install ; \ + \ : dev package needs a couple of additions ; \ echo ../$(INSTALL_PREFIX)$(ARCH)/vpp/bin/vppapigen /usr/bin \ >> deb/debian/vpp-dev.install ; \ diff --git a/build-root/rpm/vpp.spec b/build-root/rpm/vpp.spec index b63d3e17aed..8308dbf5af1 100644 --- a/build-root/rpm/vpp.spec +++ b/build-root/rpm/vpp.spec @@ -125,6 +125,8 @@ install -p -m 644 %{_mu_build_dir}/../src/vpp/conf/80-vpp.conf %{buildroot}/etc/ # libraries # mkdir -p -m755 %{buildroot}%{_libdir} +mkdir -p -m755 %{buildroot}/etc/bash_completion.d +mkdir -p -m755 %{buildroot}/usr/share/vpp for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/*/lib* -type f -name '*.so.*.*.*' -print ) do install -p -m 755 $file %{buildroot}%{_libdir} @@ -141,6 +143,8 @@ for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/vpp/share/vpp/api -type do install -p -m 644 $file %{buildroot}/usr/share/vpp/api done +install -p -m 644 %{_mu_build_dir}/../src/scripts/vppctl_completion %{buildroot}/etc/bash_completion.d +install -p -m 644 %{_mu_build_dir}/../src/scripts/vppctl-cmd-list %{buildroot}/usr/share/vpp # Lua bindings mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/lua/examples/cli @@ -269,6 +273,8 @@ fi %exclude %{_libdir}/vpp_api_test_plugins %{_libdir}/* /usr/share/vpp/api/* +/etc/bash_completion.d/vppctl_completion +/usr/share/vpp/vppctl-cmd-list %files api-lua %defattr(644,root,root) diff --git a/src/Makefile.am b/src/Makefile.am index 18a41a153ee..227accc029c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,6 +28,14 @@ noinst_HEADERS = dist_bin_SCRIPTS = lib_LTLIBRARIES = BUILT_SOURCES = +install-data-local: + @echo "Building vppctl command list..." + @DIR_SEARCH="$(srcdir)" ; \ + DIR_EXCLUDE="examples" ; \ + GREP_TIME=`time (grep -wIr "\.path = " $$DIR_SEARCH --exclude-dir=$$DIR_EXCLUDE \ + | cut -d '"' -f2 | sort -u > $(srcdir)/scripts/vppctl-cmd-list) 2>&1` ; \ + GREP_TIME=`echo $$GREP_TIME | awk '{print $$2}'` ; \ + echo "Command list built, Time taken: $$GREP_TIME" ############################################################################### # DPDK diff --git a/src/scripts/vppctl_completion b/src/scripts/vppctl_completion new file mode 100644 index 00000000000..2a64e9abd08 --- /dev/null +++ b/src/scripts/vppctl_completion @@ -0,0 +1,30 @@ +#Copyright 2017 Intel Corporation +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +_vppctl() +{ + local cur prev num opts + COMPREPLY=( $(compgen -f ${cur}) ) + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[@]:1}" + num="$((${#COMP_WORDS[@]}-1))" + + VPP_CMD_LIST="$(cat /usr/share/vpp/vppctl-cmd-list)" + + opts="$(awk -v prev="^$prev" -v num=$num '{if($0 ~ prev) print $num}' <<< "${VPP_CMD_LIST}")" + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + +} +complete -F _vppctl vppctl |