From a384dbbef311b16924ef43ab6e35ec62252c70f7 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 20 Aug 2018 15:00:38 -0500 Subject: [PATCH] Decouple Fault Management from stx-config Add bash completion script for FM shell. Story: 2002828 Task: 22747 Change-Id: I3ac3262573d198ab5b9cfe8bcfd5e52dd9910ebd Signed-off-by: Tao Liu --- python-fmclient/centos/python-fmclient.spec | 6 ++++ .../fmclient/tools/fm.bash_completion | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 python-fmclient/fmclient/tools/fm.bash_completion diff --git a/python-fmclient/centos/python-fmclient.spec b/python-fmclient/centos/python-fmclient.spec index cf20b01a..51dc5a25 100644 --- a/python-fmclient/centos/python-fmclient.spec +++ b/python-fmclient/centos/python-fmclient.spec @@ -20,11 +20,13 @@ Requires: python-six >= 1.9.0 Requires: python-oslo-i18n >= 2.1.0 Requires: python-oslo-utils >= 3.20.0 Requires: python-requests +Requires: bash-completion %description A python client library for Fault Management %define local_bindir /usr/bin/ +%define local_etc_bash_completiond /etc/bash_completion.d/ %define pythonroot /usr/lib64/python2.7/site-packages %define debug_package %{nil} @@ -56,6 +58,9 @@ export PBR_VERSION=%{version} --install-data=/usr/share \ --single-version-externally-managed +install -d -m 755 %{buildroot}%{local_etc_bash_completiond} +install -p -D -m 664 tools/fm.bash_completion %{buildroot}%{local_etc_bash_completiond}/fm.bash_completion + # prep SDK package mkdir -p %{buildroot}/usr/share/remote-clients tar zcf %{buildroot}/usr/share/remote-clients/%{name}-%{version}.tgz --exclude='.gitignore' --exclude='.gitreview' -C .. %{name}-%{version} @@ -68,6 +73,7 @@ rm -rf $RPM_BUILD_ROOT %defattr(-,root,root,-) %doc LICENSE %{local_bindir}/* +%{local_etc_bash_completiond}/* %{pythonroot}/%{pypi_name}/* %{pythonroot}/%{pypi_name}-%{version}*.egg-info diff --git a/python-fmclient/fmclient/tools/fm.bash_completion b/python-fmclient/fmclient/tools/fm.bash_completion new file mode 100644 index 00000000..030fc9d5 --- /dev/null +++ b/python-fmclient/fmclient/tools/fm.bash_completion @@ -0,0 +1,33 @@ +# +# Copyright (c) 2018 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# bash completion for Titanium Cloud fm commands + +_fm_opts="" # lazy init +_fm_flags="" # lazy init +_fm_opts_exp="" # lazy init +_fm() +{ + local cur prev kbc + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [ "x$_fm_opts" == "x" ] ; then + kbc="`fm bash-completion | sed -e "s/ -h / /"`" + _fm_opts="`echo "$kbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/[ ][ ]*/ /g"`" + _fm_flags="`echo " $kbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/[ ][ ]*/ /g"`" + _fm_opts_exp="`echo $_fm_opts | sed -e "s/[ ]/|/g"`" + fi + + if [[ " ${COMP_WORDS[@]} " =~ " "($_fm_opts_exp)" " && "$prev" != "help" ]] ; then + COMPREPLY=($(compgen -W "${_fm_flags}" -- ${cur})) + else + COMPREPLY=($(compgen -W "${_fm_opts}" -- ${cur})) + fi + return 0 +} +complete -F _fm fm