scripts: refactor output formatting functions
Move the common output formatting functions into a separate library file and import that into each script. makepkg is excluded due to its additional color formatting. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
6f3a2145b0
commit
4272b37d3d
6 changed files with 48 additions and 69 deletions
|
@ -25,6 +25,7 @@ EXTRA_DIST = \
|
||||||
$(LIBRARY)
|
$(LIBRARY)
|
||||||
|
|
||||||
LIBRARY = \
|
LIBRARY = \
|
||||||
|
library/output_format.sh \
|
||||||
library/parse_options.sh
|
library/parse_options.sh
|
||||||
|
|
||||||
# Files that should be removed, but which Automake does not know.
|
# Files that should be removed, but which Automake does not know.
|
||||||
|
@ -69,13 +70,30 @@ $(OURSCRIPTS): Makefile
|
||||||
@chmod a-w $@.tmp
|
@chmod a-w $@.tmp
|
||||||
@mv $@.tmp $@
|
@mv $@.tmp $@
|
||||||
|
|
||||||
makepkg: $(srcdir)/makepkg.sh.in $(srcdir)/library/parse_options.sh
|
makepkg: \
|
||||||
pacman-db-upgrade: $(srcdir)/pacman-db-upgrade.sh.in
|
$(srcdir)/makepkg.sh.in \
|
||||||
pacman-key: $(srcdir)/pacman-key.sh.in
|
$(srcdir)/library/parse_options.sh
|
||||||
|
|
||||||
|
pacman-db-upgrade: \
|
||||||
|
$(srcdir)/pacman-db-upgrade.sh.in \
|
||||||
|
$(srcdir)/library/output_format.sh
|
||||||
|
|
||||||
|
pacman-key: \
|
||||||
|
$(srcdir)/pacman-key.sh.in \
|
||||||
|
$(srcdir)/library/output_format.sh
|
||||||
|
|
||||||
pacman-optimize: $(srcdir)/pacman-optimize.sh.in
|
pacman-optimize: $(srcdir)/pacman-optimize.sh.in
|
||||||
pkgdelta: $(srcdir)/pkgdelta.sh.in
|
|
||||||
|
pkgdelta: \
|
||||||
|
$(srcdir)/pkgdelta.sh.in \
|
||||||
|
$(srcdir)/library/output_format.sh
|
||||||
|
|
||||||
rankmirrors: $(srcdir)/rankmirrors.sh.in
|
rankmirrors: $(srcdir)/rankmirrors.sh.in
|
||||||
repo-add: $(srcdir)/repo-add.sh.in
|
|
||||||
|
repo-add: \
|
||||||
|
$(srcdir)/repo-add.sh.in \
|
||||||
|
$(srcdir)/library/output_format.sh
|
||||||
|
|
||||||
repo-remove: $(srcdir)/repo-add.sh.in
|
repo-remove: $(srcdir)/repo-add.sh.in
|
||||||
rm -f repo-remove
|
rm -f repo-remove
|
||||||
$(LN_S) repo-add repo-remove
|
$(LN_S) repo-add repo-remove
|
||||||
|
|
21
scripts/library/output_format.sh
Normal file
21
scripts/library/output_format.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
msg() {
|
||||||
|
(( QUIET )) && return
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf "==> ${mesg}\n" "$@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
msg2() {
|
||||||
|
(( QUIET )) && return
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf " -> ${mesg}\n" "$@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
local mesg=$1; shift
|
||||||
|
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
||||||
|
}
|
|
@ -28,15 +28,8 @@ myver='@PACKAGE_VERSION@'
|
||||||
eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
|
eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
|
||||||
dbroot="${DBPath:-@localstatedir@/lib/pacman/}"
|
dbroot="${DBPath:-@localstatedir@/lib/pacman/}"
|
||||||
|
|
||||||
msg() {
|
m4_include(library/output_format.sh)
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
error () {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> ERROR: ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "pacman-db-upgrade (pacman) %s\n\n" "$myver"
|
printf "pacman-db-upgrade (pacman) %s\n\n" "$myver"
|
||||||
printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0"
|
printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0"
|
||||||
|
|
|
@ -26,26 +26,7 @@ export TEXTDOMAINDIR='@localedir@'
|
||||||
|
|
||||||
myver="@PACKAGE_VERSION@"
|
myver="@PACKAGE_VERSION@"
|
||||||
|
|
||||||
msg() {
|
m4_include(library/output_format.sh)
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> ${mesg}\n" "$@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
msg2() {
|
|
||||||
(( QUIET )) && return
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf " -> ${mesg}\n" "$@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
warning() {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "pacman-key (pacman) %s\n" ${myver}
|
printf "pacman-key (pacman) %s\n" ${myver}
|
||||||
|
|
|
@ -34,21 +34,7 @@ QUIET=0
|
||||||
# ensure we have a sane umask set
|
# ensure we have a sane umask set
|
||||||
umask 0022
|
umask 0022
|
||||||
|
|
||||||
msg() {
|
m4_include(library/output_format.sh)
|
||||||
(( QUIET )) && return
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> ${mesg}\n" "$@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
warning() {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
# print usage instructions
|
# print usage instructions
|
||||||
usage() {
|
usage() {
|
||||||
|
|
|
@ -38,27 +38,7 @@ CLEAN_LOCK=0
|
||||||
# ensure we have a sane umask set
|
# ensure we have a sane umask set
|
||||||
umask 0022
|
umask 0022
|
||||||
|
|
||||||
msg() {
|
m4_include(library/output_format.sh)
|
||||||
(( QUIET )) && return
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> ${mesg}\n" "$@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
msg2() {
|
|
||||||
(( QUIET )) && return
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf " -> ${mesg}\n" "$@" >&1
|
|
||||||
}
|
|
||||||
|
|
||||||
warning() {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
local mesg=$1; shift
|
|
||||||
printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
# print usage instructions
|
# print usage instructions
|
||||||
usage() {
|
usage() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue