class Geny::DSL
The top-level command file is evaulated in the context of this class.
Public Class Methods
new()
click to toggle source
@private
# File lib/geny/dsl.rb, line 9 def initialize @helpers = [] @invoke = proc { warn "I don't know what to do!" } end
Public Instance Methods
helpers(*modules, &block)
click to toggle source
Define helper methods. These methods are available within the {#invoke} block and all templates.
# File lib/geny/dsl.rb, line 29 def helpers(*modules, &block) @helpers += modules unless modules.empty? @helpers << Module.new(&block) if block_given? @helpers end
invoke(&block)
click to toggle source
Define the behavior for when the command runs. The block is evaluated in the context of a {Context::Invoke}.
# File lib/geny/dsl.rb, line 22 def invoke(&block) @invoke = block if block_given? @invoke end
parse(&block)
click to toggle source
Define arguments and options that the command accepts. The block is evaluated in the context of an {rubydoc.info/github/rzane/argy/Argy/Parser Argy::Parser}.
# File lib/geny/dsl.rb, line 16 def parse(&block) parser.instance_eval(&block) end
parser()
click to toggle source
@private
# File lib/geny/dsl.rb, line 36 def parser @parser ||= Argy.new do |o| o.on "-h", "--help", "show this help and exit" do puts o.help exit end end end