Skip to content

Commit

Permalink
release 1.0
Browse files Browse the repository at this point in the history
- added more commands, shuffle the order
- added installation script
- using make to run tests
- update README with installation steps and usage
  • Loading branch information
kdabir committed Aug 29, 2017
1 parent be35ddc commit 4dddf27
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[{Makefile, makefile}]
indent_style = tab
indent_size = 4
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: bash

before_install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
install:
- sudo apt-get install -qq bc
script:
- bats .hastest.bats
- make test
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
bats .hastest.bats

install:
cp has /usr/local/bin/has

uninstall:
rm -f /usr/local/bin/has
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,45 @@

## 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
✔ node 8.2.1
✔ 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"

Expand Down
41 changes: 23 additions & 18 deletions has
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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=$?
Expand All @@ -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"
Expand All @@ -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

Expand Down

0 comments on commit 4dddf27

Please sign in to comment.