Commit d9bf6320 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

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: default avatarMichal Berger <michalx.berger@intel.com>
Change-Id: I9ca0b919445e5a08c49ab8fa5d0a3acc2e5c4e4e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8448


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarPawel Piatek <pawelx.piatek@intel.com>
parent 7c06be85
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -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
	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"))