From 4dddf27108fde9165b5818defe23de4d204791f7 Mon Sep 17 00:00:00 2001 From: Kunal Dabir Date: Tue, 29 Aug 2017 12:01:11 +0530 Subject: [PATCH] release 1.0 - added more commands, shuffle the order - added installation script - using make to run tests - update README with installation steps and usage --- .editorconfig | 4 ++++ .travis.yml | 3 ++- Makefile | 8 ++++++++ README.md | 25 +++++++++++++++++++++---- has | 41 +++++++++++++++++++++++------------------ 5 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 Makefile mode change 100644 => 100755 has diff --git a/.editorconfig b/.editorconfig index 3fed774..803935a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,7 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false + +[{Makefile, makefile}] +indent_style = tab +indent_size = 4 diff --git a/.travis.yml b/.travis.yml index 6221d94..621160e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e85f54 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +test: + bats .hastest.bats + +install: + cp has /usr/local/bin/has + +uninstall: + rm -f /usr/local/bin/has diff --git a/README.md b/README.md index 890127e..17459bd 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/has b/has old mode 100644 new mode 100755 index 94b71c6..31c2e28 --- a/has +++ b/has @@ -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} .." - echo "EXAMPLE: ${0} git curl node" + BINARY_NAME="has" + echo "${BINARY_NAME} v1.0" + echo "USAGE: ${BINARY_NAME} .." + echo "EXAMPLE: ${BINARY_NAME} git curl node" else