diff --git a/README.md b/README.md index f93214f..82eb54a 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,16 @@ -# dq +# has -Check how developer friendly is your machine! +`has` helps you check presence of various command line tools on path. ## How ? -Just fire the following from the Terminal + Download the `has` file. There is no dependency apart from `bash` itself - curl -sL https://dqhub.herokuapp.com/dq?check=*/java,*/ruby,*/python,*/git,*/node | bash` - -Should produce output like: - - ✔ git 2.3.0 - ✔ java 1.8.0 - ✔ node 0.12.0 - ✔ python 2.7.6 - ✔ ruby 2.1.2 - Your dq is 5 / 5 - -We have checks for more than 40 commands, - -## Sharable url? -The urls like above look bit long and scary. They are not 'share' friendly. We've got you covered. You can shorten -the url either using dqhub itself (and give a logical name too) or any third party url-shortner. - -We have already done for the check that we did above: - - curl -sL https://dqhub.herokuapp.com/check/minimal | bash - -**Feeling courageous**, see what all you have got : - - curl -sL https://dqhub.herokuapp.com/check/all | bash - -This checks for about 40 commands on your box - -## More configurable DQ - -You can edit the query params to make dq check for only those commands that you care about: - - https://dqhub.herokuapp.com/dq?check=frontend/* - -Check the lib directory structure, `check` query param should be comma separated list of globs (path) - - -## Running Locally - -`cd` in to directory and just do a `bundle install` once and then to start server `rackup`. - - -## Rolling out your own locally - -When you need to mix and match, it's equally simple. Checkout the repo, and execute from the root: - -`ruby build.rb | sh` - -For example, if you develop frontend apps with node/ruby and use some typical databases - -`ruby build.rb "db/*,frontend/*,ruby/*" | sh` - -Or, you develop server side java/groovy and use some common databases - -`ruby build.rb "java/*,groovy/*,db/*" | sh` - -There no external gem dependency, you just need to have `ruby` though. - - -## Deploying to heroku - - heroku addons:add mongolab - -## #noserver -checkout bash-only branch, it's maintained by awesome @dexterous. - -## About - -Ever got onto a new machine or a remote server ? If you develop, you almost certainly need to check availability of your -tool-chain on command line. DQ is intended to relieve you from pain of checking each command individually. - -It was named DQ as Developer Quotient (or Developer Friendliness Quotient of a machine), which may not be the most -apt name but that was the best name I could think of. - -## Contributing - -Please submit more command checks, it's very easy to do so. Fork the repo and send PR. -Issues and feedback welcome. - -## Paranoid ? - -Don't want to run `curl` piping to `bash`. Understandably, you might be concerned. Worry not. -- If you still want to check, do a `curl -sL | cat` first. - (replacing `bash` with `cat`, to see the content of the file ) + $ bash 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 ### ♥ diff --git a/has b/has new file mode 100644 index 0000000..d7dc53f --- /dev/null +++ b/has @@ -0,0 +1,121 @@ +#!/usr/bin/env bash + +## Important so that version is not extracted for failed commands (not found) +set -o pipefail + +PASS='✔' +FAIL='✘' + +REGEX_SIMPLE_VERSION="([[:digit:]]+\.?){2,3}" + +__dynamic_detect(){ + cmd=$1 + params=$2 + version=$(eval ${cmd} ${params} "2>&1" | egrep -o "$REGEX_SIMPLE_VERSION" | head -1) + status=$? +} + +# commands that use `--version` flag +__dynamic_detect--version(){ + __dynamic_detect $1 "--version" +} + +## commands that use `-version` flag +__dynamic_detect-version(){ + __dynamic_detect $1 "-version" +} + +# commands that use `-v` flag +__dynamic_detect-v(){ + __dynamic_detect $1 "-v" +} + + +__detect(){ + name=$1 + + # setup aliases + case ${name} in + golang) command="go" ;; + jre) command="java" ;; + jdk) command="javac" ;; + nodejs) command="node" ;; + goreplay) command="gor";; + *) command=${name} ;; + esac + + case ${command} in + go) + version=$(go version 2>&1| egrep -o "$REGEX_SIMPLE_VERSION" | head -1) + status=$? + ;; + + hugo) + version=$(hugo version 2>&1| egrep -o "$REGEX_SIMPLE_VERSION" | head -1) + status=$? + ;; + + ab) + version=$(ab -V 2>&1 | egrep -o "$REGEX_SIMPLE_VERSION" | head -1) + status=$? + ;; + + gor) + version=$(gor version 2>&1 | egrep -o "$REGEX_SIMPLE_VERSION" | head -1) + 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|node|npm|ruby|gem|rake) __dynamic_detect--version ${command} ;; + groovy|gradle) __dynamic_detect--version ${command} ;; + + *) + ## Can allow dynamic checking here + if [[ "${HAS_ALLOW_UNSAFE}" == "y" ]]; then + __dynamic_detect--version ${command} + else + status="-1" + fi + ;; + esac + + if [ "$status" -eq "-1" ]; then + + echo ${FAIL} ${command} "not understood" + + elif [ $status -eq 127 ]; then + + echo ${FAIL} ${command} + + elif [ ${status} -eq 0 ]; then + + echo ${PASS} ${command} ${version} + + else + + echo ${PASS} ${command} + fi +} + + +# 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" + +else + + # for each arg + for cmd in "$@"; do + __detect $cmd + done + +fi + +