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>
This commit is contained in:
Padraig Connolly
2017-01-10 17:10:39 +00:00
committed by Damjan Marion
parent c3af7bf104
commit 69915cba2d
5 changed files with 55 additions and 0 deletions

3
.gitignore vendored
View File

@@ -88,3 +88,6 @@ GTAGS
# Build files in the test directory
/test/*.ok
# vppctl command list
/src/scripts/vppctl-cmd-list

View File

@@ -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 ; \

View File

@@ -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)

View File

@@ -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

View File

@@ -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