]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
fixed problems with ruby 1.8 and GLI, and added some tests.
authorelijah <elijah@riseup.net>
Wed, 5 Dec 2012 09:02:39 +0000 (01:02 -0800)
committerelijah <elijah@riseup.net>
Wed, 5 Dec 2012 09:02:39 +0000 (01:02 -0800)
leap_cli.gemspec
lib/leap_cli/commands/ca.rb
lib/leap_cli/commands/node.rb
lib/leap_cli/commands/vagrant.rb
lib/leap_cli/version.rb
lib/lib_ext/gli.rb
test/test_helper.rb
test/unit/command_line_test.rb [new file with mode: 0644]
test/unit/config_object_list_test.rb
test/unit/config_object_test.rb

index 2bd29298fb69362623909728ba9c11b1fbecc124..77d6dd173902e907ebcf23669e25ccc6a1224ee2 100644 (file)
@@ -46,7 +46,7 @@ spec = Gem::Specification.new do |s|
   #s.add_development_dependency('aruba')
 
   # console gems
-  s.add_runtime_dependency('gli','~> 2.3')
+  s.add_runtime_dependency('gli','~> 2.5.0')
   s.add_runtime_dependency('command_line_reporter')
   s.add_runtime_dependency('highline')
   s.add_runtime_dependency('paint')
index f471b5aa416587b8b6607143e9dce41d3318d236..d6fd97589629a7c4f6b6572bef7d5f508762cb0f 100644 (file)
@@ -7,11 +7,11 @@ module LeapCli; module Commands
 
   desc "Manage X.509 certificates"
   #long_desc ""
-  command :cert do |c|
+  command :cert do |cert|
 
-    c.desc 'Creates a Certificate Authority (private key and CA certificate)'
-    c.command :ca do |c|
-      c.action do |global_options,options,args|
+    cert.desc 'Creates a Certificate Authority (private key and CA certificate)'
+    cert.command :ca do |ca|
+      ca.action do |global_options,options,args|
         assert_files_missing! :ca_cert, :ca_key
         assert_config! 'provider.ca.name'
         assert_config! 'provider.ca.bit_size'
@@ -48,10 +48,10 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Creates or renews a X.509 certificate/key pair for a single node or all nodes'
-    c.arg_name 'node-name', :optional => false
-    c.command :update do |c|
-      c.action do |global_options,options,args|
+    cert.desc 'Creates or renews a X.509 certificate/key pair for a single node or all nodes'
+    cert.arg_name 'node-name', :optional => false
+    cert.command :update do |update|
+      update.action do |global_options,options,args|
         assert_files_exist! :ca_cert, :ca_key, :msg => 'Run `leap cert ca` to create them'
         assert_config! 'provider.ca.server_certificates.bit_size'
         assert_config! 'provider.ca.server_certificates.digest'
@@ -70,9 +70,9 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Creates a Diffie-Hellman parameter file' # (needed for server-side of some TLS connections)
-    c.command :dh do |c|
-      c.action do |global_options,options,args|
+    cert.desc 'Creates a Diffie-Hellman parameter file' # (needed for server-side of some TLS connections)
+    cert.command :dh do |dh|
+      dh.action do |global_options,options,args|
         long_running do
           if cmd_exists?('certtool')
             log 0, 'Generating DH parameters (takes a long time)...'
@@ -104,10 +104,10 @@ module LeapCli; module Commands
     # nice details about CSRs:
     #   http://www.redkestrel.co.uk/Articles/CSR.html
     #
-    c.desc 'Creates a CSR for use in buying a commercial X.509 certificate'
-    c.command :csr do |c|
+    cert.desc 'Creates a CSR for use in buying a commercial X.509 certificate'
+    cert.command :csr do |csr|
       #c.switch 'sign', :desc => 'additionally creates a cert that is signed by your own CA (recommended only for testing)', :negatable => false
-      c.action do |global_options,options,args|
+      csr.action do |global_options,options,args|
         assert_config! 'provider.domain'
         assert_config! 'provider.name'
         assert_config! 'provider.default_language'
index aa9610f0aa3cb0922b7e7f1d673ea1c81c4c874d..9bf27e2c43da38cb4bd9c826d63004d80328718d 100644 (file)
@@ -8,19 +8,19 @@ module LeapCli; module Commands
   ##
 
   desc 'Node management'
