diff mbox

[ndctl,v2] ndctl: make completion smarter wrt mode/type/idle options

Message ID 1467062845-24290-1-git-send-email-vishal.l.verma@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Verma, Vishal L June 27, 2016, 9:27 p.m. UTC
Add three new 'filters' for mode, type, and idle.

'mode' and 'type' work with each other to prevent a blk namespace from
showing modes like 'dax' or 'memory', or if those modes are specified,
then limiting 'type' to 'pmem'.

Also show completions for --map= only if mode is 'memory'.

For idle filtering (typically relevant for 'ndctl list', only show idle
{namespaces, regions} in the completion id a --idle has been specified
on the command line so far. This makes sense because trying to list an
idle namespace without --idle (even if you know that is the one you
want) won't show any output withot --idle.

Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---

v2: Remove filtering for --map=  (Dan)

 contrib/ndctl | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

Comments

Verma, Vishal L June 27, 2016, 9:29 p.m. UTC | #1
On Mon, 2016-06-27 at 15:27 -0600, Vishal Verma wrote:
> Add three new 'filters' for mode, type, and idle.

> 

> 'mode' and 'type' work with each other to prevent a blk namespace from

> showing modes like 'dax' or 'memory', or if those modes are specified,

> then limiting 'type' to 'pmem'.

> 

> Also show completions for --map= only if mode is 'memory'.


Oops, this line should've been deleted.. Can you fixup please?

> 

> For idle filtering (typically relevant for 'ndctl list', only show

> idle

> {namespaces, regions} in the completion id a --idle has been specified

> on the command line so far. This makes sense because trying to list an

> idle namespace without --idle (even if you know that is the one you

> want) won't show any output withot --idle.

> 

> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

> ---

> 

> v2: Remove filtering for --map=  (Dan)

> 

>  contrib/ndctl | 27 +++++++++++++++++++++++----

>  1 file changed, 23 insertions(+), 4 deletions(-)

> 

> diff --git a/contrib/ndctl b/contrib/ndctl

> index b7a82fc..160a9dc 100755

> --- a/contrib/ndctl

> +++ b/contrib/ndctl

> @@ -110,6 +110,8 @@ __ndctl_get_regions()

>  {

>  	local opts="--regions $*"

>  	[ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter"

> +	[ -n "$type_filter" ] && opts="$opts --type=$type_filter"

> +	[ -n "$idle_filter" ] && opts="$opts --idle"

>  	echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\"

> -f4)"

>  }

>  

> @@ -118,6 +120,8 @@ __ndctl_get_ns()

>  	opts="--namespaces $*"

>  	[ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter"

>  	[ -n "$reg_filter" ] && opts="$opts --bus=$reg_filter"

> +	[ -n "$type_filter" ] && opts="$opts --type=$type_filter"

> +	[ -n "$idle_filter" ] && opts="$opts --idle"

>  	echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\"

> -f4)"

>  }

>  

> @@ -147,7 +151,7 @@ __ndctl_comp_options()

>  			opts=$(__ndctl_get_dimms)

>  			;;

>  		--namespace)

> -			opts=$(__ndctl_get_ns -i)

> +			opts=$(__ndctl_get_ns)

>  			;;

>  		--reconfig)

>  			# It is ok to reconfig disabled namespaces

> @@ -155,9 +159,15 @@ __ndctl_comp_options()

>  			;;

>  		--type)

>  			opts="pmem blk"

> +			if [[ "$mode_filter" == @(dax|memory) ]];

> then

> +				opts="pmem"

> +			fi

>  			;;

>  		--mode)

>  			opts="raw sector memory dax"

> +			if [[ "$type_filter" == "blk" ]]; then

> +				opts="raw sector"

> +			fi

>  			;;

>  		--map)

>  			opts="mem dev"

> @@ -224,13 +234,13 @@ __ndctl_prev_skip_opts ()

>  	done

>  }

>  

> -bus_filter=''

> -reg_filter=''

> -

>  __ndctl_init_filters()

>  {

>  	bus_filter=''

>  	reg_filter=''

> +	type_filter=''

> +	idle_filter=''

> +	mode_filter=''

>  

>  	for __word in "${words[@]}"; do

>  		if [[ "$__word" =~ --bus=(.*) ]]; then

> @@ -245,6 +255,15 @@ __ndctl_init_filters()

>  			local regions=$(__ndctl_get_regions -i)

>  			[[ "$regions" == *"$reg_filter"* ]] ||

> reg_filter=''

>  		fi

> +		if [[ "$__word" =~ --idle ]]; then

> +			idle_filter="1"

> +		fi

> +		if [[ "$__word" =~ --type=(.*) ]]; then

> +			type_filter="${BASH_REMATCH[1]}"

> +		fi

> +		if [[ "$__word" =~ --mode=(.*) ]]; then

> +			mode_filter="${BASH_REMATCH[1]}"

> +		fi

>  	done

>  }

>
diff mbox

Patch

diff --git a/contrib/ndctl b/contrib/ndctl
index b7a82fc..160a9dc 100755
--- a/contrib/ndctl
+++ b/contrib/ndctl
@@ -110,6 +110,8 @@  __ndctl_get_regions()
 {
 	local opts="--regions $*"
 	[ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter"
+	[ -n "$type_filter" ] && opts="$opts --type=$type_filter"
+	[ -n "$idle_filter" ] && opts="$opts --idle"
 	echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)"
 }
 
@@ -118,6 +120,8 @@  __ndctl_get_ns()
 	opts="--namespaces $*"
 	[ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter"
 	[ -n "$reg_filter" ] && opts="$opts --bus=$reg_filter"
+	[ -n "$type_filter" ] && opts="$opts --type=$type_filter"
+	[ -n "$idle_filter" ] && opts="$opts --idle"
 	echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)"
 }
 
@@ -147,7 +151,7 @@  __ndctl_comp_options()
 			opts=$(__ndctl_get_dimms)
 			;;
 		--namespace)
-			opts=$(__ndctl_get_ns -i)
+			opts=$(__ndctl_get_ns)
 			;;
 		--reconfig)
 			# It is ok to reconfig disabled namespaces
@@ -155,9 +159,15 @@  __ndctl_comp_options()
 			;;
 		--type)
 			opts="pmem blk"
+			if [[ "$mode_filter" == @(dax|memory) ]]; then
+				opts="pmem"
+			fi
 			;;
 		--mode)
 			opts="raw sector memory dax"
+			if [[ "$type_filter" == "blk" ]]; then
+				opts="raw sector"
+			fi
 			;;
 		--map)
 			opts="mem dev"
@@ -224,13 +234,13 @@  __ndctl_prev_skip_opts ()
 	done
 }
 
-bus_filter=''
-reg_filter=''
-
 __ndctl_init_filters()
 {
 	bus_filter=''
 	reg_filter=''
+	type_filter=''
+	idle_filter=''
+	mode_filter=''
 
 	for __word in "${words[@]}"; do
 		if [[ "$__word" =~ --bus=(.*) ]]; then
@@ -245,6 +255,15 @@  __ndctl_init_filters()
 			local regions=$(__ndctl_get_regions -i)
 			[[ "$regions" == *"$reg_filter"* ]] || reg_filter=''
 		fi
+		if [[ "$__word" =~ --idle ]]; then
+			idle_filter="1"
+		fi
+		if [[ "$__word" =~ --type=(.*) ]]; then
+			type_filter="${BASH_REMATCH[1]}"
+		fi
+		if [[ "$__word" =~ --mode=(.*) ]]; then
+			mode_filter="${BASH_REMATCH[1]}"
+		fi
 	done
 }