vppctl: new bash completion for vppctl commands 48/4648/6
authorPadraig Connolly <padraig.connolly@intel.com>
Tue, 10 Jan 2017 17:10:39 +0000 (17:10 +0000)
committerDamjan Marion <dmarion.lists@gmail.com>
Fri, 13 Jan 2017 20:18:18 +0000 (20:18 +0000)
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>
.gitignore
build-data/platforms.mk
build-root/rpm/vpp.spec
src/Makefile.am
src/scripts/vppctl_completion [new file with mode: 0644]

index 61c407f..ab997fa 100644 (file)
@@ -88,3 +88,6 @@ GTAGS
 
 # Build files in the test directory
 /test/*.ok
+
+# vppctl command list
+/src/scripts/vppctl-cmd-list
index e192155..4183675 100644 (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 ;                              \
index b63d3e1..8308dbf 100644 (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)
index 18a41a1..227accc 100644 (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
diff --git a/src/scripts/vppctl_completion b/src/scripts/vppctl_completion
new file mode 100644 (file)
index 0000000..2a64e9a
--- /dev/null
@@ -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