Class: Ame::Help::Terminal
- Inherits:
-
Object
- Object
- Ame::Help::Terminal
- Defined in:
- lib/ame-1.0/help/terminal.rb
Overview
Outputs help requests to a pair of IO objects, defaulting to ‘$stdout` and `$stderr`. An instance of this class is used by default for outputting help requests from Root, but can be overridden by invoking Root.help with another object (such as an instance of this class that’s been constructed with different parameters).
Instance Method Summary collapse
-
#dispatch(method, klass) ⇒ self
Outputs a help request for a Class.dispatch METHOD to KLASS, displaying all options and arguments to the method and listing the possible dispatch methods.
-
#error(method, error) ⇒ Object
Outputs ERROR that occurred while processing METHOD.
- #initialize(output = $stdout, error = $stderr, exit_on_error = true) ⇒ Terminal constructor
-
#method(method) ⇒ self
Outputs a help request for METHOD, displaying all its options and arguments.
-
#version(method, version) ⇒ self
Outputs VERSION information for METHOD.
Constructor Details
#initialize(output = $stdout, error = $stderr, exit_on_error = true) ⇒ Terminal
16 17 18 |
# File 'lib/ame-1.0/help/terminal.rb', line 16 def initialize(output = $stdout, error = $stderr, exit_on_error = true) @output, @error, @exit_on_error = output, error, exit_on_error end |
Instance Method Details
#dispatch(method, klass) ⇒ self
Outputs a help request for a Class.dispatch METHOD to KLASS, displaying all options and arguments to the method and listing the possible dispatch methods.
26 27 28 29 30 31 32 |
# File 'lib/ame-1.0/help/terminal.rb', line 26 def dispatch(method, klass) output(method_s(method).tap{ |result| append_group result, 'Methods', klass.methods.sort_by{ |m| m.name } do |m| m.name end }) end |
#error(method, error) ⇒ Object
Outputs ERROR that occurred while processing METHOD.
55 56 57 58 59 |
# File 'lib/ame-1.0/help/terminal.rb', line 55 def error(method, error) errput '%s: %s' % [method, error] exit 1 if @exit_on_error raise error end |
#method(method) ⇒ self
Outputs a help request for METHOD, displaying all its options and arguments.
38 39 40 |
# File 'lib/ame-1.0/help/terminal.rb', line 38 def method(method) output(method_s(method)) end |
#version(method, version) ⇒ self
Outputs VERSION information for METHOD.
46 47 48 |
# File 'lib/ame-1.0/help/terminal.rb', line 46 def version(method, version) output('%s %s' % [method.name, version]) end |