From f87a7f2656ceff174a00933a170032f093ecc72d Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 9 Sep 2019 16:46:45 +0200 Subject: [PATCH] LU-12734 misc: add bash completion for lctl set/get_param 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 Change-Id: I16d2698e782702375c7fa3edf3bfde2e3b197297 Reviewed-on: https://review.whamcloud.com/36105 Tested-by: jenkins Reviewed-by: Andreas Dilger Reviewed-by: Quentin Bouget Tested-by: Maloo Reviewed-by: Oleg Drokin --- debian/lustre-client-utils.install.in | 1 + debian/lustre-server-utils.install.in | 1 + lustre.spec.in | 1 + lustre/autoconf/lustre-core.m4 | 18 ++++++++++++++++++ lustre/scripts/Makefile.am | 8 +++++++- lustre/scripts/bash-completion/lctl | 29 +++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lustre/scripts/bash-completion/lctl diff --git a/debian/lustre-client-utils.install.in b/debian/lustre-client-utils.install.in index 7f737cf..34ab12c 100644 --- a/debian/lustre-client-utils.install.in +++ b/debian/lustre-client-utils.install.in @@ -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 diff --git a/debian/lustre-server-utils.install.in b/debian/lustre-server-utils.install.in index 148f5b5..984523e 100644 --- a/debian/lustre-server-utils.install.in +++ b/debian/lustre-server-utils.install.in @@ -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 diff --git a/lustre.spec.in b/lustre.spec.in index 41fdf71..380fe87 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -532,6 +532,7 @@ fi %{_mandir}/man?/* %endif %{_datadir}/lustre +%{_datadir}/bash-completion/completions/* %{_includedir}/lustre %{_includedir}/linux/lnet %{_includedir}/linux/lustre diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 210ddaa..3995f81 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -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) diff --git a/lustre/scripts/Makefile.am b/lustre/scripts/Makefile.am index f834235..bbb1cc7 100644 --- a/lustre/scripts/Makefile.am +++ b/lustre/scripts/Makefile.am @@ -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 index 0000000..485bb69 --- /dev/null +++ b/lustre/scripts/bash-completion/lctl @@ -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 -- 1.8.3.1