On Fri, Jun 10, 2011 at 4:36 AM, Allan McRae <[email protected]> wrote: > Move the common output formatting functions into a separate > library file and import that into each script. makepkg is > excluded dues to its additional color formatting. *due to
Otherwise, looks good. Depending on what you decide with the Makefile dependencies stuff I mentioned in reply to the other library func email, you may need to adjust things here too (and add it to the 4 lines requiring it). > Signed-off-by: Allan McRae <[email protected]> > --- > scripts/Makefile.am | 1 + > scripts/library/output_format.sh | 21 +++++++++++++++++++++ > scripts/pacman-db-upgrade.sh.in | 9 +-------- > scripts/pacman-key.sh.in | 21 +-------------------- > scripts/pkgdelta.sh.in | 16 +--------------- > scripts/repo-add.sh.in | 22 +--------------------- > 6 files changed, 26 insertions(+), 64 deletions(-) > create mode 100644 scripts/library/output_format.sh > > diff --git a/scripts/Makefile.am b/scripts/Makefile.am > index 74ee180..303731c 100644 > --- a/scripts/Makefile.am > +++ b/scripts/Makefile.am > @@ -24,6 +24,7 @@ EXTRA_DIST = \ > repo-add.sh.in > > LIBRARY = \ > + library/output_format.sh \ > library/parse_options.sh You'll want to add deps accordingly in the Makefile as well, so if someone updates the library file the right scripts get rebuilt. > # Files that should be removed, but which Automake does not know. > diff --git a/scripts/library/output_format.sh > b/scripts/library/output_format.sh > new file mode 100644 > index 0000000..9e890e7 > --- /dev/null > +++ b/scripts/library/output_format.sh > @@ -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 > +} > \ No newline at end of file > diff --git a/scripts/pacman-db-upgrade.sh.in b/scripts/pacman-db-upgrade.sh.in > index 17d8beb..eaaa934 100644 > --- a/scripts/pacman-db-upgrade.sh.in > +++ b/scripts/pacman-db-upgrade.sh.in > @@ -28,15 +28,8 @@ myver='@PACKAGE_VERSION@' > eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf) > dbroot="${DBPath:-@localstatedir@/lib/pacman/}" > > -msg() { > - local mesg=$1; shift > - printf "==> ${mesg}\n" "$@" >&2 > -} > +m4_include(library/output_format.sh) > > -error () { > - local mesg=$1; shift > - printf "==> ERROR: ${mesg}\n" "$@" >&2 > -} > usage() { > printf "pacman-db-upgrade (pacman) %s\n\n" "$myver" > printf "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0" > diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in > index 20ec20f..a757c9b 100644 > --- a/scripts/pacman-key.sh.in > +++ b/scripts/pacman-key.sh.in > @@ -26,26 +26,7 @@ export TEXTDOMAINDIR='@localedir@' > > myver="@PACKAGE_VERSION@" > > -msg() { > - 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 > -} > +m4_include(library/output_format.sh) > > usage() { > printf "pacman-key (pacman) %s\n" ${myver} > diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in > index d17b41d..c5a4882 100644 > --- a/scripts/pkgdelta.sh.in > +++ b/scripts/pkgdelta.sh.in > @@ -34,21 +34,7 @@ QUIET=0 > # ensure we have a sane umask set > umask 0022 > > -msg() { > - (( 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 > -} > +m4_include(library/output_format.sh) > > # print usage instructions > usage() { > diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in > index 0ffc0df..6ccefd7 100644 > --- a/scripts/repo-add.sh.in > +++ b/scripts/repo-add.sh.in > @@ -38,27 +38,7 @@ CLEAN_LOCK=0 > # ensure we have a sane umask set > umask 0022 > > -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 > -} > +m4_include(library/output_format.sh) > > # print usage instructions > usage() { > -- > 1.7.5.4 > > >
