Whamcloud - gitweb
LU-12734 misc: add bash completion for lctl set/get_param 05/36105/6
authorDominique Martinet <dominique.martinet@cea.fr>
Mon, 9 Sep 2019 14:46:45 +0000 (16:46 +0200)
committerOleg Drokin <green@whamcloud.com>
Fri, 20 Sep 2019 07:55:09 +0000 (07:55 +0000)
Add some start of bash completion for lctl, mainly set_param and
get_param, and modify build system to install it.

Test-Parameters: trivial
Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr>
Change-Id: I16d2698e782702375c7fa3edf3bfde2e3b197297
Reviewed-on: https://review.whamcloud.com/36105
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Quentin Bouget <quentin.bouget@cea.fr>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
debian/lustre-client-utils.install.in
debian/lustre-server-utils.install.in
lustre.spec.in
lustre/autoconf/lustre-core.m4
lustre/scripts/Makefile.am
lustre/scripts/bash-completion/lctl [new file with mode: 0644]

index 7f737cf..34ab12c 100644 (file)
@@ -4,3 +4,4 @@ debian/tmp/usr/bin/*                    usr/bin
 debian/tmp/usr/lib/*.so.*              usr/lib
 debian/tmp/lib/systemd/system/*        lib/systemd/system
 debian/tmp/etc/*                       etc
+debian/tmp/usr/share/bash-completion/completions/*     usr/share/bash-completion/completions
index 148f5b5..984523e 100644 (file)
@@ -5,3 +5,4 @@ debian/tmp/usr/lib/*.so.*               usr/lib
 debian/tmp/usr/lib/lustre/*.so*        usr/lib/lustre
 debian/tmp/lib/systemd/system/*        lib/systemd/system
 debian/tmp/etc/*                       etc
+debian/tmp/usr/share/bash-completion/completions/*     usr/share/bash-completion/completions
index 41fdf71..380fe87 100644 (file)
@@ -532,6 +532,7 @@ fi
 %{_mandir}/man?/*
 %endif
 %{_datadir}/lustre
+%{_datadir}/bash-completion/completions/*
 %{_includedir}/lustre
 %{_includedir}/linux/lnet
 %{_includedir}/linux/lustre
index 210ddaa..3995f81 100644 (file)
@@ -3392,6 +3392,23 @@ AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitd
 AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
        [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
 AC_MSG_RESULT([$with_systemdsystemunitdir])
+
+AC_MSG_CHECKING([bash-completion directory])
+AC_ARG_WITH([bash-completion-dir],
+       AS_HELP_STRING([--with-bash-completion-dir[=PATH]],
+               [Install the bash auto-completion script in this directory.]),
+       [],
+       [with_bash_completion_dir=yes])
+AS_IF([test "x$with_bash_completion_dir" = "xyes"], [
+       BASH_COMPLETION_DIR="`pkg-config --variable=completionsdir bash-completion`"
+       AS_IF([test "x$BASH_COMPLETION_DIR" = "x"], [
+               [BASH_COMPLETION_DIR="$datadir/bash-completion/completions"]
+       ])
+], [
+       BASH_COMPLETION_DIR="$with_bash_completion_dir"
+])
+AC_SUBST([BASH_COMPLETION_DIR])
+AC_MSG_RESULT([$BASH_COMPLETION_DIR])
 ]) # LC_CONFIGURE
 
 #
@@ -3411,6 +3428,7 @@ AM_CONDITIONAL(GSS_PIPEFS, test x$enable_gss_pipefs = xyes)
 AM_CONDITIONAL(GSS_SSK, test x$enable_ssk = xyes)
 AM_CONDITIONAL(LIBPTHREAD, test x$enable_libpthread = xyes)
 AM_CONDITIONAL(HAVE_SYSTEMD, test "x$with_systemdsystemunitdir" != "xno")
+AM_CONDITIONAL(ENABLE_BASH_COMPLETION, test "x$with_bash_completion_dir" != "xno")
 AM_CONDITIONAL(XATTR_HANDLER, test "x$lb_cv_compile_xattr_handler_flags" = xyes)
 AM_CONDITIONAL(SELINUX, test "$SELINUX" = "-lselinux")
 AM_CONDITIONAL(GETSEPOL, test x$enable_getsepol = xyes)
index f834235..bbb1cc7 100644 (file)
@@ -82,11 +82,17 @@ endif
 
 endif # UTILS
 
+if ENABLE_BASH_COMPLETION
+bashcompletiondir = $(BASH_COMPLETION_DIR)
+dist_bashcompletion_DATA = bash-completion/lctl
+endif
+
 EXTRA_DIST = license-status lustre_rmmod ldev lc_mon lhbadm \
             lc_servip lustre_routes_config lustre_routes_conversion \
             $(addsuffix .in,$(genscripts)) lfs_migrate lustre_req_history \
             lustre lsvcgss lc_common haconfig Lustre.ha_v2 dkms.mkconf \
-            zfsobj2fid ko2iblnd-probe statechange-lustre.sh
+            zfsobj2fid ko2iblnd-probe statechange-lustre.sh \
+            bash-completion/lctl
 
 CLEANFILES = $(genscripts)
 
diff --git a/lustre/scripts/bash-completion/lctl b/lustre/scripts/bash-completion/lctl
new file mode 100644 (file)
index 0000000..485bb69
--- /dev/null
@@ -0,0 +1,29 @@
+_lctl()
+{
+       local cur prev words cword
+
+       _init_completion || return
+       COMPREPLY=()
+
+       if [[ "$cword" == "1" ]]; then
+               COMPREPLY=( $( compgen -W '$(lctl --list-commands |
+                                            grep -v '^=')' -- "$cur" ) )
+               return 0
+       fi
+
+       case "${words[1]}" in
+       set_param|list_param|get_param)
+               local filter="s/=$//"
+               [[ "${words[1]}" == "set_param" ]] && filter="/[^=/]$/d"
+               mapfile -t COMPREPLY < <(
+                   lctl list_param -F "${cur#[\"\']}*" 2>/dev/null |
+                   sed -e "$filter" -e 's#/$#.#' \
+                       -e "s#^${cur//\*/[^.]*}#$cur#"
+                   )
+               compopt -o nospace
+
+               return 0
+               ;;
+       esac
+} &&
+complete -F _lctl lctl