Class: Escort::App
- Inherits:
-
Object
- Object
- Escort::App
- Defined in:
- lib/escort/app.rb
Instance Attribute Summary collapse
-
#option_string ⇒ Object
readonly
Returns the value of attribute option_string.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(option_string, &block) ⇒ App
constructor
A new instance of App.
- #setup_application ⇒ Object
Constructor Details
#initialize(option_string, &block) ⇒ App
Returns a new instance of App.
13 14 15 16 17 |
# File 'lib/escort/app.rb', line 13 def initialize(option_string, &block) @option_string = option_string @setup = nil @block = block end |
Instance Attribute Details
#option_string ⇒ Object (readonly)
Returns the value of attribute option_string.
11 12 13 |
# File 'lib/escort/app.rb', line 11 def option_string @option_string end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
11 12 13 |
# File 'lib/escort/app.rb', line 11 def setup @setup end |
Class Method Details
.create(option_string = '', &block) ⇒ Object
5 6 7 8 |
# File 'lib/escort/app.rb', line 5 def create(option_string = '', &block) self.new(option_string, &block).setup_application.execute exit(0) end |
Instance Method Details
#execute ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/escort/app.rb', line 33 def execute begin AutoOptions.augment(setup) = (option_string) = Escort::GlobalPreParser.new(setup).parse(.dup) Escort::Logger.setup_error_logger() #now we can start doing error logging everything above here has to be rock solid configuration = Escort::Setup::Configuration::Loader.new(setup, ).configuration , arguments = Escort::OptionParser.new(configuration, setup).parse() context = ([:global]) action = setup.action_for(context) current_command = context.empty? ? :global : context.last raise Escort::ClientError.new("No action defined for command '#{current_command}'") unless action actual_arguments = Escort::Arguments.read(arguments, setup.arguments_required_for(context)) rescue => e handle_escort_error(e) end execute_action(action, , actual_arguments, configuration.user) end |
#setup_application ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/escort/app.rb', line 19 def setup_application old_error_sev_threshold = error_logger.sev_threshold begin error_logger.sev_threshold = ::Logger::DEBUG cli_app_configuration = Escort::Setup::Dsl::Global.new(&@block) @setup = Escort::SetupAccessor.new(cli_app_configuration) self rescue => e handle_escort_error(e) ensure error_logger.sev_threshold = old_error_sev_threshold end end |