mirror of https://github.com/kdabir/has.git
added: colors (#26)
Support Colors #12 * added: colors No more echo with variables in them. Think of it like the Holocaust... Never. Again. * update: removed color codes from tests
This commit is contained in:
parent
8674525059
commit
4d1035e241
|
@ -3,28 +3,28 @@
|
|||
@test "works with single command check" {
|
||||
run bash has git
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ $output == *"✔ git"* ]]
|
||||
[[ "$status" -eq 0 ]]
|
||||
[[ "$(echo "${output}" | grep "✔" | grep "git")" ]]
|
||||
}
|
||||
|
||||
@test "safely tells about tools not configured" {
|
||||
run bash has foobar
|
||||
|
||||
[ "$status" -eq 1 ]
|
||||
[[ $output == *"✘ foobar not understood"* ]]
|
||||
[[ "$status" -eq 1 ]]
|
||||
[[ "$(echo "${output}" | grep "✘" | grep "foobar not understood")" ]]
|
||||
}
|
||||
|
||||
@test "env var lets override safety check" {
|
||||
HAS_ALLOW_UNSAFE=y run bash has foobar
|
||||
|
||||
[ "$status" -eq 1 ]
|
||||
[[ $output == *"✘ foobar"* ]]
|
||||
[[ "$status" -eq 1 ]]
|
||||
[[ "$(echo "${output}" | grep "✘" | grep "foobar")" ]]
|
||||
}
|
||||
|
||||
@test "status code reflects number of failed commands" {
|
||||
HAS_ALLOW_UNSAFE=y run bash has foobar make git barbaz
|
||||
HAS_ALLOW_UNSAFE=y run bash has foobar bc git barbaz
|
||||
|
||||
[ "$status" -eq 2 ]
|
||||
[[ $output == *"✘ foobar"* ]]
|
||||
[[ $output == *"✘ barbaz"* ]]
|
||||
[[ "$status" -eq 2 ]]
|
||||
[[ "$(echo "${output}" | grep "✘" | grep "foobar")" ]]
|
||||
[[ "$(echo "${output}" | grep "✘" | grep "barbaz")" ]]
|
||||
}
|
||||
|
|
26
has
26
has
|
@ -6,8 +6,8 @@
|
|||
set -o pipefail
|
||||
|
||||
## constant - symbols for success failure
|
||||
PASS='✔'
|
||||
FAIL='✘'
|
||||
PASS="\e[1m\e[38;5;2m✔\e[m"
|
||||
FAIL="\e[1m\e[38;5;1m✘\e[m"
|
||||
|
||||
## These variables are used to keep track of passed and failed commands
|
||||
OK=0
|
||||
|
@ -143,23 +143,19 @@ __detect(){
|
|||
|
||||
|
||||
if [ "$status" -eq "-1" ]; then ## When unsafe processing is not allowed, the -1 signifies
|
||||
|
||||
echo ${FAIL} ${command} "not understood"
|
||||
printf "${FAIL} ${command} not understood\n"
|
||||
KO=$(($KO+1))
|
||||
|
||||
elif [ ${status} -eq 127 ]; then ## command not installed
|
||||
|
||||
echo ${FAIL} ${command}
|
||||
printf "${FAIL} ${command}\n"
|
||||
KO=$(($KO+1))
|
||||
|
||||
elif [ ${status} -eq 0 ] || [ ${status} -eq 141 ]; then ## successfully executed
|
||||
|
||||
echo ${PASS} ${command} ${version}
|
||||
printf "${PASS} ${command} ${version}\n"
|
||||
OK=$(($OK+1))
|
||||
|
||||
else ## as long as its not 127, command is there, but we might not have been able to extract version
|
||||
|
||||
echo ${PASS} ${command}
|
||||
printf "${PASS} ${command}\n"
|
||||
OK=$(($OK+1))
|
||||
fi
|
||||
|
||||
|
@ -171,17 +167,17 @@ if [ "$#" -eq 0 ]; then
|
|||
# print help
|
||||
BINARY_NAME="has"
|
||||
VERSION="v1.2.1"
|
||||
echo "${BINARY_NAME} ${VERSION}"
|
||||
echo "USAGE: ${BINARY_NAME} <command-names>.."
|
||||
echo "EXAMPLE: ${BINARY_NAME} git curl node"
|
||||
printf "${BINARY_NAME} ${VERSION}\n"
|
||||
printf "USAGE: ${BINARY_NAME} <command-names>..\n"
|
||||
printf "EXAMPLE: ${BINARY_NAME} git curl node\n"
|
||||
|
||||
else
|
||||
|
||||
# for each arg
|
||||
for cmd in "$@"; do
|
||||
__detect $cmd
|
||||
done
|
||||
|
||||
# echo ${OK} / $(($OK+$KO))
|
||||
exit ${KO}
|
||||
exit "${KO}"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue