From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH] ndctl, bash-completion: add completion for ndctl-monitor
Date: Wed, 18 Jul 2018 18:38:46 -0600 [thread overview]
Message-ID: <20180719003846.12068-1-vishal.l.verma@intel.com> (raw)
Add bash completions for the 'ndctl monitor' command. This introduces
some new semantics where the completion for --log= can be either a file
path, or one of the canonical options (currently 'standard' or 'syslog'.
We handle this by (ab)using compgen to test whether the entered
string is a substring of one of the canonical strings. If it is, then we
include the array of the canonical strngs as well as regular _filedir
output in our reply. If not, then we rely on _filedir doing its thing.
Cc: QI Fuli <qi.fuli@jp.fujitsu.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
contrib/ndctl | 44 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/contrib/ndctl b/contrib/ndctl
index 7a99baf..515494d 100755
--- a/contrib/ndctl
+++ b/contrib/ndctl
@@ -91,7 +91,7 @@ __ndctlcomp()
COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
for cword in "${COMPREPLY[@]}"; do
- if [[ "$cword" == @(--bus|--region|--type|--mode|--size|--dimm|--reconfig|--uuid|--name|--sector-size|--map|--namespace|--input|--output|--label-version|--align|--block|--count|--firmware|--media-temperature|--ctrl-temperature|--spares|--media-temperature-threshold|--ctrl-temperature-threshold|--spares-threshold|--media-temperature-alarm|--ctrl-temperature-alarm|--spares-alarm|--numa-node) ]]; then
+ if [[ "$cword" == @(--bus|--region|--type|--mode|--size|--dimm|--reconfig|--uuid|--name|--sector-size|--map|--namespace|--input|--output|--label-version|--align|--block|--count|--firmware|--media-temperature|--ctrl-temperature|--spares|--media-temperature-threshold|--ctrl-temperature-threshold|--spares-threshold|--media-temperature-alarm|--ctrl-temperature-alarm|--spares-alarm|--numa-node|--log|--dimm-event|--config-file) ]]; then
COMPREPLY[$i]="${cword}="
else
COMPREPLY[$i]="${cword} "
@@ -167,10 +167,13 @@ __ndctl_get_nodes()
echo "$nlist"
}
+saveopts=""
__ndctl_file_comp()
{
local cur="$1"
+
_filedir
+ saveopts="${COMPREPLY[*]}"
}
__ndctl_comp_options()
{
@@ -179,6 +182,7 @@ __ndctl_comp_options()
if [[ "$cur" == *=* ]]; then
local cur_subopt=${cur%%=*}
+ local cur_arg=${cur##*=}
case $cur_subopt in
--bus)
opts=$(__ndctl_get_buses)
@@ -219,7 +223,7 @@ __ndctl_comp_options()
--input)
;&
--firmware)
- __ndctl_file_comp "${cur##*=}"
+ __ndctl_file_comp "$cur_arg"
return
;;
--label-version)
@@ -235,11 +239,45 @@ __ndctl_comp_options()
--numa-node)
opts=$(__ndctl_get_nodes)
;;
+ --log)
+ local my_args=( "standard" "syslog" )
+
+ __ndctl_file_comp "$cur_arg"
+ if [ -n "$cur_arg" ]; then
+ # if $cur_arg is a substring of $my_args (as
+ # determined by compgen), then we continue to
+ # manually construct opts using $my_args, but
+ # if it is not a substring (compgen returns
+ # empty), then we defer to _ndctl_file_comp
+ # and return immediately. (NOTE: subscripting
+ # of the my_args array here is fragile).
+ # If this pattern repeats, where we need to
+ # complete with filenames and some custom
+ # options, find a better way to generalize this
+ if [ -z "$(compgen -W "${my_args[*]}" -- "$cur_arg")" ]; then
+ return
+ fi
+ fi
+ opts="${my_args[*]} $saveopts"
+ ;;
+ --dimm-event)
+ opts="all \
+ dimm-spares-remaining \
+ dimm-media-temperature \
+ dimm-controller-temperature \
+ dimm-health-state \
+ dimm-unclean-shutdown \
+ "
+ ;;
+ --config-file)
+ __ndctl_file_comp "$cur_arg"
+ return
+ ;;
*)
return
;;
esac
- __ndctlcomp "$opts" "${cur##*=}"
+ __ndctlcomp "$opts" "$cur_arg"
fi
}
--
2.14.4
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
reply other threads:[~2018-07-19 0:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180719003846.12068-1-vishal.l.verma@intel.com \
--to=vishal.l.verma@intel.com \
--cc=linux-nvdimm@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).