From ebe59833f39c17599b2a6a7ebfe91abfed3f36d9 Mon Sep 17 00:00:00 2001 From: Kunal Dabir Date: Fri, 13 Feb 2015 13:20:25 +0530 Subject: [PATCH] extracting regex for version matching in setup. bit ugly, but can be refactored later. also grep was acting different on mac/linux mac/BSD grep no longer has -P so finally using egrep. character class \d was not working on some linux so used :digit: --- include/setup.sh | 4 +++- lib/core/git.sh | 4 ++-- lib/core/java.sh | 2 +- lib/core/node.sh | 4 ++-- lib/core/python.sh | 2 +- lib/core/ruby.sh | 2 +- lib/db/mongo.sh | 4 ++-- lib/db/mongod.sh | 4 ++-- lib/frontend/bower.sh | 4 ++-- lib/frontend/coffee.sh | 4 ++-- lib/frontend/grunt.sh | 4 ++-- lib/frontend/npm.sh | 4 ++-- lib/frontend/sass.sh | 4 ++-- lib/frontend/yo.sh | 4 ++-- lib/groovy/groovy.sh | 4 ++-- lib/java/gradle.sh | 4 ++-- 16 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/setup.sh b/include/setup.sh index 1d15dfd..b255351 100644 --- a/include/setup.sh +++ b/include/setup.sh @@ -10,6 +10,8 @@ if [[ "$1" == "--no-version" ]]; then NO_VERSION=0 fi +SIMPLE_VERSIONING="([[:digit:]]+\.?){2,3}" + if [[ $TERM == xterm-*color ]]; then PASS="\E[32m$PASS\E[0m" FAIL="\E[31m$FAIL\E[0m" @@ -23,7 +25,7 @@ _dq_report () { if [ "$NO_VERSION" -eq 0 ]; then printf "$PASS $1\n" else - printf "$PASS %-30s %s\n" $1 $3 + printf "$PASS %-30s %s \n" "${1}" "${3}" fi OK=$(($OK+1)) else diff --git a/lib/core/git.sh b/lib/core/git.sh index 6e9b3a0..d2c4d19 100644 --- a/lib/core/git.sh +++ b/lib/core/git.sh @@ -1,6 +1,6 @@ command_name="git" -output=$(git --version) +output=$(git --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/core/java.sh b/lib/core/java.sh index 6f119e5..2cab910 100644 --- a/lib/core/java.sh +++ b/lib/core/java.sh @@ -1,5 +1,5 @@ output=$(java -version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*\.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) _dq_report 'java' $status "$version" diff --git a/lib/core/node.sh b/lib/core/node.sh index 1f6561c..ba791f6 100644 --- a/lib/core/node.sh +++ b/lib/core/node.sh @@ -1,6 +1,6 @@ command_name="node" -output=$(node --version) +output=$(node --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/core/python.sh b/lib/core/python.sh index 07e20dd..dcfaa01 100644 --- a/lib/core/python.sh +++ b/lib/core/python.sh @@ -1,5 +1,5 @@ output=$(python --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*\.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) _dq_report 'python' $status "$version" diff --git a/lib/core/ruby.sh b/lib/core/ruby.sh index 45efd41..9b63e5d 100644 --- a/lib/core/ruby.sh +++ b/lib/core/ruby.sh @@ -1,5 +1,5 @@ output=$(ruby --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*\.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) _dq_report 'ruby' $status "$version" diff --git a/lib/db/mongo.sh b/lib/db/mongo.sh index 4b3cf92..cfacd93 100644 --- a/lib/db/mongo.sh +++ b/lib/db/mongo.sh @@ -1,6 +1,6 @@ command_name="mongo-client" -output=$(mongo --version) +output=$(mongo --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) _dq_report "$command_name" $status "$version" diff --git a/lib/db/mongod.sh b/lib/db/mongod.sh index 909a5de..907bcbc 100644 --- a/lib/db/mongod.sh +++ b/lib/db/mongod.sh @@ -1,6 +1,6 @@ command_name="mongodb" -output=$(mongod --version) +output=$(mongod --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) _dq_report "$command_name" $status "$version" diff --git a/lib/frontend/bower.sh b/lib/frontend/bower.sh index 128dc64..635a90a 100644 --- a/lib/frontend/bower.sh +++ b/lib/frontend/bower.sh @@ -1,6 +1,6 @@ command_name="bower" -output=$(bower --version) +output=$(bower --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/frontend/coffee.sh b/lib/frontend/coffee.sh index dfc52fb..4a47ea6 100644 --- a/lib/frontend/coffee.sh +++ b/lib/frontend/coffee.sh @@ -1,6 +1,6 @@ command_name="coffee" -output=$(coffee --version) +output=$(coffee --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/frontend/grunt.sh b/lib/frontend/grunt.sh index 364f632..5bf9ddf 100644 --- a/lib/frontend/grunt.sh +++ b/lib/frontend/grunt.sh @@ -1,6 +1,6 @@ command_name="grunt" -output=$(grunt --version) +output=$(grunt --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/frontend/npm.sh b/lib/frontend/npm.sh index 027c6aa..73426b7 100644 --- a/lib/frontend/npm.sh +++ b/lib/frontend/npm.sh @@ -1,6 +1,6 @@ command_name="npm" -output=$(npm --version) +output=$(npm --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/frontend/sass.sh b/lib/frontend/sass.sh index a1e8fdc..1e2984d 100644 --- a/lib/frontend/sass.sh +++ b/lib/frontend/sass.sh @@ -1,6 +1,6 @@ command_name="sass" -output=$(sass --version) +output=$(sass --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/frontend/yo.sh b/lib/frontend/yo.sh index e479429..efa162e 100644 --- a/lib/frontend/yo.sh +++ b/lib/frontend/yo.sh @@ -1,6 +1,6 @@ command_name="yeoman" -output=$(yo --version) +output=$(yo --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*.\d*") +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING") _dq_report "$command_name" $status "$version" diff --git a/lib/groovy/groovy.sh b/lib/groovy/groovy.sh index 34c482f..98618fc 100644 --- a/lib/groovy/groovy.sh +++ b/lib/groovy/groovy.sh @@ -1,5 +1,5 @@ -output=$(groovy --version) +output=$(groovy --version 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*\.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) _dq_report 'groovy' $status "$version" diff --git a/lib/java/gradle.sh b/lib/java/gradle.sh index a4a67a7..386ff90 100644 --- a/lib/java/gradle.sh +++ b/lib/java/gradle.sh @@ -1,6 +1,6 @@ command_name="gradle" output=$(gradle -v 2>&1) status=$? -version=$(echo "$output" | grep -o "\d*\.\d*" | head -1) +version=$(echo "$output" | egrep -o "$SIMPLE_VERSIONING" | head -1) -_dq_report "$command_name" $status "$version" \ No newline at end of file +_dq_report "$command_name" $status "$version"