From d9bf6320b10023473841d1afd0625eec22900a37 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Mon, 21 Jun 2021 15:45:44 +0200 Subject: [PATCH] bash-completion: Use -h output in case app is not available under the sock In case SPDK app crashed the leftover sock file would force completion to use rpc_get_methods() instead of the -h output to get the list of rpc functions. The end result would look something like: $ rpc.py IsSPDKapplicationrunning? By the very accident this is quite informative about the state of the app but from bash-completion standpoint not very useful. Instead, if rpc_get_methods() fail fallback to -h output. Signed-off-by: Michal Berger Change-Id: I9ca0b919445e5a08c49ab8fa5d0a3acc2e5c4e4e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8448 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Karol Latecki Reviewed-by: Pawel Piatek --- scripts/bash-completion/spdk | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/bash-completion/spdk b/scripts/bash-completion/spdk index 3f884f9df..a7cf5bc39 100644 --- a/scripts/bash-completion/spdk +++ b/scripts/bash-completion/spdk @@ -25,11 +25,6 @@ _get_help_pos() { } _get_default_rpc_methods() { - if [[ -S $rpc_sock ]]; then - _get_supported_methods "$1" - return 0 - fi - local aliases method names # Don't squash whitespaces, slurp the entire line while read -r; do @@ -53,7 +48,10 @@ _get_default_rpc_methods() { _get_supported_methods() { local method methods - mapfile -t methods < <("$1" -s "$rpc_sock" rpc_get_methods 2> /dev/null) + if ! methods=($("$1" -s "$rpc_sock" rpc_get_methods 2> /dev/null)); then + _get_default_rpc_methods "$1" + return 0 + fi ((${#methods[@]} > 0)) || return 0 # Kill the json flavor @@ -209,7 +207,11 @@ _rpc() { local -A rpc_methods=() _set_rpc_sock - _get_default_rpc_methods "$rpc" + if [[ -S $rpc_sock ]]; then + _get_supported_methods "$rpc" + else + _get_default_rpc_methods "$rpc" + fi if method=$(_method_in_words); then COMPREPLY=($(compgen -W '$(_get_help_rpc_method "$rpc" "$method")' -- "$cur"))