Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quite mode #45

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .hastest.bats
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,16 @@ teardown() {
[ "$(echo "${lines[1]}" | grep "git")" ]
[ ! "${lines[0]##*\ }" = "${lines[1]##*\ }" ]
}

@test "quite mode" {
run $has -q
[ "$status" -eq 0 ]
[ -z "${output}" ]
}

@test "status code in quite mode still equal to number of failed commands" {
HAS_ALLOW_UNSAFE=y run $has -q foobar bc git barbaz

[ "$status" -eq 2 ]
[ -z "${output}" ]
}
29 changes: 21 additions & 8 deletions has
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set -o pipefail

readonly BINARY_NAME="has"
readonly VERSION="v1.4.0"
readonly VERSION="v1.5.0"

## constants - symbols for success failure
if [[ -z $TERM ]]; then
Expand Down Expand Up @@ -223,33 +223,46 @@ __detect(){
esac

if [ "$status" -eq "-1" ]; then ## When unsafe processing is not allowed, the -1 signifies
printf '%b %s not understood\n' "${FAIL}" "${command}"
printf '%b %s not understood\n' "${FAIL}" "${command}" > "$OUTPUT"
KO=$(( KO+1 ))

elif [ ${status} -eq 127 ]; then ## command not installed
printf '%b %s\n' "${FAIL}" "${command}"
printf '%b %s\n' "${FAIL}" "${command}" > "$OUTPUT"
KO=$(( KO+1 ))

elif [ ${status} -eq 0 ] || [ ${status} -eq 141 ]; then ## successfully executed
printf "%b %s %b\n" "${PASS}" "${command}" "${txtbold}${txtyellow}${version}${txtreset}"
printf "%b %s %b\n" "${PASS}" "${command}" "${txtbold}${txtyellow}${version}${txtreset}" > "$OUTPUT"
OK=$(( OK+1 ))

else ## as long as its not 127, command is there, but we might not have been able to extract version
printf '%b %s\n' "${PASS}" "${command}"
printf '%b %s\n' "${PASS}" "${command}" > "$OUTPUT"
OK=$(( OK+1 ))
fi
} #end __detect

OPTIND=1
OUTPUT=/dev/stdout

while getopts "q" opt; do
case "$opt" in
q) QUIET="true"
OUTPUT=/dev/null
;;
esac
done

shift $((OPTIND-1))

if [ -s "${RC_FILE}" ]; then
HASRC="true"
fi

# if HASRC is not set AND no arguments passed to script
if [[ -z "${HASRC}" ]] && [ "$#" -eq 0 ]; then
# print help
printf '%s %s\n' "${BINARY_NAME}" "${VERSION}"
printf 'USAGE:\t %s <command-names>..\n' "${BINARY_NAME}"
printf 'EXAMPLE: %s git curl node\n' "${BINARY_NAME}"
printf '%s %s\n' "${BINARY_NAME}" "${VERSION}" > "$OUTPUT"
printf 'USAGE:\t %s [-q] <command-names>..\n' "${BINARY_NAME}" > "$OUTPUT"
printf 'EXAMPLE: %s git curl node\n' "${BINARY_NAME}" > "$OUTPUT"

else
# for each cli-arg
Expand Down