[pacman-dev] [PATCH 00/11] Streamline syntax of contrib scripts
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options. Gordian Edenhofer (11): checkupdates: streamline usage function paccache: streamline usage function pacdiff: streamline usage function pacdiff: proper option handling pacdiff: streamline option syntax with makepkg paclist: streamline usage function paclog-pkglist: streamline usage function pacscripts: streamline usage function updpkgsums: streamline usage function rankmirrors: streamline usage function rankmirrors: proper option handling contrib/checkupdates.sh.in | 9 +-- contrib/paccache.sh.in | 61 ++++++++++---------- contrib/pacdiff.sh.in | 76 +++++++++++++++---------- contrib/paclist.sh.in | 10 ++-- contrib/paclog-pkglist.sh.in | 12 ++-- contrib/pacscripts.sh.in | 18 +++--- contrib/rankmirrors.sh.in | 132 +++++++++++++++++++++---------------------- contrib/updpkgsums.sh.in | 21 ++++--- 8 files changed, 179 insertions(+), 160 deletions(-) -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/checkupdates.sh.in | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in index ff62891..8c04370 100644 --- a/contrib/checkupdates.sh.in +++ b/contrib/checkupdates.sh.in @@ -25,13 +25,14 @@ m4_include(../scripts/library/output_format.sh) m4_include(../scripts/library/term_colors.sh) if (( $# > 0 )); then - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - echo "Safely print a list of pending updates" + printf -- "$(gettext "Safely print a list of pending updates")\n" echo - echo "Usage: ${myname}" + printf -- "$(gettext "Usage: %s")\n" "$0" + echo + printf -- "$(gettext "Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.")\n" echo - echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.' exit 0 fi -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paccache.sh.in | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in index 02fae52..85fff55 100644 --- a/contrib/paccache.sh.in +++ b/contrib/paccache.sh.in @@ -172,36 +172,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
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index dff2115..840e36f 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -32,31 +32,31 @@ declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 m4_include(../scripts/library/output_format.sh) usage() { - cat <<EOF -${myname} (pacman) v${myver} - -A simple program to merge or remove pacnew/pacsave files. - -Usage: $myname [-l | -f | -p] [--nocolor] - -Search Options: select one (default: --pacmandb) - -l/--locate scan using locate - -f/--find scan using find - -p/--pacmandb scan active config files from pacman database - -General Options: - -o/--output print files instead of merging them - --nocolor remove colors from output - -Environment Variables: - DIFFPROG override the merge program: (default: 'vim -d') - DIFFSEARCHPATH override the search path. (only when using find) - (default: /etc) - -Example: DIFFPROG=meld DIFFSEARCHPATH="/boot /etc /usr" $myname -Example: $myname --output --locate - -EOF + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "A simple program to merge or remove pacnew/pacsave files")\n" + echo + printf -- "$(gettext "Usage: %s <operation> [options]")\n" "$0" + echo + printf -- "$(gettext "Search Options:")\n" + printf -- "$(gettext " -l, --locate Scan using locate")\n" + printf -- "$(gettext " -f, --find Scan using find")\n" + printf -- "$(gettext " -p, --pacmandb Scan active config files from pacman database")\n" + echo + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -o, --output Print files instead of merging them")\n" + printf -- "$(gettext " -m, --nocolor Remove colors from output")\n" + echo + printf -- "$(gettext "Environment Variables:")\n" + printf -- "$(gettext " DIFFPROG Override the merge program: (default: 'vim -d')")\n" + printf -- "$(gettext "\ + DIFFSEARCHPATH Override the search path. (only when using find)\n\ + (default: /etc)")\n" + echo + printf -- "$(gettext "Examples:")" + printf -- " DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" %s\n" "$myname" + printf -- " %s --output --locate\n" "$myname" + echo } version() { -- 2.10.0
Switch to parseopts. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 840e36f..bed9ea3 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -30,6 +30,7 @@ declare -a oldsaves declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 m4_include(../scripts/library/output_format.sh) +m4_include(../scripts/library/parseopts.sh) usage() { printf "%s (pacman) %s\n" "$myname" "$myver" @@ -94,7 +95,17 @@ cmd() { fi } -while [[ -n "$1" ]]; do +# Parse arguments +OPT_SHORT='lfpoVh' +OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + usage + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do case "$1" in -l|--locate) USE_LOCATE=1;; @@ -107,11 +118,14 @@ while [[ -n "$1" ]]; do --nocolor) USE_COLOR='n';; -V|--version) - version; exit 0;; + version + exit 0;; -h|--help) - usage; exit 0;; - *) - usage; exit 1;; + usage + exit 0;; + --) + shift + break 2;; esac shift done -- 2.10.0
Allow for '-m' as abbreviation for '--nocolor'. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index bed9ea3..8336706 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -96,7 +96,7 @@ cmd() { } # Parse arguments -OPT_SHORT='lfpoVh' +OPT_SHORT='lfpomVh' OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then usage @@ -115,7 +115,7 @@ while :; do USE_PACDB=1;; -o|--output) OUTPUTONLY=1;; - --nocolor) + -m|--nocolor) USE_COLOR='n';; -V|--version) version -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paclist.sh.in | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/paclist.sh.in b/contrib/paclist.sh.in index f4fd540..156f9d3 100644 --- a/contrib/paclist.sh.in +++ b/contrib/paclist.sh.in @@ -31,13 +31,15 @@ if ! type gettext &>/dev/null; then fi usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - printf "List all packages installed from a given repository\n" "${myname}" + printf -- "$(gettext "List all packages installed from a given repository")\n" echo - printf "Usage: %s <repository>\n" "${myname}" + printf -- "$(gettext "Usage: %s <repository>")\n" "$0" + echo + printf -- "$(gettext "Examples:")" + printf -- " %s testing\n" "$myname" echo - printf "Example: %s testing\n" "${myname}" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paclog-pkglist.sh.in | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in index 847b389..6e9bced 100644 --- a/contrib/paclog-pkglist.sh.in +++ b/contrib/paclog-pkglist.sh.in @@ -25,15 +25,17 @@ export TEXTDOMAINDIR='/usr/share/locale' declare logfile=${1:-@localstatedir@/log/pacman.log} usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - echo "Parse a log file into a list of currently installed packages" + printf -- "$(gettext "Parse a log file into a list of currently installed packages")\n" echo - printf "Usage: %s [path to pacman log]\n" "${myname}" + printf -- "$(gettext "Usage: %s [path to pacman log]")\n" "$0" echo - printf "Example: %s @localstatedir@/log/pacman.log\n" "${myname}" + printf -- "$(gettext "Examples:")" + printf -- " %s @localstatedir@/log/pacman.log\n" "$myname" + echo + printf -- "$(gettext "Defaults to: @localstatedir@/log/pacman.log")\n" echo - echo 'Defaults to: @localstatedir@/log/pacman.log' } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacscripts.sh.in | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/contrib/pacscripts.sh.in b/contrib/pacscripts.sh.in index 4a1e0c5..de94843 100644 --- a/contrib/pacscripts.sh.in +++ b/contrib/pacscripts.sh.in @@ -45,18 +45,20 @@ error() { } usage() { - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package." + printf -- "$(gettext "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package")\n" echo - echo "Usage: ${myname} <pkgname|pkgfile>" + printf -- "$(gettext "Usage: %s <pkgname|pkgfile>")\n" "$0" echo - echo " Options:" - echo " -h, --help Print this help message" - echo " -v, --version Print program name and version" + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -h, --help Print this help message")\n" + printf -- "$(gettext " -v, --version Print program name and version")\n" + echo + printf -- "$(gettext "Examples:")" + printf -- " %s gconf-editor\n" "$myname" + printf -- " %s gconf-editor-3.0.1-3-x86_64.pkg.tar.xz\n" "$myname" echo - echo "Example: ${myname} gconf-editor" - echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/updpkgsums.sh.in | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index c571d29..5b68765 100644 --- a/contrib/updpkgsums.sh.in +++ b/contrib/updpkgsums.sh.in @@ -23,19 +23,22 @@ declare -r myname='updpkgsums' declare -r myver='@PACKAGE_VERSION@' usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - printf "%s will perform an in place update of the checksums in the\n" "${myname}" - echo "path specified by [build file], defaulting to PKGBUILD in the current" - echo "working directory." + printf -- "$(gettext "\ +%s will perform an in place update of the checksums in the\n\ +path specified by [build file], defaulting to PKGBUILD in the current\n\ +working directory")\n" "$myname" echo - printf "Usage: %s [options] [build file]\n" "${myname}" + printf -- "$(gettext "Usage: %s [options] [build file]")\n" "$0" echo - echo " -h, --help display this help message and exit" - echo " -V, --version display version information and exit" + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -h, --help Display this help message and exit")\n" + printf -- "$(gettext " -V, --version Display version information and exit")\n" + echo + printf -- "$(gettext "These options can be passed to makepkg:")\n" + printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" echo - echo "These options can be passed to makepkg:" - echo " -m, --nocolor disable colorized output messages" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/rankmirrors.sh.in | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in index 7b50eb2..6ded91f 100644 --- a/contrib/rankmirrors.sh.in +++ b/contrib/rankmirrors.sh.in @@ -25,22 +25,24 @@ declare -r myname='rankmirrors' declare -r myver='@PACKAGE_VERSION@' usage() { - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - echo "Ranks pacman mirrors by their connection and opening speed. Pacman mirror" - echo "files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if the URL is" - echo "provided." + printf -- "$(gettext "\ +Ranks pacman mirrors by their connection and opening speed. Pacman mirror\n\ +files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if the URL is\n\ +provided")\n" echo - echo "Usage: ${myname} [options] MIRRORFILE | URL" + printf -- "$(gettext "Usage: %s [options] <mirrorfile|URL>")\n" "$0" + echo + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -h, --help Show this help message and exit")\n" + printf -- "$(gettext " -n <N> Number of servers to output, 0 for all")\n" + printf -- "$(gettext " -t, --times Only output mirrors and their response times")\n" + printf -- "$(gettext " -u, --url Test a specific URL")\n" + printf -- "$(gettext " -v, --verbose Be verbose in ouptut")\n" + printf -- "$(gettext " -r, --repo <repo> Specify a repository name instead of guessing")\n" + printf -- "$(gettext " --version Show program's version number and exit")\n" echo - echo "Options:" - echo " --version show program's version number and exit" - echo " -h, --help show this help message and exit" - echo " -n NUM number of servers to output, 0 for all" - echo " -t, --times only output mirrors and their response times" - echo " -u, --url test a specific URL" - echo " -v, --verbose be verbose in ouptut" - echo " -r, --repo specify a repository name instead of guessing" exit 0 } -- 2.10.0
Switch to parseopts. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/rankmirrors.sh.in | 104 +++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in index 6ded91f..c0f2316 100644 --- a/contrib/rankmirrors.sh.in +++ b/contrib/rankmirrors.sh.in @@ -24,6 +24,8 @@ trap finaloutput INT declare -r myname='rankmirrors' declare -r myver='@PACKAGE_VERSION@' +m4_include(../scripts/library/parseopts.sh) + usage() { printf "%s (pacman) %s\n" "$myname" "$myver" echo @@ -43,7 +45,6 @@ provided")\n" printf -- "$(gettext " -r, --repo <repo> Specify a repository name instead of guessing")\n" printf -- "$(gettext " --version Show program's version number and exit")\n" echo - exit 0 } version() { @@ -122,68 +123,59 @@ finaloutput() { exit 0 } - -# Argument parsing -[[ $1 ]] || usage -while [[ $1 ]]; do - if [[ ${1:0:2} = -- ]]; then - case "${1:2}" in - help) usage ;; - version) version ;; - times) TIMESONLY=1 ; shift ;; - verbose) VERBOSE=1 ; shift ;; - url) - CHECKURL=1; - [[ $2 ]] || err "Must specify URL."; - URL="$2"; - shift 2;; - repo) - [[ $2 ]] || err "Must specify repository name."; - TARGETREPO="$2"; - shift 2;; - *) err "'$1' is an invalid argument." - esac - elif [[ ${1:0:1} = - ]]; then - - if [[ ! ${1:1:1} ]]; then - [[ -t 0 ]] && err "Stdin is empty." - IFS=$'\n' linearray=( $(</dev/stdin) ) - STDIN=1 +# Parse arguments +OPT_SHORT=':hVtvn:u:r:' +OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + usage + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case "$1" in + -h|--help) + usage + exit 0;; + --version) + version;; + -t|--times) + TIMESONLY=1;; + -v|--verbose) + VERBOSE=1;; + -u|--url) + CHECKURL=1 + URL="$2" + shift;; + -r|--repo) + TARGETREPO="$2" + shift;; + -n) + NUM="$2" + shift;; + --) shift - else - snum=1 - for ((i=1 ; i<${#1}; i++)); do - case ${1:$i:1} in - h) usage ;; - t) TIMESONLY=1 ;; - v) VERBOSE=1 ;; - u) - CHECKURL=1; - [[ $2 ]] || err "Must specify URL."; - URL="$2"; - snum=2;; - r) - [[ $2 ]] || err "Must specify repository name."; - TARGETREPO="$2"; - snum=2;; - n) - [[ $2 ]] || err "Must specify number."; - NUM="$2"; - snum=2;; - *) err "'$1' is an invalid argument." ;; - esac - done - shift $snum - fi + break 2;; + esac + shift +done +if [[ ${#@} -eq 1 ]]; then + if [[ $1 == "-" ]]; then + [[ -t 0 ]] && err "Stdin is empty." + IFS=$'\n' linearray=( $(</dev/stdin) ) + STDIN=1 elif [[ -f $1 ]]; then FILE="1" IFS=$'\n' linearray=( $(<$1) ) [[ $linearray ]] || err "File is empty." - shift - else + elif [[ ! -f $1 ]]; then err "'$1' does not exist." fi -done +else + usage + exit 1 +fi # Some sanity checks [[ $NUM ]] || NUM=0 -- 2.10.0
On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gmail.com> wrote: Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options. None of your changes which add gettext support are useful in their current form as you do not export TEXTDOMAIN or TEXTDOMAINDIR. Gordian Edenhofer (11): checkupdates: streamline usage function paccache: streamline usage function pacdiff: streamline usage function pacdiff: proper option handling pacdiff: streamline option syntax with makepkg paclist: streamline usage function paclog-pkglist: streamline usage function pacscripts: streamline usage function updpkgsums: streamline usage function rankmirrors: streamline usage function rankmirrors: proper option handling contrib/checkupdates.sh.in | 9 +-- contrib/paccache.sh.in | 61 ++++++++++---------- contrib/pacdiff.sh.in | 76 +++++++++++++++---------- contrib/paclist.sh.in | 10 ++-- contrib/paclog-pkglist.sh.in | 12 ++-- contrib/pacscripts.sh.in | 18 +++--- contrib/rankmirrors.sh.in | 132 +++++++++++++++++++++--------- ------------- contrib/updpkgsums.sh.in | 21 ++++--- 8 files changed, 179 insertions(+), 160 deletions(-) -- 2.10.0
On Thu, 2016-09-29 at 20:40 +1000, Dave Reisner wrote:
On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gmail.c om> wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
None of your changes which add gettext support are useful in their current form as you do not export TEXTDOMAIN or TEXTDOMAINDIR.
Thanks for the hint! I forgot about that. Btw. paclist [1] already defined it. [1] https://git.archlinux.org/pacman.git/tree/contrib/paclist.sh.in#n23
On 29/09/16 21:25, Gordian Edenhofer wrote:
On Thu, 2016-09-29 at 20:40 +1000, Dave Reisner wrote:
On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gmail.c om> wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
None of your changes which add gettext support are useful in their current form as you do not export TEXTDOMAIN or TEXTDOMAINDIR.
Thanks for the hint! I forgot about that. Btw. paclist [1] already defined it.
[1] https://git.archlinux.org/pacman.git/tree/contrib/paclist.sh.in#n23
It only works for paclist because it uses translations already provided by pacman. This will not work for anything else because strings from the contrib files are not added to the pacman translation. A new translation domain for contrib needs set-up if this is to work. A
On Thu, 2016-09-29 at 21:39 +1000, Allan McRae wrote:
On 29/09/16 21:25, Gordian Edenhofer wrote:
On Thu, 2016-09-29 at 20:40 +1000, Dave Reisner wrote:
On Sep 29, 2016 06:23, "Gordian Edenhofer" <gordian.edenhofer@gma il.c om> wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
None of your changes which add gettext support are useful in their current form as you do not export TEXTDOMAIN or TEXTDOMAINDIR.
Thanks for the hint! I forgot about that. Btw. paclist [1] already defined it.
[1] https://git.archlinux.org/pacman.git/tree/contrib/paclist.sh.in #n23
It only works for paclist because it uses translations already provided by pacman. This will not work for anything else because strings from the contrib files are not added to the pacman translation.
A new translation domain for contrib needs set-up if this is to work.
Thanks for the explanation. To be honest I don't know how to setup a translation domain since I haven't read any documentation about this matter yet. I would appreciate if anybody could help me with this. Until then I will resumbit this patch as RFC once more and order commits according to whether they touch usage. An alternative approach would be to strip all gettext invocations and simply not make contrib script translatable.
Switch to parseopts. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index dff2115..cd93164 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -30,6 +30,7 @@ declare -a oldsaves declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 m4_include(../scripts/library/output_format.sh) +m4_include(../scripts/library/parseopts.sh) usage() { cat <<EOF @@ -94,7 +95,17 @@ cmd() { fi } -while [[ -n "$1" ]]; do +# Parse arguments +OPT_SHORT='lfpoVh' +OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + usage + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do case "$1" in -l|--locate) USE_LOCATE=1;; @@ -107,11 +118,14 @@ while [[ -n "$1" ]]; do --nocolor) USE_COLOR='n';; -V|--version) - version; exit 0;; + version + exit 0;; -h|--help) - usage; exit 0;; - *) - usage; exit 1;; + usage + exit 0;; + --) + shift + break 2;; esac shift done -- 2.10.0
Allow for '-m' as abbreviation for '--nocolor'. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index cd93164..3394993 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,7 +47,7 @@ Search Options: select one (default: --pacmandb) General Options: -o/--output print files instead of merging them - --nocolor remove colors from output + -m/--nocolor remove colors from output Environment Variables: DIFFPROG override the merge program: (default: 'vim -d') @@ -96,7 +96,7 @@ cmd() { } # Parse arguments -OPT_SHORT='lfpoVh' +OPT_SHORT='lfpomVh' OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then usage @@ -115,7 +115,7 @@ while :; do USE_PACDB=1;; -o|--output) OUTPUTONLY=1;; - --nocolor) + -m|--nocolor) USE_COLOR='n';; -V|--version) version -- 2.10.0
Switch to parseopts. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/rankmirrors.sh.in | 102 +++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 56 deletions(-) diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in index 7b50eb2..0988fe9 100644 --- a/contrib/rankmirrors.sh.in +++ b/contrib/rankmirrors.sh.in @@ -41,7 +41,6 @@ usage() { echo " -u, --url test a specific URL" echo " -v, --verbose be verbose in ouptut" echo " -r, --repo specify a repository name instead of guessing" - exit 0 } version() { @@ -120,68 +119,59 @@ finaloutput() { exit 0 } - -# Argument parsing -[[ $1 ]] || usage -while [[ $1 ]]; do - if [[ ${1:0:2} = -- ]]; then - case "${1:2}" in - help) usage ;; - version) version ;; - times) TIMESONLY=1 ; shift ;; - verbose) VERBOSE=1 ; shift ;; - url) - CHECKURL=1; - [[ $2 ]] || err "Must specify URL."; - URL="$2"; - shift 2;; - repo) - [[ $2 ]] || err "Must specify repository name."; - TARGETREPO="$2"; - shift 2;; - *) err "'$1' is an invalid argument." - esac - elif [[ ${1:0:1} = - ]]; then - - if [[ ! ${1:1:1} ]]; then - [[ -t 0 ]] && err "Stdin is empty." - IFS=$'\n' linearray=( $(</dev/stdin) ) - STDIN=1 +# Parse arguments +OPT_SHORT=':hVtvn:u:r:' +OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + usage + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case "$1" in + -h|--help) + usage + exit 0;; + --version) + version;; + -t|--times) + TIMESONLY=1;; + -v|--verbose) + VERBOSE=1;; + -u|--url) + CHECKURL=1 + URL="$2" + shift;; + -r|--repo) + TARGETREPO="$2" + shift;; + -n) + NUM="$2" + shift;; + --) shift - else - snum=1 - for ((i=1 ; i<${#1}; i++)); do - case ${1:$i:1} in - h) usage ;; - t) TIMESONLY=1 ;; - v) VERBOSE=1 ;; - u) - CHECKURL=1; - [[ $2 ]] || err "Must specify URL."; - URL="$2"; - snum=2;; - r) - [[ $2 ]] || err "Must specify repository name."; - TARGETREPO="$2"; - snum=2;; - n) - [[ $2 ]] || err "Must specify number."; - NUM="$2"; - snum=2;; - *) err "'$1' is an invalid argument." ;; - esac - done - shift $snum - fi + break 2;; + esac + shift +done +if [[ ${#@} -eq 1 ]]; then + if [[ $1 == "-" ]]; then + [[ -t 0 ]] && err "Stdin is empty." + IFS=$'\n' linearray=( $(</dev/stdin) ) + STDIN=1 elif [[ -f $1 ]]; then FILE="1" IFS=$'\n' linearray=( $(<$1) ) [[ $linearray ]] || err "File is empty." - shift - else + elif [[ ! -f $1 ]]; then err "'$1' does not exist." fi -done +else + usage + exit 1 +fi # Some sanity checks [[ $NUM ]] || NUM=0 -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 897cd85..0754c0d 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -60,6 +60,7 @@ REAL_PACKAGE_VERSION = $(PACKAGE_VERSION) endif edit = sed \ + -e 's|@localedir[@]|$(localedir)|g' \ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ -e 's|@localstatedir[@]|$(localstatedir)|g' \ -e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \ -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/checkupdates.sh.in | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in index ff62891..40a13ec 100644 --- a/contrib/checkupdates.sh.in +++ b/contrib/checkupdates.sh.in @@ -21,17 +21,29 @@ declare -r myname='checkupdates' declare -r myver='@PACKAGE_VERSION@' +# 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/term_colors.sh) if (( $# > 0 )); then - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "Safely print a list of pending updates")\n" echo - echo "Safely print a list of pending updates" + printf -- "$(gettext "Usage: %s")\n" "$0" echo - echo "Usage: ${myname}" + printf -- "$(gettext "Note: Export the "%s" variable to change the path of the temporary database.")\n" "CHECKUPDATES_DB" echo - echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.' exit 0 fi -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@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
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 61 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 3394993..80fd1f8 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -29,35 +29,46 @@ USE_COLOR='y' declare -a oldsaves declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 +# 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) usage() { - cat <<EOF -${myname} (pacman) v${myver} - -A simple program to merge or remove pacnew/pacsave files. - -Usage: $myname [-l | -f | -p] [--nocolor] - -Search Options: select one (default: --pacmandb) - -l/--locate scan using locate - -f/--find scan using find - -p/--pacmandb scan active config files from pacman database - -General Options: - -o/--output print files instead of merging them - -m/--nocolor remove colors from output - -Environment Variables: - DIFFPROG override the merge program: (default: 'vim -d') - DIFFSEARCHPATH override the search path. (only when using find) - (default: /etc) - -Example: DIFFPROG=meld DIFFSEARCHPATH="/boot /etc /usr" $myname -Example: $myname --output --locate - -EOF + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "A simple program to merge or remove pacnew/pacsave files")\n" + echo + printf -- "$(gettext "Usage: %s <operation> [options]")\n" "$0" + echo + printf -- "$(gettext "Search Options:")\n" + printf -- "$(gettext " -l, --locate Scan using locate")\n" + printf -- "$(gettext " -f, --find Scan using find")\n" + printf -- "$(gettext " -p, --pacmandb Scan active config files from pacman database")\n" + echo + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -o, --output Print files instead of merging them")\n" + printf -- "$(gettext " -m, --nocolor Remove colors from output")\n" + echo + printf -- "$(gettext "Environment Variables:")\n" + printf -- "$(gettext " DIFFPROG Override the merge program: (default: 'vim -d')")\n" + printf -- "$(gettext "\ + DIFFSEARCHPATH Override the search path. (only when using find)\n\ + (default: /etc)")\n" + echo + printf -- "$(gettext "Examples:")" + printf -- " DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" %s\n" "$myname" + printf -- " %s --output --locate\n" "$myname" + echo } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paclist.sh.in | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contrib/paclist.sh.in b/contrib/paclist.sh.in index f4fd540..47589f7 100644 --- a/contrib/paclist.sh.in +++ b/contrib/paclist.sh.in @@ -20,24 +20,27 @@ declare -r myname='paclist' declare -r myver='@PACKAGE_VERSION@' +# gettext initialization export TEXTDOMAIN='pacman' -export TEXTDOMAINDIR='/usr/share/locale' +export TEXTDOMAINDIR='@localedir@' # determine whether we have gettext; make it a no-op if we do not -if ! type gettext &>/dev/null; then +if ! type -p gettext >/dev/null; then gettext() { - echo "$@" + printf "%s\n" "$@" } fi usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - printf "List all packages installed from a given repository\n" "${myname}" + printf -- "$(gettext "List all packages installed from a given repository")\n" echo - printf "Usage: %s <repository>\n" "${myname}" + printf -- "$(gettext "Usage: %s <repository>")\n" "$0" + echo + printf -- "$(gettext "Examples:")" + printf -- " %s testing\n" "$myname" echo - printf "Example: %s testing\n" "${myname}" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paclog-pkglist.sh.in | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in index 847b389..040e183 100644 --- a/contrib/paclog-pkglist.sh.in +++ b/contrib/paclog-pkglist.sh.in @@ -20,20 +20,31 @@ declare -r myname='paclog-pkglist' declare -r myver='@PACKAGE_VERSION@' -export TEXTDOMAIN='pacman' -export TEXTDOMAINDIR='/usr/share/locale' declare logfile=${1:-@localstatedir@/log/pacman.log} +# 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 + usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "Parse a log file into a list of currently installed packages")\n" echo - echo "Parse a log file into a list of currently installed packages" + printf -- "$(gettext "Usage: %s [path to pacman log]")\n" "$0" echo - printf "Usage: %s [path to pacman log]\n" "${myname}" + printf -- "$(gettext "Examples:")" + printf -- " %s @localstatedir@/log/pacman.log\n" "$myname" echo - printf "Example: %s @localstatedir@/log/pacman.log\n" "${myname}" + printf -- "$(gettext "Defaults to: @localstatedir@/log/pacman.log")\n" echo - echo 'Defaults to: @localstatedir@/log/pacman.log' } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacscripts.sh.in | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/contrib/pacscripts.sh.in b/contrib/pacscripts.sh.in index 4a1e0c5..40fd4be 100644 --- a/contrib/pacscripts.sh.in +++ b/contrib/pacscripts.sh.in @@ -27,6 +27,17 @@ set -o errexit declare -r myname='pacscripts' declare -r myver='@PACKAGE_VERSION@' +# 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 + conf="@sysconfdir@/pacman.conf" if [ ! -r "$conf" ]; then @@ -45,18 +56,20 @@ error() { } usage() { - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package")\n" echo - echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package." + printf -- "$(gettext "Usage: %s <pkgname|pkgfile>")\n" "$0" echo - echo "Usage: ${myname} <pkgname|pkgfile>" + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -h, --help Print this help message")\n" + printf -- "$(gettext " -v, --version Print program name and version")\n" echo - echo " Options:" - echo " -h, --help Print this help message" - echo " -v, --version Print program name and version" + printf -- "$(gettext "Examples:")" + printf -- " %s gconf-editor\n" "$myname" + printf -- " %s gconf-editor-3.0.1-3-x86_64.pkg.tar.xz\n" "$myname" echo - echo "Example: ${myname} gconf-editor" - echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/updpkgsums.sh.in | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index c571d29..6183e0a 100644 --- a/contrib/updpkgsums.sh.in +++ b/contrib/updpkgsums.sh.in @@ -22,20 +22,34 @@ shopt -s extglob declare -r myname='updpkgsums' declare -r myver='@PACKAGE_VERSION@' +# 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 + usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "\ +%s will perform an in place update of the checksums in the\n\ +path specified by [build file], defaulting to PKGBUILD in the current\n\ +working directory")\n" "$myname" echo - printf "%s will perform an in place update of the checksums in the\n" "${myname}" - echo "path specified by [build file], defaulting to PKGBUILD in the current" - echo "working directory." + printf -- "$(gettext "Usage: %s [options] [build file]")\n" "$0" echo - printf "Usage: %s [options] [build file]\n" "${myname}" + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -h, --help Display this help message and exit")\n" + printf -- "$(gettext " -V, --version Display version information and exit")\n" echo - echo " -h, --help display this help message and exit" - echo " -V, --version display version information and exit" + printf -- "$(gettext "These options can be passed to makepkg:")\n" + printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" echo - echo "These options can be passed to makepkg:" - echo " -m, --nocolor disable colorized output messages" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/rankmirrors.sh.in | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in index 0988fe9..bd65d73 100644 --- a/contrib/rankmirrors.sh.in +++ b/contrib/rankmirrors.sh.in @@ -24,23 +24,38 @@ trap finaloutput INT declare -r myname='rankmirrors' declare -r myver='@PACKAGE_VERSION@' +# 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/parseopts.sh) + usage() { - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "\ +Ranks pacman mirrors by their connection and opening speed. Pacman mirror\n\ +files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if the URL is\n\ +provided")\n" echo - echo "Ranks pacman mirrors by their connection and opening speed. Pacman mirror" - echo "files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if the URL is" - echo "provided." + printf -- "$(gettext "Usage: %s [options] <mirrorfile|URL>")\n" "$0" echo - echo "Usage: ${myname} [options] MIRRORFILE | URL" + printf -- "$(gettext "Options:")\n" + printf -- "$(gettext " -h, --help Show this help message and exit")\n" + printf -- "$(gettext " -n <N> Number of servers to output, 0 for all")\n" + printf -- "$(gettext " -t, --times Only output mirrors and their response times")\n" + printf -- "$(gettext " -u, --url Test a specific URL")\n" + printf -- "$(gettext " -v, --verbose Be verbose in ouptut")\n" + printf -- "$(gettext " -r, --repo <repo> Specify a repository name instead of guessing")\n" + printf -- "$(gettext " --version Show program's version number and exit")\n" echo - echo "Options:" - echo " --version show program's version number and exit" - echo " -h, --help show this help message and exit" - echo " -n NUM number of servers to output, 0 for all" - echo " -t, --times only output mirrors and their response times" - echo " -u, --url test a specific URL" - echo " -v, --verbose be verbose in ouptut" - echo " -r, --repo specify a repository name instead of guessing" } version() { -- 2.10.0
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cce5a1e 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@") +# 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) -- 2.10.0
On Thu, Sep 29, 2016 at 12:23:00PM +0200, Gordian Edenhofer wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
Again, you're still putting flag names in the translatable strings. This will only ever end badly.
Gordian Edenhofer (11): checkupdates: streamline usage function paccache: streamline usage function pacdiff: streamline usage function pacdiff: proper option handling pacdiff: streamline option syntax with makepkg paclist: streamline usage function paclog-pkglist: streamline usage function pacscripts: streamline usage function updpkgsums: streamline usage function rankmirrors: streamline usage function rankmirrors: proper option handling
contrib/checkupdates.sh.in | 9 +-- contrib/paccache.sh.in | 61 ++++++++++---------- contrib/pacdiff.sh.in | 76 +++++++++++++++---------- contrib/paclist.sh.in | 10 ++-- contrib/paclog-pkglist.sh.in | 12 ++-- contrib/pacscripts.sh.in | 18 +++--- contrib/rankmirrors.sh.in | 132 +++++++++++++++++++++---------------------- contrib/updpkgsums.sh.in | 21 ++++--- 8 files changed, 179 insertions(+), 160 deletions(-)
-- 2.10.0
On Thu, 2016-09-29 at 09:04 -0400, Dave Reisner wrote:
On Thu, Sep 29, 2016 at 12:23:00PM +0200, Gordian Edenhofer wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
Again, you're still putting flag names in the translatable strings. This will only ever end badly.
It has worked great for makepkg, see the git repo for dozens of examples [1]. [1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in#n11 66
On Thu, Sep 29, 2016 at 03:30:30PM +0200, Gordian Edenhofer wrote:
On Thu, 2016-09-29 at 09:04 -0400, Dave Reisner wrote:
On Thu, Sep 29, 2016 at 12:23:00PM +0200, Gordian Edenhofer wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
Again, you're still putting flag names in the translatable strings. This will only ever end badly.
It has worked great for makepkg, see the git repo for dozens of examples [1].
[1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in#n11 66
Has it worked great? - id.po contains --noprapare instead of --noprepare - da.po contains --finer instead of --finger - sv.po contains --inout instead of --input Repeating this mistake of allowing flags to be translated is purely cargo-cult nonsense. Please don't do it.
On Thu, 2016-09-29 at 09:56 -0400, Dave Reisner wrote:
On Thu, Sep 29, 2016 at 03:30:30PM +0200, Gordian Edenhofer wrote:
On Thu, 2016-09-29 at 09:04 -0400, Dave Reisner wrote:
On Thu, Sep 29, 2016 at 12:23:00PM +0200, Gordian Edenhofer wrote:
Reorganize scripts in contrib to fit the syntax and style of makepkg. Unify multiple different approaches to e.g. write a usage function, handle options and differences in naming schemas for options.
Again, you're still putting flag names in the translatable strings. This will only ever end badly.
It has worked great for makepkg, see the git repo for dozens of examples [1].
[1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in #n11 66
Has it worked great?
- id.po contains --noprapare instead of --noprepare - da.po contains --finer instead of --finger - sv.po contains --inout instead of --input
Repeating this mistake of allowing flags to be translated is purely cargo-cult nonsense. Please don't do it.
Ok, I will resubmit a new version with non-translatable flags.
Switch to parseopts. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index dff2115..cd93164 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -30,6 +30,7 @@ declare -a oldsaves declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 m4_include(../scripts/library/output_format.sh) +m4_include(../scripts/library/parseopts.sh) usage() { cat <<EOF @@ -94,7 +95,17 @@ cmd() { fi } -while [[ -n "$1" ]]; do +# Parse arguments +OPT_SHORT='lfpoVh' +OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + usage + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do case "$1" in -l|--locate) USE_LOCATE=1;; @@ -107,11 +118,14 @@ while [[ -n "$1" ]]; do --nocolor) USE_COLOR='n';; -V|--version) - version; exit 0;; + version + exit 0;; -h|--help) - usage; exit 0;; - *) - usage; exit 1;; + usage + exit 0;; + --) + shift + break 2;; esac shift done -- 2.10.0
Allow for '-m' as abbreviation for '--nocolor'. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index cd93164..3394993 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -47,7 +47,7 @@ Search Options: select one (default: --pacmandb) General Options: -o/--output print files instead of merging them - --nocolor remove colors from output + -m/--nocolor remove colors from output Environment Variables: DIFFPROG override the merge program: (default: 'vim -d') @@ -96,7 +96,7 @@ cmd() { } # Parse arguments -OPT_SHORT='lfpoVh' +OPT_SHORT='lfpomVh' OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then usage @@ -115,7 +115,7 @@ while :; do USE_PACDB=1;; -o|--output) OUTPUTONLY=1;; - --nocolor) + -m|--nocolor) USE_COLOR='n';; -V|--version) version -- 2.10.0
Switch to parseopts. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/rankmirrors.sh.in | 102 +++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 56 deletions(-) diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in index 7b50eb2..0988fe9 100644 --- a/contrib/rankmirrors.sh.in +++ b/contrib/rankmirrors.sh.in @@ -41,7 +41,6 @@ usage() { echo " -u, --url test a specific URL" echo " -v, --verbose be verbose in ouptut" echo " -r, --repo specify a repository name instead of guessing" - exit 0 } version() { @@ -120,68 +119,59 @@ finaloutput() { exit 0 } - -# Argument parsing -[[ $1 ]] || usage -while [[ $1 ]]; do - if [[ ${1:0:2} = -- ]]; then - case "${1:2}" in - help) usage ;; - version) version ;; - times) TIMESONLY=1 ; shift ;; - verbose) VERBOSE=1 ; shift ;; - url) - CHECKURL=1; - [[ $2 ]] || err "Must specify URL."; - URL="$2"; - shift 2;; - repo) - [[ $2 ]] || err "Must specify repository name."; - TARGETREPO="$2"; - shift 2;; - *) err "'$1' is an invalid argument." - esac - elif [[ ${1:0:1} = - ]]; then - - if [[ ! ${1:1:1} ]]; then - [[ -t 0 ]] && err "Stdin is empty." - IFS=$'\n' linearray=( $(</dev/stdin) ) - STDIN=1 +# Parse arguments +OPT_SHORT=':hVtvn:u:r:' +OPT_LONG=('out:' 'jobs:' 'quiet' 'nocolor' 'pacnew' 'version') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + usage + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET + +while :; do + case "$1" in + -h|--help) + usage + exit 0;; + --version) + version;; + -t|--times) + TIMESONLY=1;; + -v|--verbose) + VERBOSE=1;; + -u|--url) + CHECKURL=1 + URL="$2" + shift;; + -r|--repo) + TARGETREPO="$2" + shift;; + -n) + NUM="$2" + shift;; + --) shift - else - snum=1 - for ((i=1 ; i<${#1}; i++)); do - case ${1:$i:1} in - h) usage ;; - t) TIMESONLY=1 ;; - v) VERBOSE=1 ;; - u) - CHECKURL=1; - [[ $2 ]] || err "Must specify URL."; - URL="$2"; - snum=2;; - r) - [[ $2 ]] || err "Must specify repository name."; - TARGETREPO="$2"; - snum=2;; - n) - [[ $2 ]] || err "Must specify number."; - NUM="$2"; - snum=2;; - *) err "'$1' is an invalid argument." ;; - esac - done - shift $snum - fi + break 2;; + esac + shift +done +if [[ ${#@} -eq 1 ]]; then + if [[ $1 == "-" ]]; then + [[ -t 0 ]] && err "Stdin is empty." + IFS=$'\n' linearray=( $(</dev/stdin) ) + STDIN=1 elif [[ -f $1 ]]; then FILE="1" IFS=$'\n' linearray=( $(<$1) ) [[ $linearray ]] || err "File is empty." - shift - else + elif [[ ! -f $1 ]]; then err "'$1' does not exist." fi -done +else + usage + exit 1 +fi # Some sanity checks [[ $NUM ]] || NUM=0 -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 897cd85..0754c0d 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -60,6 +60,7 @@ REAL_PACKAGE_VERSION = $(PACKAGE_VERSION) endif edit = sed \ + -e 's|@localedir[@]|$(localedir)|g' \ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ -e 's|@localstatedir[@]|$(localstatedir)|g' \ -e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \ -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/checkupdates.sh.in | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in index ff62891..40a13ec 100644 --- a/contrib/checkupdates.sh.in +++ b/contrib/checkupdates.sh.in @@ -21,17 +21,29 @@ declare -r myname='checkupdates' declare -r myver='@PACKAGE_VERSION@' +# 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/term_colors.sh) if (( $# > 0 )); then - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "Safely print a list of pending updates")\n" echo - echo "Safely print a list of pending updates" + printf -- "$(gettext "Usage: %s")\n" "$0" echo - echo "Usage: ${myname}" + printf -- "$(gettext "Note: Export the "%s" variable to change the path of the temporary database.")\n" "CHECKUPDATES_DB" echo - echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.' exit 0 fi -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@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
On Fri, Sep 30, 2016 at 01:47:54PM +0200, Gordian Edenhofer wrote:
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@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
I'm going to need convincing that this fits the definition of "streamlined" compared to the current implementation. stream·line /ˈstrēmˌlīn/ 1. design or provide with a form that presents very little resistance to a flow of air or water, increasing speed and ease of movement. 2. make (an organization or system) more efficient and effective by employing faster or simpler working methods. This is neither faster, nor simpler, nor more efficient or effective. It certainly doesn't have lower resistance.
}
version() { -- 2.10.0
On Fri, 2016-09-30 at 08:14 -0400, Dave Reisner wrote:
On Fri, Sep 30, 2016 at 01:47:54PM +0200, Gordian Edenhofer wrote:
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@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
I'm going to need convincing that this fits the definition of "streamlined" compared to the current implementation.
stream·line /ˈstrēmˌlīn/
1. design or provide with a form that presents very little resistance to a flow of air or water, increasing speed and ease of movement. 2. make (an organization or system) more efficient and effective by employing faster or simpler working methods.
This is neither faster, nor simpler, nor more efficient or effective. It certainly doesn't have lower resistance.
Unifying the syntax of the various contrib scripts will make it easier to amend them because you don't have to honor some random style choice from the initial author. I guess most of you are more familiar with how things are done in makepkg than you are with any script in contrib.
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacdiff.sh.in | 67 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index 3394993..b9b15b8 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -29,35 +29,52 @@ USE_COLOR='y' declare -a oldsaves declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0 +# 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) usage() { - cat <<EOF -${myname} (pacman) v${myver} - -A simple program to merge or remove pacnew/pacsave files. - -Usage: $myname [-l | -f | -p] [--nocolor] - -Search Options: select one (default: --pacmandb) - -l/--locate scan using locate - -f/--find scan using find - -p/--pacmandb scan active config files from pacman database - -General Options: - -o/--output print files instead of merging them - -m/--nocolor remove colors from output - -Environment Variables: - DIFFPROG override the merge program: (default: 'vim -d') - DIFFSEARCHPATH override the search path. (only when using find) - (default: /etc) - -Example: DIFFPROG=meld DIFFSEARCHPATH="/boot /etc /usr" $myname -Example: $myname --output --locate - -EOF + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "A simple program to merge or remove pacnew/pacsave files")\n" + echo + printf -- "$(gettext "Usage: %s <operation> [options]")\n" "$0" + echo + printf -- "$(gettext "Search Options:")\n" + printf -- " -l, --locate " + printf -- "$(gettext "Scan using locate")\n" + printf -- " -f, --find " + printf -- "$(gettext "Scan using find")\n" + printf -- " -p, --pacmandb " + printf -- "$(gettext "Scan active config files from pacman database")\n" + echo + printf -- "$(gettext "Options:")\n" + printf -- " -o, --output " + printf -- "$(gettext "Print files instead of merging them")\n" + printf -- " -m, --nocolor " + printf -- "$(gettext "Remove colors from output")\n" + echo + printf -- "$(gettext "Environment Variables:")\n" + printf -- " DIFFPROG " + printf -- "$(gettext "Override the merge program: (default: '%s')")\n" "vim -d" + printf -- " DIFFSEARCHPATH " + printf -- "$(gettext "Override the search path. (only when using find)\n\ + (default: %s)")\n" "/etc" + echo + printf -- "$(gettext "Examples:")" + printf -- " DIFFPROG=meld DIFFSEARCHPATH=\"/boot /etc /usr\" %s\n" "$myname" + printf -- " %s --output --locate\n" "$myname" + echo } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paclist.sh.in | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contrib/paclist.sh.in b/contrib/paclist.sh.in index f4fd540..47589f7 100644 --- a/contrib/paclist.sh.in +++ b/contrib/paclist.sh.in @@ -20,24 +20,27 @@ declare -r myname='paclist' declare -r myver='@PACKAGE_VERSION@' +# gettext initialization export TEXTDOMAIN='pacman' -export TEXTDOMAINDIR='/usr/share/locale' +export TEXTDOMAINDIR='@localedir@' # determine whether we have gettext; make it a no-op if we do not -if ! type gettext &>/dev/null; then +if ! type -p gettext >/dev/null; then gettext() { - echo "$@" + printf "%s\n" "$@" } fi usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" echo - printf "List all packages installed from a given repository\n" "${myname}" + printf -- "$(gettext "List all packages installed from a given repository")\n" echo - printf "Usage: %s <repository>\n" "${myname}" + printf -- "$(gettext "Usage: %s <repository>")\n" "$0" + echo + printf -- "$(gettext "Examples:")" + printf -- " %s testing\n" "$myname" echo - printf "Example: %s testing\n" "${myname}" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/paclog-pkglist.sh.in | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/contrib/paclog-pkglist.sh.in b/contrib/paclog-pkglist.sh.in index 847b389..065210c 100644 --- a/contrib/paclog-pkglist.sh.in +++ b/contrib/paclog-pkglist.sh.in @@ -20,20 +20,31 @@ declare -r myname='paclog-pkglist' declare -r myver='@PACKAGE_VERSION@' -export TEXTDOMAIN='pacman' -export TEXTDOMAINDIR='/usr/share/locale' declare logfile=${1:-@localstatedir@/log/pacman.log} +# 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 + usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "Parse a log file into a list of currently installed packages")\n" echo - echo "Parse a log file into a list of currently installed packages" + printf -- "$(gettext "Usage: %s [path to pacman log]")\n" "$0" echo - printf "Usage: %s [path to pacman log]\n" "${myname}" + printf -- "$(gettext "Examples:")" + printf -- " %s @localstatedir@/log/pacman.log\n" "$myname" echo - printf "Example: %s @localstatedir@/log/pacman.log\n" "${myname}" + printf -- "$(gettext "Defaults to: %s")\n" "@localstatedir@/log/pacman.log" echo - echo 'Defaults to: @localstatedir@/log/pacman.log' } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/pacscripts.sh.in | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/contrib/pacscripts.sh.in b/contrib/pacscripts.sh.in index 4a1e0c5..0c5e926 100644 --- a/contrib/pacscripts.sh.in +++ b/contrib/pacscripts.sh.in @@ -27,6 +27,17 @@ set -o errexit declare -r myname='pacscripts' declare -r myver='@PACKAGE_VERSION@' +# 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 + conf="@sysconfdir@/pacman.conf" if [ ! -r "$conf" ]; then @@ -45,18 +56,22 @@ error() { } usage() { - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package")\n" echo - echo "Prints the {pre,post}_{install,remove,upgrade} scripts of a given package." + printf -- "$(gettext "Usage: %s <pkgname|pkgfile>")\n" "$0" echo - echo "Usage: ${myname} <pkgname|pkgfile>" + printf -- "$(gettext "Options:")\n" + printf -- " -h, --help " + printf -- "$(gettext "Print this help message")\n" + printf -- " -v, --version " + printf -- "$(gettext "Print program name and version")\n" echo - echo " Options:" - echo " -h, --help Print this help message" - echo " -v, --version Print program name and version" + printf -- "$(gettext "Examples:")" + printf -- " %s gconf-editor\n" "$myname" + printf -- " %s gconf-editor-3.0.1-3-x86_64.pkg.tar.xz\n" "$myname" echo - echo "Example: ${myname} gconf-editor" - echo "Example: ${myname} gconf-editor-3.0.1-3-x86_64.pkg.tar.xz" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/updpkgsums.sh.in | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/contrib/updpkgsums.sh.in b/contrib/updpkgsums.sh.in index c571d29..132c192 100644 --- a/contrib/updpkgsums.sh.in +++ b/contrib/updpkgsums.sh.in @@ -22,20 +22,37 @@ shopt -s extglob declare -r myname='updpkgsums' declare -r myver='@PACKAGE_VERSION@' +# 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 + usage() { - printf "%s (pacman) v%s\n" "${myname}" "${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "\ +%s will perform an in place update of the checksums in the\n\ +path specified by [build file], defaulting to PKGBUILD in the current\n\ +working directory")\n" "$myname" echo - printf "%s will perform an in place update of the checksums in the\n" "${myname}" - echo "path specified by [build file], defaulting to PKGBUILD in the current" - echo "working directory." + printf -- "$(gettext "Usage: %s [options] [build file]")\n" "$0" echo - printf "Usage: %s [options] [build file]\n" "${myname}" + printf -- "$(gettext "Options:")\n" + printf -- " -h, --help " + printf -- "$(gettext "Display this help message and exit")\n" + printf -- " -V, --version " + printf -- "$(gettext "Display version information and exit")\n" echo - echo " -h, --help display this help message and exit" - echo " -V, --version display version information and exit" + printf -- "$(gettext "These options can be passed to makepkg:")\n" + printf -- " -m, --nocolor " + printf -- "$(gettext "Disable colorized output messages")\n" echo - echo "These options can be passed to makepkg:" - echo " -m, --nocolor disable colorized output messages" } version() { -- 2.10.0
Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> --- contrib/rankmirrors.sh.in | 48 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in index 0988fe9..e1e0503 100644 --- a/contrib/rankmirrors.sh.in +++ b/contrib/rankmirrors.sh.in @@ -24,23 +24,45 @@ trap finaloutput INT declare -r myname='rankmirrors' declare -r myver='@PACKAGE_VERSION@' +# 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/parseopts.sh) + usage() { - echo "${myname} (pacman) v${myver}" + printf "%s (pacman) %s\n" "$myname" "$myver" + echo + printf -- "$(gettext "\ +Ranks pacman mirrors by their connection and opening speed. Pacman mirror\n\ +files are located in %s. It can also rank one mirror if the URL is\n\ +provided")\n" "@sysconfdir@/pacman.d/" echo - echo "Ranks pacman mirrors by their connection and opening speed. Pacman mirror" - echo "files are located in @sysconfdir@/pacman.d/. It can also rank one mirror if the URL is" - echo "provided." + printf -- "$(gettext "Usage: %s [options] <mirrorfile|URL>")\n" "$0" echo - echo "Usage: ${myname} [options] MIRRORFILE | URL" + printf -- "$(gettext "Options:")\n" + printf -- " -h, --help " + printf -- "$(gettext "Show this help message and exit")\n" + printf -- " -n <N> " + printf -- "$(gettext "Number of servers to output, 0 for all")\n" + printf -- " -t, --times " + printf -- "$(gettext "Only output mirrors and their response times")\n" + printf -- " -u, --url " + printf -- "$(gettext "Test a specific URL")\n" + printf -- " -v, --verbose " + printf -- "$(gettext "Be verbose in ouptut")\n" + printf -- " -r, --repo <repo> " + printf -- "$(gettext "Specify a repository name instead of guessing")\n" + printf -- " --version " + printf -- "$(gettext "Show program's version number and exit")\n" echo - echo "Options:" - echo " --version show program's version number and exit" - echo " -h, --help show this help message and exit" - echo " -n NUM number of servers to output, 0 for all" - echo " -t, --times only output mirrors and their response times" - echo " -u, --url test a specific URL" - echo " -v, --verbose be verbose in ouptut" - echo " -r, --repo specify a repository name instead of guessing" } version() { -- 2.10.0
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cc243c9 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@") +# 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) @@ -54,13 +65,18 @@ usage() { printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0" echo printf -- "$(gettext "Options:")\n" - printf -- "$(gettext " -h, --help Show this help message and exit")\n" - printf -- "$(gettext " -q, --quiet Silence most of the status reporting")\n" - printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" - printf -- "$(gettext " -o, --out <dir> Write output to specified directory (instead of \$PKGDEST)")\n" - printf -- "$(gettext " --pacnew Package .pacnew files")\n" + printf -- " -h, --help " + printf -- "$(gettext "Show this help message and exit")\n" + printf -- " -q, --quiet " + printf -- "$(gettext "Silence most of the status reporting")\n" + printf -- " -m, --nocolor " + printf -- "$(gettext "Disable colorized output messages")\n" + printf -- " -o, --out <dir> " + printf -- "$(gettext "Write output to specified directory (instead of %s)")\n" "\$PKGDEST" + printf -- " --pacnew " + printf -- "$(gettext "Package .pacnew files")\n" echo - printf -- "$(gettext "Examples:")" + printf -- "$(gettext "Examples:")" printf -- " %s linux-headers\n" "$myname" printf -- " %s -o ~/packages libarchive\n" "$myname" printf -- " %s --nocolor --pacnew gzip make binutils\n" "$myname" -- 2.10.0
On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cc243c9 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@")
+# 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" "$@"
Not sure if this is copypasted from somewhere, but it's wrong. Consider the output of: printf '%s\n' 1 2 3 vs. printf '%s\n' '1 2 3' You probably wanted this to be: printf '%s\n' "$*"
+ } +fi + m4_include(../scripts/library/output_format.sh) m4_include(../scripts/library/parseopts.sh)
@@ -54,13 +65,18 @@ usage() { printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0" echo printf -- "$(gettext "Options:")\n" - printf -- "$(gettext " -h, --help Show this help message and exit")\n" - printf -- "$(gettext " -q, --quiet Silence most of the status reporting")\n" - printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" - printf -- "$(gettext " -o, --out <dir> Write output to specified directory (instead of \$PKGDEST)")\n" - printf -- "$(gettext " --pacnew Package .pacnew files")\n" + printf -- " -h, --help " + printf -- "$(gettext "Show this help message and exit")\n"
This splitting/wrapping doesn't really make me think that this is an improvement. Other patches are subjectively worse IMO -- particularly cases where the usage wraps onto multiple lines and you're adding arbitrary amounts of whitespace wrapping. It's hard to get right and I suspect it'll be broken in the future. There's a reason I used a heredoc for paccache's usage function. It's natural, reads easily, and is easy to extend. Still wondering if we actually care about translations for contrib, or if we care about contrib at all.
+ printf -- " -q, --quiet " + printf -- "$(gettext "Silence most of the status reporting")\n" + printf -- " -m, --nocolor " + printf -- "$(gettext "Disable colorized output messages")\n" + printf -- " -o, --out <dir> " + printf -- "$(gettext "Write output to specified directory (instead of %s)")\n" "\$PKGDEST" + printf -- " --pacnew " + printf -- "$(gettext "Package .pacnew files")\n" echo - printf -- "$(gettext "Examples:")" + printf -- "$(gettext "Examples:")" printf -- " %s linux-headers\n" "$myname" printf -- " %s -o ~/packages libarchive\n" "$myname" printf -- " %s --nocolor --pacnew gzip make binutils\n" "$myname" -- 2.10.0
On Fri, 2016-09-30 at 08:14 -0400, Dave Reisner wrote:
On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cc243c9 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@") +# 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" "$@"
Not sure if this is copypasted from somewhere, but it's wrong. Consider the output of:
printf '%s\n' 1 2 3
vs.
printf '%s\n' '1 2 3'
You probably wanted this to be: printf '%s\n' "$*"
Yes, this is indeed copy-pasted from makepkg [1] since I though it would be properly scripted there.
+ } +fi + m4_include(../scripts/library/output_format.sh) m4_include(../scripts/library/parseopts.sh) @@ -54,13 +65,18 @@ usage() { printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0" echo printf -- "$(gettext "Options:")\n" - printf -- "$(gettext " -h, --help Show this help message and exit")\n" - printf -- "$(gettext " -q, --quiet Silence most of the status reporting")\n" - printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" - printf -- "$(gettext " -o, --out <dir> Write output to specified directory (instead of \$PKGDEST)")\n" - printf -- "$(gettext " --pacnew Package .pacnew files")\n" + printf -- " -h, --help " + printf -- "$(gettext "Show this help message and exit")\n"
This splitting/wrapping doesn't really make me think that this is an improvement. Other patches are subjectively worse IMO -- particularly cases where the usage wraps onto multiple lines and you're adding arbitrary amounts of whitespace wrapping. It's hard to get right and I suspect it'll be broken in the future. There's a reason I used a heredoc for paccache's usage function. It's natural, reads easily, and is easy to extend.
Still wondering if we actually care about translations for contrib, or if we care about contrib at all.
I really like heredocs and initially submitted my bacman patch using them for the very same reasons you mentioned. However I was advised to follow the style from scripts like makepkg, repo-add etc. [1] https://git.archlinux.org/pacman.git/tree/scripts/makepkg.sh.in#n12 26
Had to try this myself because I don't trust you on this for whatever reason: $ set -- -a '1 2 3' -b; printf '<%s>\n' "$@" <-a> <1 2 3> <-b> $ set -- -a '1 2 3' -b; printf '<%s>\n' "$*" <-a 1 2 3 -b> Wow uh. So. My own expectation was that "1 2 3" would be split up too instead. I'm not decided on which of these makepkg should do. I can submit the implied makepkg patch and scan the project tree for other instances of this. cheers! mar77i
On 30/09/16 22:14, Dave Reisner wrote:
On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cc243c9 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@")
+# 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" "$@"
Not sure if this is copypasted from somewhere, but it's wrong. Consider the output of:
printf '%s\n' 1 2 3
vs.
printf '%s\n' '1 2 3'
You probably wanted this to be: printf '%s\n' "$*"
Just because I am being dumb... Can someone explain the issue here: # foo1() { printf "%s\n" "$@"; } # foo2() { printf "%s\n" "$*"; } # foo1 "test string" test string # foo2 "test string" test string I don't see a difference. Allan
On Sat, 1 Oct 2016 17:41:51 +1000 Allan McRae <allan@archlinux.org> wrote:
On 30/09/16 22:14, Dave Reisner wrote:
On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cc243c9 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@")
+# 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" "$@"
Not sure if this is copypasted from somewhere, but it's wrong. Consider the output of:
printf '%s\n' 1 2 3
vs.
printf '%s\n' '1 2 3'
You probably wanted this to be: printf '%s\n' "$*"
Just because I am being dumb... Can someone explain the issue here:
# foo1() { printf "%s\n" "$@"; } # foo2() { printf "%s\n" "$*"; }
# foo1 "test string" test string
# foo2 "test string" test string
I don't see a difference.
Cause you never tested w/out quotes (multiple args): # foo1 test string test string # foo2 test string test string
Allan
On 01/10/16 19:16, Olivier Brunel wrote:
On Sat, 1 Oct 2016 17:41:51 +1000 Allan McRae <allan@archlinux.org> wrote:
On 30/09/16 22:14, Dave Reisner wrote:
On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be translatable with gettext. --- contrib/bacman.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 39fbe99..cc243c9 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -32,6 +32,17 @@ QUIET=0 # Required for fakeroot because options are shifted off the array. ARGS=("$@")
+# 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" "$@"
Not sure if this is copypasted from somewhere, but it's wrong. Consider the output of:
printf '%s\n' 1 2 3
vs.
printf '%s\n' '1 2 3'
You probably wanted this to be: printf '%s\n' "$*"
Just because I am being dumb... Can someone explain the issue here:
# foo1() { printf "%s\n" "$@"; } # foo2() { printf "%s\n" "$*"; }
# foo1 "test string" test string
# foo2 "test string" test string
I don't see a difference.
Cause you never tested w/out quotes (multiple args):
# foo1 test string test string
# foo2 test string test string
Good thing all gettext calls require quotes then. A
participants (5)
-
Allan McRae
-
Dave Reisner
-
Gordian Edenhofer
-
Martin Kühne
-
Olivier Brunel