lib/sickle.rb in sickle-0.5.2 vs lib/sickle.rb in sickle-0.5.3
- old
+ new
@@ -188,10 +188,14 @@
name = (Sickle.namespace + [name]).join(":")
base.__commands[name] = command
end
end
+ def before(&block)
+ @__before_hook = block
+ end
+
def desc(label)
Sickle.push_desc(label)
end
def global_option(name, opts = {})
@@ -250,9 +254,14 @@
# puts "results: #{results.inspect}"
obj = self.new
obj.instance_variable_set(:@__options, results)
+
+ if @__before_hook
+ obj.instance_exec(&@__before_hook)
+ end
+
command.meth.bind(obj).call(*args)
else
puts "\e[31mCommand '#{command_name}' not found\e[0m"
puts
run(["help"])