[1/2] checkupdates: add -q/--quiet

Message ID 20190628201258.20566-1-morganamilo@gmail.com
State Rejected
Headers show
Series
  • [1/2] checkupdates: add -q/--quiet
Related show

Commit Message

morganamilo June 28, 2019, 8:12 p.m. UTC

Comments

Eli Schwartz June 28, 2019, 8:20 p.m. UTC | #1
On 6/28/19 4:12 PM, morganamilo wrote:

What's the utility of adding this extra option, vs. just using:

checkupdates | awk '{print $1}'

The typical use of this script probably just cares about the exit code
anyway. There are some scripts which just count the number of lines.

Patch

diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in
index 0885983..024243c 100644
--- a/src/checkupdates.sh.in
+++ b/src/checkupdates.sh.in
@@ -22,6 +22,7 @@  declare -r myname='checkupdates'
 declare -r myver='@PACKAGE_VERSION@'
 
 DOWNLOAD_CACHE=0
+QUIET=0
 
 m4_include(../lib/output_format.sh)
 m4_include(../lib/term_colors.sh)
@@ -38,14 +39,15 @@  Usage: ${myname} [options]
   Options:
     -d, --download        download pending updates to the pacman cache.
     -h, --help            display this help message and exit.
+    -q, --quiet           only display pkgnames.
 
 Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.
 
 __EOF__
 }
 
-OPT_SHORT='dh'
-OPT_LONG=('download' 'help')
+OPT_SHORT='dhq'
+OPT_LONG=('download' 'help' 'quiet')
 
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
 	exit 1
@@ -60,6 +62,8 @@  while :; do
 		-h|--help)
 			usage
 			exit 0 ;;
+		-q|--quiet)
+			QUIET=1 ;;
 		--)
 			shift
 			break ;;
@@ -92,6 +96,9 @@  fi
 mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]')
 
 if (( ${#updates[@]} )); then
+	if (( $QUIET )); then
+		updates=("${updates[@]%% *}")
+	fi
 	printf '%s\n' "${updates[@]}"
 	if (( DOWNLOAD_CACHE )); then
 		sudo pacman -Sw --noconfirm "${updates[@]%% *}" --dbpath "$CHECKUPDATES_DB" --logfile /dev/null