-  command :node do |c|
-    c.desc 'Create a new configuration file for a node'
-    c.command :add do |c|
-      c.action do |global_options,options,args|
+  command :node do |node|
+    node.desc 'Create a new configuration file for a node'
+    node.command :add do |add|
+      add.action do |global_options,options,args|
         log 'not yet implemented'
       end
     end
 
-    c.desc 'Bootstraps a node, setting up ssh keys and installing prerequisites'
-    c.arg_name 'node-name', :optional => false, :multiple => false
-    c.command :init do |c|
-      c.switch 'echo', :desc => 'if set, passwords are visible as you type them (default is hidden)', :negatable => false
-      c.action do |global_options,options,args|
+    node.desc 'Bootstraps a node, setting up ssh keys and installing prerequisites'
+    node.arg_name 'node-name', :optional => false, :multiple => false
+    node.command :init do |init|
+      init.switch 'echo', :desc => 'if set, passwords are visible as you type them (default is hidden)', :negatable => false
+      init.action do |global_options,options,args|
         node = get_node_from_args(args)
         ping_node(node)
         save_public_host_key(node)
@@ -33,17 +33,17 @@ module LeapCli; module Commands
       end
     end
 
-    c.desc 'Renames a node file, and all its related files'
-    c.command :mv do |c|
-      c.action do |global_options,options,args|
+    node.desc 'Renames a node file, and all its related files'
+    node.command :mv do |mv|
+      mv.action do |global_options,options,args|
         log 'not yet implemented'
       end
     end
 
-    c.desc 'Removes a node file, and all its related files'
-    c.arg_name '<node-name>', :optional => false, :multiple => false
-    c.command :rm do |c|
-      c.action do |global_options,options,args|
+    node.desc 'Removes a node file, and all its related files'
+    node.arg_name '<node-name>', :optional => false, :multiple => false
+    node.command :rm do |rm|
+      rm.action do |global_options,options,args|
         log 'not yet implemented'
       end
     end
index eaf070ffd3205ef2c35af28a25c1523d6540abac..f3c3c3371875a11f6195f6629fb1e7d403553d94 100644 (file)
@@ -5,47 +5,47 @@ module LeapCli; module Commands
 
   desc "Manage local virtual machines"
   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(s)'
-    c.arg_name 'node-filter', :optional => true #, :multiple => false
-    c.command :start do |c|
-      c.action do |global_options,options,args|
+  command :local do |local|
+    local.desc 'Starts up the virtual machine(s)'
+    local.arg_name 'node-filter', :optional => true #, :multiple => false
+    local.command :start do |start|
+      start.action do |global_options,options,args|
         vagrant_setup
         vagrant_command(["up", "sandbox on"], args)
       end
     end
 
-    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|
+    local.desc 'Shuts down the virtual machine(s)'
+    local.arg_name 'node-filter', :optional => true #, :multiple => false
+    local.command :stop do |stop|
+      stop.action do |global_options,options,args|
         vagrant_setup
         vagrant_command("halt", args)
       end
     end
 
-    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|
+    local.desc 'Resets virtual machine(s) to a pristine state'
+    local.arg_name 'node-filter', :optional => true #, :multiple => false
+    local.command :reset do |reset|
+      reset.action do |global_options,options,args|
         vagrant_setup
         vagrant_command("sandbox rollback", args)
       end
     end
 
-    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|
+    local.desc 'Destroys the virtual machine(s), reclaiming the disk space'
+    local.arg_name 'node-filter', :optional => true #, :multiple => false
+    local.command :destroy do |destroy|
+      destroy.action do |global_options,options,args|
         vagrant_setup
         vagrant_command("destroy", args)
       end
     end
 
-    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|
+    local.desc 'Print the status of local virtual machine(s)'
+    local.arg_name 'node-filter', :optional => true #, :multiple => false
+    local.command :status do |status|
+      status.action do |global_options,options,args|
         vagrant_setup
         vagrant_command("status", args)
       end
index 0dbd215208c8d1e6c9a7d334e543dc6ad3232cb6..7851676e223208f73ee447bca14af470190162bf 100644 (file)
@@ -1,6 +1,6 @@
 module LeapCli
   unless defined?(LeapCli::VERSION)
-    VERSION = '0.1.3'
+    VERSION = '0.1.4'
     SUMMARY = 'Command line interface to the LEAP platform'
     DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.'
     REQUIRE_PATHS = ['lib', 'vendor/supply_drop/lib', 'vendor/certificate_authority/lib']
