]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added assert() macro.
authorelijah <elijah@riseup.net>
Mon, 29 Jul 2013 20:39:15 +0000 (13:39 -0700)
committerelijah <elijah@riseup.net>
Mon, 29 Jul 2013 20:39:15 +0000 (13:39 -0700)
if failed, spits out this on compile:

 = FAILED assertion while evaluating node 'worm'
   - assertion: services.include? 'couchdb'
   - offending key: require_couchdb
 = bailing out

lib/leap_cli/config/macros.rb
lib/leap_cli/config/object.rb
lib/leap_cli/version.rb

index f46799cb56d1f8bb19029484200073857c039b26..b5f6a349e6acab2fec8a562529551f9b2e0701f4 100644 (file)
@@ -335,5 +335,27 @@ module LeapCli; module Config
       entries.join("\n")
     end
 
+    ##
+    ## UTILITY
+    ##
+
+    class AssertionFailed < Exception
+      attr_accessor :assertion
+      def initialize(assertion)
+        @assertion = assertion
+      end
+      def to_s
+        @assertion
+      end
+    end
+
+    def assert(assertion)
+      if instance_eval(assertion)
+        true
+      else
+        raise AssertionFailed.new(assertion)
+      end
+    end
+
   end
 end; end
index 00997b1f0d15a5fbc273f4d18da168841194cc73..1d296b3f7dd646caacc1cbe7613105e526ea9bc2 100644 (file)
@@ -282,6 +282,12 @@ module LeapCli
                 Util::log "error message: no file '#{exc}'", :indent => 1
               end
             end
+          rescue AssertionFailed => exc
+            Util.bail! do
+              Util::log :failed, "assertion while evaluating node '#{@node.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 '#{@node.name}'"
index 0e96de694dc9d34659643b92e6f9fffcb3d08151..30a1b5810e4614132a2416b6f4e0e33d0bedd027 100644 (file)
@@ -1,6 +1,6 @@
 module LeapCli
   unless defined?(LeapCli::VERSION)
-    VERSION = '1.1.4'
+    VERSION = '1.2.0'
     COMPATIBLE_PLATFORM_VERSION = '0.2.3'..'1.99'
     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.'