new and improved

This commit is contained in:
ville rantanen
2014-03-13 11:04:18 +02:00
parent f6ccd55634
commit 428fe44d16

View File

@@ -13,11 +13,20 @@ usage () { echo "
Autobundles are loaded if exist. 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 () { bundlefunc () {
for ((i=0; i<${#bundles[@]}; i++ )) do for ((i=0; i<${#bundles[@]}; i++ )) do
[[ -a ${bundles[$i]}/bundle.xml ]] || echo Bundle ${bundles[$i]} not found || exit 1 [[ -a ${bundles[$i]}/bundle.xml ]] || echo Bundle ${bundles[$i]} not found || exit 1
BUNDLESTRING=${BUNDLESTRING}" -b \"$( readlink -f ${bundles[$i]} )\"" BUNDLESTRING=${BUNDLESTRING}" -b \"$( readlink -f ${bundles[$i]} )\""
RUNNERSTRING=${RUNNERSTRING}"//$ -b \"$( readlink -f ${bundles[$i]} )\" \n"
done done
} }
@@ -26,7 +35,7 @@ listcomps () {
for ((i=0; i<${#bundles[@]}; i++ )) do for ((i=0; i<${#bundles[@]}; i++ )) do
bname=$( cat ${bundles[$i]}/bundle.xml | tr -d -c [:print:] | tr " " _ | sed 's,.*<name>\(.*\)</name>.*,\1,' ) bname=$( cat ${bundles[$i]}/bundle.xml | tr -d -c [:print:] | tr " " _ | sed 's,.*<name>\(.*\)</name>.*,\1,' )
[[ -a ${bundles[$i]}/bundle.xml ]] || echo Bundle ${bundles[$i]} not found || exit 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 done
} }
printcomps () { printcomps () {
@@ -35,6 +44,16 @@ printcomps () {
done done
} }
listdoc () {
if [ -z "$SHORTLIST" ]
then anduril run-component $1 $BUNDLESTRING --doc $LONGLIST
else
anduril run-component $1 $BUNDLESTRING --doc $LONGLIST | grep "^[*=]"
fi
}
bundles=( ) bundles=( )
LONGLIST="" LONGLIST=""
SHORTLIST="" SHORTLIST=""
@@ -43,7 +62,7 @@ while getopts $options option
do do
case $option in case $option in
b ) bundles+=($OPTARG);; b ) bundles+=($OPTARG);;
l ) listcomps; printcomps | sort; exit;; l ) add_autobundles; listcomps; printcomps; exit;;
L ) LONGLIST="-L";; L ) LONGLIST="-L";;
h ) usage; exit;; h ) usage; exit;;
s ) SHORTLIST="yes";; s ) SHORTLIST="yes";;
@@ -53,6 +72,13 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ ! -e "$ANDURIL_HOME/anduril.jar" ]
then echo ANDURIL_HOME/anduril.jar not found!
exit 1
fi
add_autobundles
bundlefunc bundlefunc
if [ -z "$1" ] if [ -z "$1" ]
then usage then usage
@@ -64,8 +90,37 @@ then echo -e "\n\nFile $1.and already exists. Remove it first."
exit exit
fi fi
if [ -z "$SHORTLIST" ] listdoc "$1"
then anduril run-component $1 $BUNDLESTRING --doc $LONGLIST if [ $? -ne 0 ]
else then listcomps
anduril run-component $1 $BUNDLESTRING --doc $LONGLIST | grep "^[*=]" 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 fi