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 <TAB> 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 <michalx.berger@intel.com> Change-Id: I9ca0b919445e5a08c49ab8fa5d0a3acc2e5c4e4e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8448 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Pawel Piatek <pawelx.piatek@intel.com>
This commit is contained in:
parent
7c06be855a
commit
d9bf6320b1
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user