diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-06-08 13:08:29 -0600 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-06-08 13:08:29 -0600 |
commit | 18b74bdc32406fbe4b79c5efc0f1814683ba2b9a (patch) | |
tree | ce88cf8add0c9e5648016ee7a10fb2ee65980d5a | |
parent | 0d4d85ac0b1a2a1e2d5ed03d43f8b3b5d728ca3a (diff) |
is_built: make the version optional
-rwxr-xr-x | src/is_built | 6 | ||||
-rw-r--r-- | test/is_built-test.sh | 9 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/is_built b/src/is_built index e6797fd..a1da507 100755 --- a/src/is_built +++ b/src/is_built @@ -2,7 +2,7 @@ cmd=${0##*/} usage() { - echo "Usage: $cmd [-h] pkgname pkgver" + echo "Usage: $cmd [-h] pkgname [pkgver]" echo echo "Detect if a given package version is already in repos" echo "Assuming you want greater or equal." @@ -21,13 +21,13 @@ while getopts 'h' arg; do *) usage >&2; exit 2 ;; esac done -if [[ $# != 2 ]]; then +if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then usage >&2 exit 2 fi pkg=${1} -ver=${2} +ver=${2:-0} pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null) # if pacman fails or returns nothing diff --git a/test/is_built-test.sh b/test/is_built-test.sh index bcd46f5..04b17cd 100644 --- a/test/is_built-test.sh +++ b/test/is_built-test.sh @@ -21,17 +21,16 @@ it_displays_help() { it_fails_with_0_args() { is_built >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? - [[ $stat > 1 ]] + [[ $stat -gt 1 ]] [[ -z "$(cat $tmpdir/stdout)" ]] [[ -n "$(cat $tmpdir/stderr)" ]] } -it_fails_with_1_arg() { - is_built sh >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? +it_succeeds_with_1_arg() { + is_built sh >$tmpdir/stdout 2>$tmpdir/stderr - [[ $stat > 1 ]] [[ -z "$(cat $tmpdir/stdout)" ]] - [[ -n "$(cat $tmpdir/stderr)" ]] + [[ -z "$(cat $tmpdir/stderr)" ]] } it_returns_1_for_non_existent_package() { |