]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
leap list improvements: lazy evaluation; don't bomb on ConfigError; remove requiremen...
authorelijah <elijah@riseup.net>
Sat, 28 Jun 2014 00:19:51 +0000 (17:19 -0700)
committerelijah <elijah@riseup.net>
Sat, 28 Jun 2014 00:19:51 +0000 (17:19 -0700)
Rakefile
bin/leap
lib/leap_cli.rb
lib/leap_cli/commands/list.rb
lib/leap_cli/commands/pre.rb
lib/leap_cli/config/manager.rb
lib/leap_cli/config/object.rb
lib/leap_cli/exceptions.rb
lib/leap_cli/requirements.rb [deleted file]

index 2cc2c795ecdc3b156aae468e9cf0e2a67a4bea64..deb953964edea2eed9acfca1d2ca951288d437e3 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -86,33 +86,6 @@ Rake::TestTask.new do |t|
 end
 task :default => :test
 
-##
-## CODE GENERATION
-##
-
-desc "Updates the list of required configuration options for this version of LEAP CLI"
-task 'update-requirements' do
-  Dir.chdir($base_dir) do
-    required_configs = `find -name '*.rb' | xargs grep -R 'assert_config!'`.split("\n").collect{|line|
-      if line =~ /def/ || line =~ /pre\.rb/
-        nil
-      else
-        line.sub(/.*assert_config! ["'](.*?)["'].*/,'"\1"')
-      end
-    }.compact
-    File.open("#{$base_dir}/lib/leap_cli/requirements.rb", 'w') do |f|
-      f.puts "# run 'rake update-requirements' to generate this file."
-      f.puts "module LeapCli"
-      f.puts "  REQUIREMENTS = ["
-      f.puts "    " + required_configs.join(",\n    ")
-      f.puts "  ]"
-      f.puts "end"
-    end
-    puts "updated #{$base_dir}/lib/leap_cli/requirements.rb"
-    #puts `cat '#{$base_dir}/lib/leap_cli/requirements.rb'`
-  end
-end
-
 ##
 ## DOCUMENTATION
 ##
index 75c14c72ce0eedd8b3723971b07e6ebd0ebc19e3..c4921276449569425d5b423150c8f259142fc392 100755 (executable)
--- a/bin/leap
+++ b/bin/leap
@@ -78,9 +78,26 @@ module LeapCli::Commands
     exit(0)
   end
 
+  # disable GLI error catching
+  ENV['GLI_DEBUG'] = "true"
+  def error_message(msg)
+  end
+
   # load commands and run
   commands_from('leap_cli/commands')
   ORIGINAL_ARGV = ARGV.dup
-  exit_status = run(ARGV)
-  exit(LeapCli::Util.exit_status || exit_status)
+  begin
+    exit_status = run(ARGV)
+    exit(LeapCli::Util.exit_status || exit_status)
+  rescue StandardError => exc
+    if LeapCli.log_level < 2
+      if exc.respond_to? :log
+        exc.log
+      else
+        puts "%s: %s" % [exc.class, exc.message]
+      end
+    else
+      raise exc
+    end
+  end
 end
index 18a15a172048b9b1d103fc87e639b3ab194ee1b8..aa176550ed96839ec50e50790c015000c0aa58d0 100644 (file)
@@ -9,7 +9,6 @@ require 'leap/platform'
 
 require 'leap_cli/version'
 require 'leap_cli/constants'
-require 'leap_cli/requirements'
 require 'leap_cli/exceptions'
 
 require 'leap_cli/leapfile'
index 5b84113d08e86543dc7ba73a22d027e1601d7210..be9163b23c42266744f99451315af79258b083f8 100644 (file)
@@ -15,15 +15,15 @@ module LeapCli; module Commands
     c.flag 'print', :desc => 'What attributes to print (optional)'
     c.switch 'disabled', :desc => 'Include disabled nodes in the list.', :negatable => false
     c.action do |global_options,options,args|
+      # don't rely on default manager(), because we want to pass custom options to load()
+      manager = LeapCli::Config::Manager.new
       if global_options[:color]
         colors = ['cyan', 'white']
       else
         colors = [nil, nil]
       end
       puts
-      if options['disabled']
-        manager.load(:include_disabled => true) # reload, with disabled nodes
-      end
+      manager.load(:include_disabled => options['disabled'], :continue_on_error => true)
       if options['print']
         print_node_properties(manager.filter(args), options['print'])
       else
@@ -45,7 +45,6 @@ module LeapCli; module Commands
     properties = properties.split(',')
     max_width = nodes.keys.inject(0) {|max,i| [i.size,max].max}
     nodes.each_node do |node|
-      node.evaluate
       value = properties.collect{|prop|
         if node[prop].nil?
           "null"
@@ -68,7 +67,7 @@ module LeapCli; module Commands
       @colors = colors
     end
     def run
-      tags = @tag_list.keys.sort
+      tags = @tag_list.keys.select{|tag| tag !~ /^_/}.sort # sorted list of tags, excluding _partials
       max_width = [20, (tags+[@heading]).inject(0) {|max,i| [i.size,max].max}].max
       table :border => false do
         row :color => @colors[0]  do
index 4b62b5be4a9ade2159ab4c2c8bfa23c3160f5c86..835eada9a7d4a0cd7a316f4b232e19864cb03663 100644 (file)
@@ -32,11 +32,6 @@ module LeapCli; module Commands
     # set verbosity
     #
     LeapCli.log_level = global[:verbose].to_i
-    if LeapCli.log_level > 1
-      ENV['GLI_DEBUG'] = "true"
-    else
-      ENV['GLI_DEBUG'] = "false"
-    end
 
     #
     # load Leapfile
@@ -68,18 +63,7 @@ module LeapCli; module Commands
     log_version
     LeapCli.log_in_color = global[:color]
 
-    #
-    # load all the nodes everything
-    #
-    manager
-
-    #
-    # check requirements
-    #
-    REQUIREMENTS.each do |key|
-      assert_config! key
-    end
-
+    true
   end
 
   private
index 1831de7caf3242a5adb5db597ecd9849208b7985..21dafd161fcce55c4f7c884f9d56d3e5010af431 100644 (file)
@@ -131,7 +131,15 @@ module LeapCli
         # apply control files
         @nodes.each do |name, node|
           control_files(node).each do |file|
-            node.instance_eval File.read(file), file, 1
+            begin
+              node.eval_file file
+            rescue ConfigError => exc
+              if options[:continue_on_error]
+                exc.log
+              else
+                raise exc
+              end
+            end
           end
         end
       end
index ef66757ceabce92fce8113364966028c8171d872..cfa07cbcb45685764d5b3704b56a717a77f5eb00 100644 (file)
@@ -202,6 +202,10 @@ module LeapCli
         end
       end
 
+      def eval_file(filename)
+        evaluate_ruby(filename, File.read(filename))
+      end
+
       protected
 
       #
@@ -242,45 +246,42 @@ module LeapCli
       # (`key` is just passed for debugging purposes)
       #
       def evaluate_ruby(key, value)
-        result = nil
-        if LeapCli.log_level >= 2
-          result = self.instance_eval(value)
-        else
-          begin
-            result = self.instance_eval(value)
-          rescue SystemStackError => exc
-            Util::log 0, :error, "while evaluating node '#{self.name}'"
-            Util::log 0, "offending key: #{key}", :indent => 1
-            Util::log 0, "offending string: #{value}", :indent => 1
-            Util::log 0, "STACK OVERFLOW, BAILING OUT. There must be an eval loop of death (variables with circular dependencies).", :indent => 1
-            raise SystemExit.new(1)
-          rescue FileMissing => exc
-            Util::bail! do
-              if exc.options[:missing]
-                Util::log :missing, exc.options[:missing].gsub('$node', self.name).gsub('$file', exc.path)
-              else
-                Util::log :error, "while evaluating node '#{self.name}'"
-                Util::log "offending key: #{key}", :indent => 1
-                Util::log "offending string: #{value}", :indent => 1
-                Util::log "error message: no file '#{exc}'", :indent => 1
-              end
-            end
-          rescue AssertionFailed => exc
-            Util.bail! do
-              Util::log :failed, "assertion while evaluating node '#{self.name}'"
-              Util::log 'assertion: %s' % exc.assertion, :indent => 1
-              Util::log "offending key: #{key}", :indent => 1
-            end
-          rescue SyntaxError, StandardError => exc
-            Util::bail! do
-              Util::log :error, "while evaluating node '#{self.name}'"
-              Util::log "offending key: #{key}", :indent => 1
-              Util::log "offending string: #{value}", :indent => 1
-              Util::log "error message: #{exc.inspect}", :indent => 1
-            end
+        self.instance_eval(value, key, 1)
+      rescue ConfigError => exc
+        raise exc # pass through
+      rescue SystemStackError => exc
+        Util::log 0, :error, "while evaluating node '#{self.name}'"
+        Util::log 0, "offending key: #{key}", :indent => 1
+        Util::log 0, "offending string: #{value}", :indent => 1
+        Util::log 0, "STACK OVERFLOW, BAILING OUT. There must be an eval loop of death (variables with circular dependencies).", :indent => 1
+        raise SystemExit.new(1)
+      rescue FileMissing => exc
+        Util::bail! do
+          if exc.options[:missing]
+            Util::log :missing, exc.options[:missing].gsub('$node', self.name).gsub('$file', exc.path)
+          else
+            Util::log :error, "while evaluating node '#{self.name}'"
+            Util::log "offending key: #{key}", :indent => 1
+            Util::log "offending string: #{value}", :indent => 1
+            Util::log "error message: no file '#{exc}'", :indent => 1
           end
+          raise exc if LeapCli.log_level >= 2
+        end
+      rescue AssertionFailed => exc
+        Util.bail! do
+          Util::log :failed, "assertion while evaluating node '#{self.name}'"
+          Util::log 'assertion: %s' % exc.assertion, :indent => 1
+          Util::log "offending key: #{key}", :indent => 1
+          raise exc if LeapCli.log_level >= 2
+        end
+      rescue SyntaxError, StandardError => exc
+        Util::bail! do
+          Util::log :error, "while evaluating node '#{self.name}'"
+          Util::log "offending key: #{key}", :indent => 1
+          Util::log "offending string: #{value}", :indent => 1
+          Util::log "error message: #{exc.inspect}", :indent => 1
+          raise exc if LeapCli.log_level >= 2
         end
-        return result
       end
 
       private
index 27993c2087814a89e83980f118d678246d968dd0..24a0fa75c949ebfae935a290b34c21e7690dc2c7 100644 (file)
@@ -6,6 +6,9 @@ module LeapCli
       @node = node
       super(msg)
     end
+    def log
+      Util.log(0, :error, "in node `#{@node.name}`: " + self.message)
+    end
   end
 
   class FileMissing < StandardError
diff --git a/lib/leap_cli/requirements.rb b/lib/leap_cli/requirements.rb
deleted file mode 100644 (file)
index f1f0952..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# run 'rake update-requirements' to generate this file.
-module LeapCli
-  REQUIREMENTS = [
-    "provider.ca.name",
-    "provider.ca.server_certificates.bit_size",
-    "provider.ca.server_certificates.digest",
-    "provider.ca.server_certificates.life_span",
-    "common.x509.use",
-    "provider.domain",
-    "provider.name",
-    "provider.ca.server_certificates.bit_size",
-    "provider.ca.server_certificates.digest",
-    "provider.ca.name",
-    "provider.ca.bit_size",
-    "provider.ca.life_span",
-    "provider.ca.client_certificates.unlimited_prefix",
-    "provider.ca.client_certificates.limited_prefix"
-  ]
-end