Class: Askcii::Application
- Inherits:
-
Object
- Object
- Askcii::Application
- Defined in:
- lib/askcii/application.rb
Overview
Main application controller that routes to appropriate commands
Instance Attribute Summary collapse
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
Instance Method Summary collapse
-
#initialize(args = ARGV.dup) ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
Constructor Details
#initialize(args = ARGV.dup) ⇒ Application
18 19 20 |
# File 'lib/askcii/application.rb', line 18 def initialize(args = ARGV.dup) @cli = CLI.new(args) end |
Instance Attribute Details
#cli ⇒ Object (readonly)
Returns the value of attribute cli.
16 17 18 |
# File 'lib/askcii/application.rb', line 16 def cli @cli end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/askcii/application.rb', line 22 def run @cli.parse! # Handle usage display if @cli.show_usage? puts Commands::HelpCommand.new(@cli).execute exit 1 end # Determine and execute the appropriate command command = determine_command command.execute rescue ConfigurationError => e $stderr.puts "Configuration Error: #{e.message}" $stderr.puts "Run 'askcii -c' to configure providers." exit 1 rescue ValidationError => e $stderr.puts "Validation Error: #{e.message}" exit 1 rescue SessionError => e $stderr.puts "Session Error: #{e.message}" exit 1 rescue => e $stderr.puts "Error: #{e.message}" $stderr.puts e.backtrace.join("\n") if @cli.verbose? exit 1 end |