Module: Scripting
- Defined in:
- lib/scripting/parser.rb,
lib/scripting/options.rb,
lib/scripting/commands.rb,
lib/scripting/pluggable.rb,
lib/scripting/application.rb,
lib/scripting/app_defaults.rb
Defined Under Namespace
Modules: AppDefaults, Commands, Pluggable Classes: Application, Options
Constant Summary collapse
- Parser =
Scripting::CustomParser(OptionParser)
Class Method Summary collapse
-
.create_application(&blk) ⇒ Object
Creates a new Scripting::Application class instance receiving a block used to describe options, command line switches, and other traits.
-
.CustomParser(klass) ⇒ Object
TODO: flesh this out…
Class Method Details
.create_application(&blk) ⇒ Object
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
do
= "Hello World"
stderr = false
stdout = true
end
switches do
on('--message=TEXT (default: #{options.message})') { |opt| . = opt }
on('--[no]-stderr') { |opt| .stderr = opt }
on('--[no]-stdout') { |opt| .stdout = opt }
end
work do
$stderr.puts . if .stderr?
$stdout.puts . if .stdout?
end
end
105 106 107 108 109 |
# File 'lib/scripting/application.rb', line 105 def self.create_application &blk app = Class.new(Application).new app.describe &blk app end |
.CustomParser(klass) ⇒ Object
TODO: flesh this out… We can, ideally, use any options parser but by default we use optparse.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |