]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
improved vagrant (support for node-filter, default to running on all local nodes...
authorelijah <elijah@riseup.net>
Tue, 27 Nov 2012 23:01:56 +0000 (15:01 -0800)
committerelijah <elijah@riseup.net>
Tue, 27 Nov 2012 23:01:56 +0000 (15:01 -0800)
lib/leap_cli/commands/vagrant.rb

index 157793e12c651fe52642d87071746159c8be84de..eaf070ffd3205ef2c35af28a25c1523d6540abac 100644 (file)
@@ -4,10 +4,10 @@ require 'fileutils'
 module LeapCli; module Commands
 
   desc "Manage local virtual machines"
-  long_desc "This command provides a convient way to manage Vagrant-based virtual machines. The Vagrantfile is automatically generated in test/Vagrantfile."
+  long_desc "This command provides a convient way to manage Vagrant-based virtual machines. If node-filter argument is missing, the command runs on all local virtual machines. The Vagrantfile is automatically generated in 'test/Vagrantfile'. If you want to run vagrant commands manually, cd to 'test'."
   command :local do |c|
-    c.desc 'Starts up the virtual machine'
-    c.arg_name 'node-name', :optional => false #, :multiple => false
+    c.desc 'Starts up the virtual machine(s)'
+    c.arg_name 'node-filter', :optional => true #, :multiple => false
     c.command :start do |c|
       c.action do |global_options,options,args|
         vagrant_setup
@@ -15,8 +15,8 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Shuts down the virtual machine'
-    c.arg_name 'node-name', :optional => false #, :multiple => false
+    c.desc 'Shuts down the virtual machine(s)'
+    c.arg_name 'node-filter', :optional => true #, :multiple => false
     c.command :stop do |c|
       c.action do |global_options,options,args|
         vagrant_setup
@@ -24,8 +24,8 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Resets virtual machine to a pristine state'
-    c.arg_name 'node-name', :optional => false #, :multiple => false
+    c.desc 'Resets virtual machine(s) to a pristine state'
+    c.arg_name 'node-filter', :optional => true #, :multiple => false
     c.command :reset do |c|
       c.action do |global_options,options,args|
         vagrant_setup
@@ -33,8 +33,8 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Destroys the virtual machine, reclaiming the disk space'
-    c.arg_name 'node-name', :optional => false #, :multiple => false
+    c.desc 'Destroys the virtual machine(s), reclaiming the disk space'
+    c.arg_name 'node-filter', :optional => true #, :multiple => false
     c.command :destroy do |c|
       c.action do |global_options,options,args|
         vagrant_setup
@@ -42,8 +42,8 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Print the status of local virtual machine'
-    c.arg_name 'node-name', :optional => false #, :multiple => false
+    c.desc 'Print the status of local virtual machine(s)'
+    c.arg_name 'node-filter', :optional => true #, :multiple => false
     c.command :status do |c|
       c.action do |global_options,options,args|
         vagrant_setup
@@ -80,12 +80,18 @@ module LeapCli; module Commands
   def vagrant_command(cmds, args)
     cmds = cmds.to_a
     assert_config! 'provider.vagrant.network'
-    nodes = manager.filter(args)[:local => true].field(:name)
+    if args.empty?
+      nodes = [""]
+    else
+      nodes = manager.filter(args)[:local => true].field(:name)
+    end
     if nodes.any?
       vagrant_dir = File.dirname(Path.named_path(:vagrantfile))
       exec = ["cd #{vagrant_dir}"]
       cmds.each do |cmd|
-        exec << "vagrant #{cmd} #{nodes.join(' ')}"
+        nodes.each do |node|
+          exec << "vagrant #{cmd} #{node}"
+        end
       end
       execute exec.join('; ')
     else