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

Gordian Edenhofer gordian.edenhofer at gmail.com
Fri Sep 30 11:47:54 UTC 2016


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

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 02fae52..78f566f 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,48 @@ 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 -- "  -d, --dryrun          "
+	printf -- "$(gettext "Perform a dry run, only finding candidate packages")\n"
+	printf -- "  -m, --move <dir>      "
+	printf -- "$(gettext "Move candidate packages to \"dir\"")\n"
+	printf -- "  -r, --remove          "
+	printf -- "$(gettext "Remove candidate packages")\n"
+	echo
+	printf -- "$(gettext "Options:")\n"
+	printf -- "  -a, --arch <arch>     "
+	printf -- "$(gettext "Scan for \"arch\" (default: all architectures)")\n"
+	printf -- "  -c, --cachedir <dir>  "
+	printf -- "$(gettext "Scan \"dir\" for packages. Can be used more than once.\n\
+	                        (default: read from %s).")\n" "@sysconfdir@/pacman.conf"
+	printf -- "  -f, --force           "
+	printf -- "$(gettext "Apply force to mv(1) and rm(1) operations")\n" "\$srcdir/"
+	printf -- "  -h, --help            "
+	printf -- "$(gettext "Display this help message and exit")\n"
+	printf -- "  -i, --ignore <pkgs>   "
+	printf -- "$(gettext "Ignore \"pkgs\", comma-separated. Alternatively, specify\n\
+	                        \"-\" to read package names from stdin, newline-\n\
+	                        delimited.")\n" "\$srcdir/"
+	printf -- "  -k, --keep <num>      "
+	printf -- "$(gettext "Keep \"num\" of each package in the cache (default: 3)")\n"
+	printf -- "  -q, --quiet           "
+	printf -- "$(gettext "Minimize output")\n"
+	printf -- "  -u, --uninstalled     "
+	printf -- "$(gettext "Target uninstalled packages")\n"
+	printf -- "  -v, --verbose         "
+	printf -- "$(gettext "Increase verbosity. specify up to 3 times.")\n"
+	printf -- "  -z, --null            "
+	printf -- "$(gettext "Use null delimiters for candidate names (only with -v\n\
+	                    and -vv)")\n"
+	printf -- "  --nocolor             "
+	printf -- "$(gettext "Remove color from output")\n"
+	echo
 }
 
 version() {
-- 
2.10.0


More information about the pacman-dev mailing list