cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [1/3] git commit: Add tab-completion to debian nodetool packaging patch by Cyril Scetbon; reviewed by mshuler for CASSANDRA-6421
Date Wed, 21 May 2014 22:23:46 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 a3effe669 -> 0fdf2ddbf
  refs/heads/trunk c6eaffc2a -> 0afad2c1d


Add tab-completion to debian nodetool packaging
patch by Cyril Scetbon; reviewed by mshuler for CASSANDRA-6421


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/0fdf2ddb
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/0fdf2ddb
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/0fdf2ddb

Branch: refs/heads/cassandra-2.1
Commit: 0fdf2ddbf0cc579398c78a75910b84e9d8be06ab
Parents: a3effe6
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Wed May 21 17:23:33 2014 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Wed May 21 17:23:33 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                      |   1 +
 debian/cassandra.bash-completion |   1 +
 debian/nodetool-completion       | 224 ++++++++++++++++++++++++++++++++++
 debian/rules                     |   1 +
 4 files changed, 227 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/0fdf2ddb/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e2ca9b5..d38fe5d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.0-rc1
+ * Add tab-completion to debian nodetool packaging (CASSANDRA-6421)
  * Change concurrent_compactors defaults (CASSANDRA-7139)
  * Add PowerShell Windows launch scripts (CASSANDRA-7001)
  * Make commitlog archive+restore more robust (CASSANDRA-6974)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0fdf2ddb/debian/cassandra.bash-completion
