]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
limit `leap db destroy` to FILTER.
authorelijah <elijah@riseup.net>
Tue, 10 Jun 2014 17:53:19 +0000 (10:53 -0700)
committerelijah <elijah@riseup.net>
Tue, 10 Jun 2014 17:53:19 +0000 (10:53 -0700)
lib/leap_cli/commands/db.rb

index e3d6b55905f8b330d8eb287ea9bf29e2a6352071..acc2f13d2e43ffffc3c4312d229d7259155816ba 100644 (file)
@@ -2,14 +2,22 @@ module LeapCli; module Commands
 
   desc 'Database commands.'
   command :db do |db|
-    db.desc 'Destroy all the databases.'
+    db.desc 'Destroy all the databases. If present, limit to FILTER nodes.'
+    db.arg_name 'FILTER', :optional => true
     db.command :destroy do |destroy|
       destroy.action do |global_options,options,args|
         say 'You are about to permanently destroy all database data.'
         return unless agree("Continue? ")
-        nodes = manager.nodes[:services => 'couchdb']
-        ssh_connect(nodes, connect_options(options)) do |ssh|
-          ssh.run('/etc/init.d/bigcouch stop && test ! -z "$(ls /opt/bigcouch/var/lib/ 2> /dev/null)" && rm -r /opt/bigcouch/var/lib/* && echo "db destroyed" || echo "db already destroyed"')
+        nodes = manager.filter(args)
+        if nodes.any?
+          nodes = nodes[:services => 'couchdb']
+        end
+        if nodes.any?
+          ssh_connect(nodes, connect_options(options)) do |ssh|
+            ssh.run('/etc/init.d/bigcouch stop && test ! -z "$(ls /opt/bigcouch/var/lib/ 2> /dev/null)" && rm -r /opt/bigcouch/var/lib/* && echo "db destroyed" || echo "db already destroyed"')
+          end
+        else
+          say 'No nodes'
         end
       end
     end