Whamcloud - gitweb
LU-12734 misc: allow older bash_completion versions 59/36459/3
authorAndreas Dilger <adilger@whamcloud.com>
Tue, 15 Oct 2019 23:07:53 +0000 (17:07 -0600)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 5 Nov 2019 18:32:09 +0000 (18:32 +0000)
Allow the "lctl" bash_completion to work on older versions which
which don't have _init_completions().  Check at runtime if this
function is available, and if not fall back to an older interface.

Has been manually tested with both bash-completion v1.3 and v2.1.

Fixes: f87a7f2656ce ("LU-12734 misc: add bash completion for lctl set/get_param)"
Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I3822c0967354d83d12f299c4be3023b2fc254035
Reviewed-on: https://review.whamcloud.com/36459
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Quentin Bouget <quentin.bouget@cea.fr>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Nathaniel Clark <nclark@whamcloud.com>
Reviewed-by: Dominique Martinet <dominique.martinet@cea.fr>
lustre/scripts/bash-completion/lctl

index 485bb69..e471e18 100644 (file)
@@ -2,8 +2,15 @@ _lctl()
 {
        local cur prev words cword
 
 {
        local cur prev words cword
 
-       _init_completion || return
        COMPREPLY=()
        COMPREPLY=()
+       # allow different versions of bash_completion to work
+       if declare -F _init_completion > /dev/null; then
+               # this provides more functionality, but is only in v2.x
+               _init_completion || return
+       else
+               # this is compatible with both v1.3 and v2.x
+               _get_comp_words_by_ref -n : cur prev words cword
+       fi
 
        if [[ "$cword" == "1" ]]; then
                COMPREPLY=( $( compgen -W '$(lctl --list-commands |
 
        if [[ "$cword" == "1" ]]; then
                COMPREPLY=( $( compgen -W '$(lctl --list-commands |