----------------------------------------------------------------------
diff --git a/debian/cassandra.bash-completion b/debian/cassandra.bash-completion
new file mode 100644
index 0000000..4847889
--- /dev/null
+++ b/debian/cassandra.bash-completion
@@ -0,0 +1 @@
+debian/nodetool-completion nodetool

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0fdf2ddb/debian/nodetool-completion
----------------------------------------------------------------------
diff --git a/debian/nodetool-completion b/debian/nodetool-completion
new file mode 100644
index 0000000..7dc35de
--- /dev/null
+++ b/debian/nodetool-completion
@@ -0,0 +1,224 @@
+have nodetool && have cqlsh &&
+{
+
+    show_keyspaces()
+    {
+        local ks=$(get_keyspaces)
+        COMPREPLY=( $(compgen -W "$ks" -- "$1") )
+    }
+
+    get_keyspaces()
+    {
+        [ -z "$keyspaces" ] && keyspaces=$(echo "DESCRIBE KEYSPACES" | cqlsh | egrep
-v '^$')
+        echo $keyspaces
+    }
+
+    show_datacenters()
+    {
+        cur=$1
+        set|grep -q ^dcs || dcs=$(echo "select data_center from system.peers;"|cqlsh |tail
-n +4|sort|uniq|awk '{if(length($1)>1) print $1}'|xargs)
+        COMPREPLY=( $(compgen -W "$dcs" -- "$cur") )
+    }
+
+    show_cfs()
+    {
+        local cur prev cfs
+        prev=$1
+        cur=$2
+        cfs=$(get_cfs $1 $2)
+        COMPREPLY=( $(compgen -W "$cfs" -- "$cur") )
+    }
+
+    get_cfs()
+    {
+        local prev
+        prev=$1
+        [ -z "${cf[$prev]}" ] && cf[$prev]=$(echo "DESCRIBE COLUMNFAMILIES" | cqlsh
-k ${prev} | egrep -v '^$')
+        echo ${cf[$prev]}
+    }
+
+    show_last_cfs()
+    {
+        local cur cfs re
+        cur=$1
+        re=$(echo ${COMP_WORDS[@]:3:$(($COMP_CWORD - 3))} | sed -e 's/ /\\|/g')
+        cfs=$(get_cfs ${COMP_WORDS[2]} | sed -e "s/$re//g")
+        COMPREPLY=( $(compgen -W "$cfs" -- "${cur}") )
+    }
+
+    _nodetool()
+    {
+        local cur prev ks
+        COMPREPLY=()
+        _get_comp_words_by_ref cur prev
+
+        local shopt='
+            cfstats
+            compactionstats
+            compactionhistory
+            decommission
+            describecluster
+            disablebackup
+            disablebinary
+            disablegossip
+            disablehandoff
+            disablethrift
+            drain
+            enablebackup
+            enablebinary
+            enablegossip
+            enablehandoff
+            enablethrift
+            getcompactionthroughput
+            getlogginglevels
+            getstreamthroughput
+            gossipinfo
+            help
+            invalidatecountercache
+            invalidatekeycache
+            invalidaterowcache
+            join
+            listsnapshots
+            pausehandoff
+            proxyhistograms
+            rangekeysample
+            reloadtriggers
+            resetlocalschema
+            resumehandoff
+            ring
+            setlogginglevel
+            status
+            statusbinary
+            statusthrift
+            stopdaemon
+            tpstats
+            version
+            '
+
+        local lngopt='
+            cfhistograms
+            cleanup
+            clearsnapshot
+            compact
+            describering
+            disableautocompaction
+            enableautocompaction
+            flush
+            getcompactionthreshold
+            getendpoints
+            getsstables
+            info
+            move
+            netstats
+            rebuild
+            rebuild_index
+            refresh
+            removenode
+            repair
+            scrub
+            setcachecapacity
+            setcachekeystosave
+            setcompactionthreshold
+            setcompactionthroughput
+            setstreamthroughput
+            settraceprobability
+            snapshot
+            stop
+            taketoken
+            truncatehints
+            upgradesstables
+            '
+
+        local optwks='
+            cfhistograms
+            cleanup
+            clearsnapshot
+            compact
+            describering
+            flush
+            getcompactionthreshold
+            getendpoints
+            getsstables
+            rebuild_index
+            refresh
+            repair
+            scrub
+            setcompactionthreshold
+            snapshot
+            '
+
+        local optwcfs='
+            cleanup
+            compact
+            disableautocompaction
+            enableautocompaction
+            flush
+            repair
+            scrub
+            upgradesstables
+            '
+
+        if [[ $COMP_CWORD -eq 1 ]] ; then
+            COMPREPLY=( $(compgen -W "${lngopt} ${shopt}" -- "${cur}") )
+        elif [[ $(echo "${lngopt}"|egrep -c "\b${prev}\b") -gt 0 ]] ; then
+            if echo $optwks|grep -q "\b$prev\b" ; then
+                show_keyspaces "${cur}"
+            else
+                case "${prev}" in
+                    removenode)
+                        # we don't want to lose time using nodetool status a 2nd time
+                        # in case of force or status
+                        if [[ "${cur}" =~ ^(f|s) ]] ; then
+                            COMPREPLY=( $(compgen -W "status force" -- "${cur}") )
+                        else
+                            [ -z "$IDS" ] && IDS=$(nodetool status|grep %|awk '{print
$7}'|xargs)
+                            COMPREPLY=( $(compgen -W "status force $IDS" -- "${cur}") )
+                        fi
+                        return 0
+                        ;;
+                    stop)
+                        COMPREPLY=( $(compgen -W "COMPACTION VALIDATION CLEANUP SCRUB INDEX_BUILD"
-- "${cur}") )
+                        return 0
+                        ;;
+                    info)
+                        COMPREPLY=( $(compgen -W "-T --tokens" -- "${cur}") )
+                        return 0
+                        ;;
+                    rebuild)
+                        show_datacenters "${cur}"
+                        return 0
+                        ;;
+                    upgradesstables)
+                        ks=$(get_keyspaces)
+                        COMPREPLY=( $(compgen -W "-a --include-all-sstables $ks" -- "${cur}")
)
+                        return 0
+                        ;;
+                esac
+            fi
+        elif [[ $COMP_CWORD -eq 3 ]] ; then
+            case "${COMP_WORDS[1]}" in
+                cfhistograms|cleanup|compact|flush|getcompactionthreshold|getendpoints|getsstables|rebuild_index|refresh|repair|scrub|setcompactionthreshold)
+                    show_cfs ${prev} ${cur}
+                    return 0
+                    ;;
+                upgradesstables)
+                    if [[ ! ${prev} == -* ]]; then
+                        show_cfs ${prev} ${cur}
+                    fi
+                    return 0
+                    ;;
+                snapshot)
+                    COMPREPLY=( $(compgen -W "-cf" -- "${cur}") )
+                    return 0
+                    ;;
+            esac
+        elif [[ "${optwcfs}" == *${COMP_WORDS[1]}* ]] ; then
+            show_last_cfs ${cur}
+        elif [[ $COMP_CWORD -eq 4 && ${COMP_WORDS[1]} == "snapshot" ]] ; then
+            show_cfs ${COMP_WORDS[2]} ${cur}
+        elif [[ $COMP_CWORD -eq 5 && ${COMP_WORDS[1]} == "snapshot" ]] ; then
+            COMPREPLY=( $(compgen -W "-t" -- "${cur}") )
+        fi
+    }
+    complete -F _nodetool nodetool
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0fdf2ddb/debian/rules
----------------------------------------------------------------------
diff --git a/debian/rules b/debian/rules
index f9dfc21..717bbf2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -63,6 +63,7 @@ binary-indep: build install
 	dh_installchangelogs
 	dh_installinit -u'start 50 2 3 4 5 . stop 50 0 1 6 .'
 	dh_installdocs README.asc CHANGES.txt NEWS.txt
+	dh_bash-completion
 	dh_compress
 	dh_fixperms
 	dh_installdeb


Mime
View raw message