[pacman-dev] [RFC v2 06/13] paccache: streamline usage function

Gordian Edenhofer gordian.edenhofer at gmail.com
Thu Sep 29 12:41:19 UTC 2016


Signed-off-by: Gordian Edenhofer <gordian.edenhofer at gmail.com>
---
 contrib/paccache.sh.in | 72 +++++++++++++++++++++++++++++---------------------
 1 file changed, 42 insertions(+), 30 deletions(-)

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 02fae52..59ebbac 100644
--- a/contrib/paccache.sh.in
+++ b/contrib/paccache.sh.in
@@ -30,6 +30,17 @@ declare    delim=$'\n' keep=3 movedir= scanarch=
 QUIET=0
 USE_COLOR='y'
 
+# gettext initialization
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='@localedir@'
+
+# Determine whether we have gettext; make it a no-op if we do not
+if ! type -p gettext >/dev/null; then
+	gettext() {
+		printf "%s\n" "$@"
+	}
+fi
+
 m4_include(../scripts/library/output_format.sh)
 m4_include(../scripts/library/parseopts.sh)
 
@@ -172,36 +183,37 @@ summarize() {
 }
 
 usage() {
-	cat <<EOF
-${myname} (pacman) v${myver}
-
-A flexible pacman cache cleaning utility.
-
-Usage: ${myname} <operation> [options] [targets...]
-
-  Operations:
-    -d, --dryrun          perform a dry run, only finding candidate packages.
-    -m, --move <dir>      move candidate packages to "dir".
-    -r, --remove          remove candidate packages.
-
-  Options:
-    -a, --arch <arch>     scan for "arch" (default: all architectures).
-    -c, --cachedir <dir>  scan "dir" for packages. can be used more than once.
-                          (default: read from @sysconfdir@/pacman.conf).
-    -f, --force           apply force to mv(1) and rm(1) operations.
-    -h, --help            display this help message and exit.
-    -i, --ignore <pkgs>   ignore "pkgs", comma-separated. Alternatively, specify
-                          "-" to read package names from stdin, newline-
-                          delimited.
-    -k, --keep <num>      keep "num" of each package in the cache (default: 3).
-        --nocolor         remove color from output.
-    -q, --quiet           minimize output
-    -u, --uninstalled     target uninstalled packages.
-    -v, --verbose         increase verbosity. specify up to 3 times.
-    -z, --null            use null delimiters for candidate names (only with -v
-                          and -vv).
-
-EOF
+	printf "%s (pacman) %s\n" "$myname" "$myver"
+	echo
+	printf -- "$(gettext "A flexible pacman cache cleaning utility")\n"
+	echo
+	printf -- "$(gettext "Usage: %s <operation> [options] [targets...]")\n" "$0"
+	echo
+	printf -- "$(gettext "Operations:")\n"
+	printf -- "$(gettext "  -d, --dryrun          Perform a dry run, only finding candidate packages")\n"
+	printf -- "$(gettext "  -m, --move <dir>      Move candidate packages to \"dir\"")\n"
+	printf -- "$(gettext "  -r, --remove          Remove candidate packages")\n"
+	echo
+	printf -- "$(gettext "Options:")\n"
+	printf -- "$(gettext "  -a, --arch <arch>     Scan for \"arch\" (default: all architectures)")\n"
+	printf -- "$(gettext "\
+  -c, --cachedir <dir>  Scan \"dir\" for packages. Can be used more than once.\n\
+                        (default: read from @sysconfdir@/pacman.conf).")\n"
+	printf -- "$(gettext "  -f, --force           Apply force to mv(1) and rm(1) operations")\n" "\$srcdir/"
+	printf -- "$(gettext "  -h, --help            Display this help message and exit")\n"
+	printf -- "$(gettext "\
+  -i, --ignore <pkgs>   Ignore \"pkgs\", comma-separated. Alternatively, specify\n\
+                        \"-\" to read package names from stdin, newline-\n\
+                        delimited.")\n" "\$srcdir/"
+	printf -- "$(gettext "  -k, --keep <num>      Keep \"num\" of each package in the cache (default: 3)")\n"
+	printf -- "$(gettext "  -q, --quiet           Minimize output")\n"
+	printf -- "$(gettext "  -u, --uninstalled     Target uninstalled packages")\n"
+	printf -- "$(gettext "  -v, --verbose         Increase verbosity. specify up to 3 times.")\n"
+	printf -- "$(gettext "\
+  -z, --null            Use null delimiters for candidate names (only with -v\n\
+                        and -vv)")\n"
+	printf -- "$(gettext "  --nocolor             Remove color from output")\n"
+	echo
 }
 
 version() {
-- 
2.10.0


More information about the pacman-dev mailing list