module Scripting
Constants
- Parser
Public Class Methods
CustomParser(klass)
click to toggle source
TODO: flesh this out… We can, ideally, use any options parser but by default we use optparse.
Calls superclass method
# File lib/scripting/parser.rb, line 7 def self.CustomParser(klass) custom = Class.new(DelegateClass(klass)) custom.class_eval do extend Forwardable def_delegators :@context, :context, :options def describe; instance_eval; end end custom.send(:define_method, :initialize) do |context| @context = context super(klass.new) end custom end
create_application(&blk)
click to toggle source
Creates a new Scripting::Application
class instance receiving a block used to describe options, command line switches, and other traits.
my_app = Scripting::create_application do plugin Scripting::AppDefaults options do message = "Hello World" stderr = false stdout = true end switches do on('--message=TEXT (default: #{options.message})') { |opt| options.message = opt } on('--[no]-stderr') { |opt| options.stderr = opt } on('--[no]-stdout') { |opt| options.stdout = opt } end work do $stderr.puts options.message if options.stderr? $stdout.puts options.message if options.stdout? end end
# File lib/scripting/application.rb, line 105 def self.create_application &blk app = Class.new(Application).new app.describe &blk app end
Public Instance Methods
describe()
click to toggle source
# File lib/scripting/parser.rb, line 12 def describe; instance_eval; end