[pacman-dev] [PATCH 4/5] pacdiff: rework search type handling, add --find option

Allan McRae allan at archlinux.org
Sat Jul 20 23:00:08 EDT 2013


On 17/07/13 04:00, Jonathan Frazier wrote:
> change cmd tests to if (( $find ))... as it is cleaner.  All search cmds
> have an option and a variable initialized to zero. the active option
> should be set to 1.  Add a switch to exclude multiple search options.
> set the default when all are equal to zero.
> 
> Signed-off-by: Jonathan Frazier <eyeswide at gmail.com>
> ---
>  contrib/pacdiff.sh.in | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
> index a39a02a..c12e9d5 100644
> --- a/contrib/pacdiff.sh.in
> +++ b/contrib/pacdiff.sh.in
> @@ -23,19 +23,23 @@ declare -r myver='@PACKAGE_VERSION@'
>  
>  diffprog=${DIFFPROG:-vimdiff}
>  diffsearchpath=${DIFFSEARCHPATH:-/etc}
> -locate=0
>  USE_COLOR='y'
>  
> +declare -i findActive=0 locateActive=0
> +
>  m4_include(../scripts/library/output_format.sh)
>  
>  usage() {
>  	cat <<EOF
>  $myname is a simple pacnew/pacorig/pacsave updater.
>  
> -Usage: $myname [-l]
> +Usage: $myname [-l | -f] [--nocolor]
> +
> +Search Options:     select one, default: find
> +  -l/--locate       scan using locate
> +  -f/--find         scan using find
>  
> -Options:
> -  -l/--locate       scan using locate (default: find)
> +General Options:
>    --nocolor         remove colors from output
>  
>  Enviroment Variables:
> @@ -55,9 +59,9 @@ version() {
>  }
>  
>  cmd() {
> -	if [ $locate -eq 1 ]; then
> +	if (( $locateActive )); then
>  		locate -0 -e -b \*.pacnew \*.pacorig \*.pacsave '*.pacsave.[0-9]'
> -	else
> +	elif (( $findActive )); then
>  		find $diffsearchpath \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave -o -name '*.pacsave.[0-9]' \) -print0
>  	fi
>  }
> @@ -65,7 +69,9 @@ cmd() {
>  while [[ -n "$1" ]]; do	
>  	case "$1" in
>  		-l|--locate)
> -		locate=1;;
> +		locateActive=1;;

We tend to use variables in all capitals for things like this.  I.e.
LOCATE and FIND.

> +		-f|--find)
> +		findActive=1;;
>  		--nocolor)
>  		USE_COLOR='n' ;;
>  		-V|--version)
> @@ -80,6 +86,12 @@ done
>  
>  m4_include(../scripts/library/term_colors.sh)
>  
> +case $(( findActive+locateActive )) in

I know these default to zero, but if you are going to add them I'd like
them to be explicitly set to zero at the top of the script.  See what we
do in makepkg and pacman-key for example.

> +	0) findActive=1;; # set the default search option
> +	[^1]) error "Only one search option may be used at a time"
> +	 	usage; exit 1;;
> +esac
> +
>  # see http://mywiki.wooledge.org/BashFAQ/020
>  while IFS= read -u 3 -r -d '' pacfile; do
>  	file="${pacfile%.pac*}"
> 



More information about the pacman-dev mailing list