From 428fe44d163560a504835f07a02044468672ccf3 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Thu, 13 Mar 2014 11:04:18 +0200 Subject: [PATCH] new and improved --- anduril/anduril-component-doc | 69 +++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/anduril/anduril-component-doc b/anduril/anduril-component-doc index 1ae41eb..0e7191a 100755 --- a/anduril/anduril-component-doc +++ b/anduril/anduril-component-doc @@ -13,11 +13,20 @@ usage () { echo " Autobundles are loaded if exist. "; } + +add_autobundles () { + for b in $( find -L "$ANDURIL_HOME" -maxdepth 2 -name bundle.xml ); + do if grep autoload.*true "$b" > /dev/null + then bundles+=( $( dirname "$b" ) ) + fi + done + +} + bundlefunc () { for ((i=0; i<${#bundles[@]}; i++ )) do [[ -a ${bundles[$i]}/bundle.xml ]] || echo Bundle ${bundles[$i]} not found || exit 1 BUNDLESTRING=${BUNDLESTRING}" -b \"$( readlink -f ${bundles[$i]} )\"" - RUNNERSTRING=${RUNNERSTRING}"//$ -b \"$( readlink -f ${bundles[$i]} )\" \n" done } @@ -26,7 +35,7 @@ listcomps () { for ((i=0; i<${#bundles[@]}; i++ )) do bname=$( cat ${bundles[$i]}/bundle.xml | tr -d -c [:print:] | tr " " _ | sed 's,.*\(.*\).*,\1,' ) [[ -a ${bundles[$i]}/bundle.xml ]] || echo Bundle ${bundles[$i]} not found || exit 1 - compList+=( $( find ${bundles[$i]} -maxdepth 3 -mindepth 3 -name component.xml -printf '%P\n' | sed -e 's,/component.xml,,' -e s,.*/,"\($bname\):", ) ) + compList+=( $( find ${bundles[$i]} -maxdepth 3 -mindepth 3 -name component.xml -printf '%P\n' | sed -e 's,/component.xml,,' -e s,.*/,"\($bname\):", | sort ) ) done } printcomps () { @@ -35,6 +44,16 @@ printcomps () { done } +listdoc () { + +if [ -z "$SHORTLIST" ] +then anduril run-component $1 $BUNDLESTRING --doc $LONGLIST +else + anduril run-component $1 $BUNDLESTRING --doc $LONGLIST | grep "^[*=]" +fi + +} + bundles=( ) LONGLIST="" SHORTLIST="" @@ -43,7 +62,7 @@ while getopts $options option do case $option in b ) bundles+=($OPTARG);; - l ) listcomps; printcomps | sort; exit;; + l ) add_autobundles; listcomps; printcomps; exit;; L ) LONGLIST="-L";; h ) usage; exit;; s ) SHORTLIST="yes";; @@ -53,6 +72,13 @@ done shift $(($OPTIND - 1)) +if [ ! -e "$ANDURIL_HOME/anduril.jar" ] +then echo ANDURIL_HOME/anduril.jar not found! + exit 1 +fi + +add_autobundles + bundlefunc if [ -z "$1" ] then usage @@ -64,8 +90,37 @@ then echo -e "\n\nFile $1.and already exists. Remove it first." exit fi -if [ -z "$SHORTLIST" ] -then anduril run-component $1 $BUNDLESTRING --doc $LONGLIST -else - anduril run-component $1 $BUNDLESTRING --doc $LONGLIST | grep "^[*=]" +listdoc "$1" +if [ $? -ne 0 ] +then listcomps + echo "Maybe you were looking for:" + substrings=( $( printcomps | sed 's,.*):,,' | grep -i "$1" ) ) + if [ ${#substrings[@]} -eq 1 ] # only 1 match found! + then echo ${substrings[0]} + listdoc ${substrings[0]} + exit 0 + fi + if [ ${#substrings[@]} -gt 1 ] # multiple matches + then printcomps | grep -i ":.*$1" + exit 1 + fi + # no grep matches, bring out the heavy artillery: + printcomps | sed 's,.*):,,' | python <( echo ' +import difflib as dl +import sys +match=[] +ratio=[] +for line in sys.stdin: + s=dl.SequenceMatcher(None, line, "'$1'") + s_ratio=s.ratio() + if s_ratio > 0: + ratio.append(s_ratio) + match.append(line.strip()) +sorted_ratios=[i[0] for i in sorted(enumerate(ratio), key=lambda x:x[1])] +best_matches=[match[i] for i in sorted_ratios[-5:]] +best_matches.reverse() +print( ", ".join(best_matches)) +' ) + + exit 1 fi