index 32ae0bc0fb17305ae085e4f20ea7681de45831b9..f9b03be140613c128498368a09a6739239deedfd 100644 (file)
@@ -19,10 +19,10 @@ module GLI
 
           # build a list of commands, sort them so the commands with subcommands are at the bottom
           commands = @sorter.call(@app.commands_declaration_order.reject(&:nodoc)).sort do |a,b|
-            if a.commands.any? && b.commands.any?;  a.name <=> b.name
+            if a.commands.any? && b.commands.any?;  a.name.to_s <=> b.name.to_s
             elsif a.commands.any?;                  1
             elsif b.commands.any?;                 -1
-            else;                                   a.name <=> b.name
+            else;                                   a.name.to_s <=> b.name.to_s
             end
           end
 
@@ -33,7 +33,7 @@ module GLI
             command_info_list << [name, command.description]
             if command.commands.any?
               @sorter.call(command.commands_declaration_order).each do |cmd|
-                command_info_list << [SUB_CMD_INDENT + command.name.to_s + " " + cmd.names,cmd.description + (command.get_default_command == cmd.name ? " (default)" : "")]
+                command_info_list << [SUB_CMD_INDENT + command.name.to_s + " " + cmd.names, cmd.description + (command.get_default_command == cmd.name ? " (default)" : "")]
               end
             end
           end
@@ -43,7 +43,7 @@ module GLI
           stringio = StringIO.new
           command_formatter.output(stringio)
           commands = stringio.string
-          global_option_descriptions = OptionsFormatter.new(global_flags_and_switches,@wrapper_class).format
+          global_option_descriptions = OptionsFormatter.new(global_flags_and_switches, @sorter, @wrapper_class).format
           GLOBAL_HELP.result(binding)
         end
       end
index e76108649cc94def1703cb60e24f3e24d592fcf9..94bb2b4be1e567198f3de8d8f27111534b942438 100644 (file)
@@ -4,16 +4,46 @@ require 'minitest/autorun'
 require 'leap_cli'
 
 class MiniTest::Unit::TestCase
+  attr_accessor :ruby_path
 
   # Add global extensions to the test case class here
 
+  def setup
+    LeapCli::Path.set_platform_path(test_platform_path)
+    LeapCli::Path.set_provider_path(test_provider_path)
+  end
+
   def manager
     @manager ||= begin
-      LeapCli::Path.set_root(File.dirname(__FILE__))
       manager = LeapCli::Config::Manager.new
       manager.load
       manager
     end
   end
 
+  def base_path
+    File.expand_path '../..', __FILE__
+  end
+
+  def leap_bin(*args)
+    `#{ruby_path} #{base_path}/bin/leap #{args.join ' '}`
+  end
+
+  def test_platform_path
+    "#{base_path}/test/leap_platform"
+  end
+
+  def test_provider_path
+    "#{base_path}/test/provider"
+  end
+
+  def with_multiple_rubies(&block)
+    ['ruby1.8', 'ruby1.9.1'].each do |ruby|
+      self.ruby_path = `which #{ruby}`.strip
+      next unless ruby_path.chars.any?
+      yield
+    end
+    self.ruby_path = ""
+  end
+
 end
diff --git a/test/unit/command_line_test.rb b/test/unit/command_line_test.rb
new file mode 100644 (file)
index 0000000..ec4c2d6
--- /dev/null
@@ -0,0 +1,12 @@
+require File.expand_path('test_helper', File.dirname(__FILE__))
+
+class CommandLineTest < MiniTest::Unit::TestCase
+
+  def test_help
+    with_multiple_rubies do
+      output = leap_bin('help')
+      assert_equal 0, $?, "help should exit 0 -- #{output}"
+    end
+  end
+
+end
index a3b76f2db5d9891b3cb67a8b890e212d40dfb924..a507094e6d43834942454246e16121ab90eca741 100644 (file)
@@ -1,6 +1,6 @@
 require File.dirname(__FILE__) + '/test_helper'
 
-class TestMeme < MiniTest::Unit::TestCase
+class ConfigObjectListTest < MiniTest::Unit::TestCase
 
   def test_node_search
     nodes = manager.nodes['name' => 'vpn1']
index 0c293c263add22be3e4db5be46f86a1d910d0c47..b981f3b44d235f65a1bb0d71a73c7cfd225829e2 100644 (file)
@@ -1,6 +1,6 @@
 require File.expand_path('test_helper', File.dirname(__FILE__))
 
-class TestMeme < MiniTest::Unit::TestCase
+class ConfigObjectTest < MiniTest::Unit::TestCase
 
   def test_bracket_lookup
     domain = manager.provider.domain