Class: Mongify::CLI::Application
- Inherits:
-
Object
- Object
- Mongify::CLI::Application
- Defined in:
- lib/mongify/cli/application.rb
Overview
Represents an instance of a Mongify application. This is the entry point for all invocations of Mongify from the command line.
Constant Summary collapse
- STATUS_SUCCESS =
Successful execution exit code
0
- STATUS_ERROR =
Failed execution exit code
1
Instance Method Summary collapse
-
#execute! ⇒ Object
Runs the application.
-
#initialize(arguments = [], stdin = $stdin, stdout = $stdout) ⇒ Application
constructor
A new instance of Application.
-
#output(message) ⇒ Object
Sends output to the UI.
-
#report_error ⇒ Object
Sets status code as failure (or error).
-
#report_success ⇒ Object
Sets status code as successful.
Constructor Details
#initialize(arguments = [], stdin = $stdin, stdout = $stdout) ⇒ Application
Returns a new instance of Application.
16 17 18 19 20 21 22 |
# File 'lib/mongify/cli/application.rb', line 16 def initialize(arguments=[], stdin=$stdin, stdout=$stdout) arguments = ['-h'] if arguments.empty? @options = Options.new(arguments) @status = STATUS_SUCCESS Mongify::Configuration.in_stream = stdin Mongify::Configuration.out_stream = stdout end |
Instance Method Details
#execute! ⇒ Object
Runs the application
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongify/cli/application.rb', line 25 def execute! begin cmd = @options.parse return cmd.execute(self) rescue MongifyError => error $stderr.puts "Error: #{error}" report_error rescue Exception => error report_error raise error end end |
#output(message) ⇒ Object
Sends output to the UI
39 40 41 |
# File 'lib/mongify/cli/application.rb', line 39 def output() UI.puts() end |
#report_error ⇒ Object
Sets status code as failure (or error)
49 50 51 |
# File 'lib/mongify/cli/application.rb', line 49 def report_error @status = STATUS_ERROR end |
#report_success ⇒ Object
Sets status code as successful
44 45 46 |
# File 'lib/mongify/cli/application.rb', line 44 def report_success @status = STATUS_SUCCESS end |