release 1.0

- added more commands, shuffle the order
- added installation script
- using make to run tests
- update README with installation steps and usage
This commit is contained in:
Kunal Dabir 2017-08-29 12:01:11 +05:30
parent be35ddcfff
commit 4dddf27108
5 changed files with 58 additions and 23 deletions

View File

@ -13,3 +13,7 @@ insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[{Makefile, makefile}]
indent_style = tab
indent_size = 4

View File

@ -1,4 +1,5 @@
language: bash
before_install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
@ -6,4 +7,4 @@ before_install:
install:
- sudo apt-get install -qq bc
script:
- bats .hastest.bats
- make test

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
test:
bats .hastest.bats
install:
cp has /usr/local/bin/has
uninstall:
rm -f /usr/local/bin/has

View File

@ -4,20 +4,37 @@
## How ?
Download the `has` file. There is no dependency apart from `bash` itself
Download the `has` file. There is no dependency apart from `bash` itself
$ bash has node npm java git gradle
$ has node npm java git gradle
✔ node 8.2.1
✔ npm 5.3.0
✔ java 1.8.0
✔ git 2.14.1
✔ gradle 4.0.1
If everything is good `has` exists with status code `0`. The status code
reflects number of commands **not found** on your path.
$ has node go javac
✔ node 8.2.1
✔ go 1.8.3
✘ javac
And echo the status:
$ echo $?
1
## Installing
Just download the `has` script in your path.
If you are lazy, you can has of the internet as well
git clone https://github.com/kdabir/has.git && cd has && make install
If you are lazy, you can run `has` directly off the internet as well:
curl -sL https://raw.githubusercontent.com/kdabir/has/master/has | bash -s git node npm
✔ git 2.14.1
@ -25,7 +42,7 @@ If you are lazy, you can has of the internet as well
✔ npm 5.3.0
And if that's too much of typing everytime, setup an alias
And if that's too much of typing every time, setup an alias
alias has="curl -sL https://raw.githubusercontent.com/kdabir/has/master/has | bash -s"

41
has Normal file → Executable file
View File

@ -48,6 +48,23 @@ __detect(){
esac
case ${command} in
# those that need --version flag
git|hg|svn|bzr) __dynamic_detect--version ${command} ;;
node|npm) __dynamic_detect--version ${command} ;;
ruby|gem|rake|bundle) __dynamic_detect--version ${command} ;;
python|python3) __dynamic_detect--version ${command} ;;
perl) __dynamic_detect--version ${command} ;;
groovy|gradle|mvn) __dynamic_detect--version ${command} ;;
bash|zsh|curl|wget) __dynamic_detect--version ${command} ;;
vim|emacs|nano|subl) __dynamic_detect--version ${command} ;;
bats|tree|ack|autojump) __dynamic_detect--version ${command} ;;
# those that need -version flag
ant|java|javac) __dynamic_detect-version ${command} ;;
## Example of commands that need custom processing
go)
version=$(go version 2>&1| egrep -o "$REGEX_SIMPLE_VERSION" | head -1)
status=$?
@ -68,30 +85,18 @@ __detect(){
if [ $? -eq 1 ]; then status=0; else status=1; fi
;;
# those that need -version flag
ant|java|javac) __dynamic_detect-version ${command} ;;
# those that need --version flag
git|hg|svn|bzr) __dynamic_detect--version ${command} ;;
node|npm) __dynamic_detect--version ${command} ;;
ruby|gem|rake|bundle) __dynamic_detect--version ${command} ;;
python|python3) __dynamic_detect--version ${command} ;;
perl) __dynamic_detect--version ${command} ;;
groovy|gradle|mvn) __dynamic_detect--version ${command} ;;
bash|zsh|curl|wget) __dynamic_detect--version ${command} ;;
vim|emacs|nano|subl) __dynamic_detect--version ${command} ;;
bats|tree|ack|autojump) __dynamic_detect--version ${command} ;;
*)
## Can allow dynamic checking here
if [[ "${HAS_ALLOW_UNSAFE}" == "y" ]]; then
__dynamic_detect--version ${command}
## fallback checking based on status!=127
else
status="-1"
fi
;;
esac
## When unsafe processing is not allowed, the -1 signifies
if [ "$status" -eq "-1" ]; then
echo ${FAIL} ${command} "not understood"
@ -115,11 +120,11 @@ __detect(){
# if no arguments passed to script
if [ "$#" -eq 0 ]; then
# print help
echo "${0} v1.0"
echo "USAGE: ${0} <command-names>.."
echo "EXAMPLE: ${0} git curl node"
BINARY_NAME="has"
echo "${BINARY_NAME} v1.0"
echo "USAGE: ${BINARY_NAME} <command-names>.."
echo "EXAMPLE: ${BINARY_NAME} git curl node"
else