Class: Consoler::Application
- Inherits:
-
Object
- Object
- Consoler::Application
- Defined in:
- lib/consoler/application.rb
Overview
Consoler application
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Application
constructor
Create a consoler application.
-
#method_missing(command_name, input = nil) {|...| ... } ⇒ nil
Register a command for this app.
-
#run(args = ARGV, disable_usage_message = false) ⇒ mixed
Run the application with a list of arguments.
-
#usage ⇒ Object
Show the usage message.
Constructor Details
#initialize(options = {}) ⇒ Application
Create a consoler application
32 33 34 35 |
# File 'lib/consoler/application.rb', line 32 def initialize(={}) @description = [:description] @commands = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(command_name, input = nil) {|...| ... } ⇒ nil
Register a command for this app
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/consoler/application.rb', line 43 def method_missing(command_name, input = nil, &block) action = nil = '' unless block.nil? then action = block = input if not .nil? and not .instance_of? String then raise 'Invalid options' end end if input.instance_of? Consoler::Application then action = input = '' end if action.nil? then raise 'Invalid subapp/block' end command = command_name.to_s _add_command(command, , action) return nil end |
Instance Method Details
#run(args = ARGV, disable_usage_message = false) ⇒ mixed
Run the application with a list of arguments
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/consoler/application.rb', line 77 def run(args = ARGV, = false) # TODO signal handling of some kind? result, matched = _run(args.dup) if not matched and not usage end return result end |
#usage ⇒ Object
Show the usage message
Contains all commands and options, including subapps
92 93 94 95 96 97 |
# File 'lib/consoler/application.rb', line 92 def usage puts "#{@description}\n\n" unless @description.nil? puts 'Usage:' _commands_usage $0 end |