Skip to content

Commit

Permalink
Search by secondary index is now in place
Browse files Browse the repository at this point in the history
  • Loading branch information
katta committed Jan 14, 2014
1 parent 172221d commit 3879c0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
29 changes: 28 additions & 1 deletion riakcli
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ printUsage() {
echo ""
echo " riakcli get object [bucket-name] [key] -> Gets the object associated with a given key in a specified bucket"
echo " riakcli put object [bucket-name] [key] [object-json] -> Creates/Updates an object for a given key in a specified bucket"
echo " riakcli search by_index [bucket-name] [index-name] [index-value]"
echo " -> Searches given value by secondary index in a specified bucket"
echo ""
echo " riakcli delete bucket [bucket-name] -> Deletes all objects in a specified bucket"
echo " riakcli delete object [bucket-name] [key] -> Deletes an object in a given bucket"
Expand Down Expand Up @@ -83,7 +85,7 @@ getObject() {
}

putObject() {
checkForArgs 3 "riakcli put object [bucket-name] [key] [object-json]"$*
checkForArgs 3 "riakcli put object [bucket-name] [key] [object-json]" $*

local BUCKET=$1
local KEY=$2
Expand All @@ -94,6 +96,15 @@ putObject() {
cput ${RIAK_BASE_URL}/riak/${BUCKET}/${KEY} ${OBJECT}
}

searchByIndex() {
checkForArgs 3 "search by_index [bucket-name] [index-name] [index-value]" $*
local BUCKET=$1
local INDEX=$2
local VALUE=$3

crl ${RIAK_BASE_URL}/buckets/${BUCKET}/index/${INDEX}_bin/${VALUE}
}

deleteBucket() {
checkForArgs 1 "riakcli delete bucket [bucket-name]" $*
local BUCKET=$1
Expand Down Expand Up @@ -151,6 +162,18 @@ get() {
esac
}

search() {
case "$1" in
"by_index" )
shift
searchByIndex $*
;;
* )
printInvalidUsage
;;
esac
}

put() {
case "$1" in
"object" )
Expand Down Expand Up @@ -209,6 +232,10 @@ __init__() {
shift
get $*
;;
"search" )
shift
search $*
;;
"list" )
shift
list $*
Expand Down
13 changes: 9 additions & 4 deletions riakcli_bashcompletion
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _riakcli() {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

opts="list get put delete flush ping help"
opts="list search get put delete flush ping help"

case "${prev}" in
list)
Expand All @@ -18,14 +18,19 @@ _riakcli() {
return 0
;;
delete)
local list_opts="bucket object"
COMPREPLY=( $(compgen -W "${list_opts}" -- ${cur}) )
local delete_opts="bucket object"
COMPREPLY=( $(compgen -W "${delete_opts}" -- ${cur}) )
return 0
;;
flush | ping | help)
return 0
;;
object | keys | bucket)
search )
local search_opts="by_index"
COMPREPLY=( $(compgen -W "${search_opts}" -- ${cur}) )
return 0
;;
object | keys | bucket | by_index )
local bucket_opts=`riakcli list buckets | cut -d ':' -f2 | sed -e 's/^.*\[//g' -e 's/"//g' -e 's/\]\}//g' -e 's/,/ /g'`
COMPREPLY=( $(compgen -W "${bucket_opts}" -- ${cur}) )
return 0
Expand Down

0 comments on commit 3879c0a

Please # to comment.