lib/timber/cli/installers.rb in timber-2.1.0.rc3 vs lib/timber/cli/installers.rb in timber-2.1.0.rc4
- old
+ new
@@ -7,60 +7,68 @@
module Timber
class CLI
module Installers
def self.run(api_key, io)
- io.puts IO::Messages.header, :green
- io.puts IO::Messages.separator, :green
- io.puts IO::Messages.contact, :green
- io.puts IO::Messages.separator, :green
- io.puts ""
+ api = API.new(api_key)
+ api.event(:started)
- if !api_key
- app_url = IO::Messages::APP_URL
-
- io.puts "Hey there! Welcome to Timber. In order to proceed, you'll need an API key."
- io.puts "You can grab one by registering at #{IO::ANSI.colorize(app_url, :blue)}."
+ begin
+ io.puts IO::Messages.header, :green
+ io.puts IO::Messages.separator, :green
+ io.puts IO::Messages.contact, :green
+ io.puts IO::Messages.separator, :green
io.puts ""
- io.puts "It takes less than a minute, with one click Google and Github registration."
- io.puts ""
- if OSHelper.can_open?
- case io.ask_yes_no("Open #{app_url}?")
- when :yes
- puts ""
- io.task("Opening #{app_url}") do
- OSHelper.open(app_url)
+ if !api_key
+ api.event(:no_api_key)
+
+ app_url = IO::Messages::APP_URL
+
+ io.puts "Hey there! Welcome to Timber. In order to proceed, you'll need an API key."
+ io.puts "You can grab one by registering at #{IO::ANSI.colorize(app_url, :blue)}."
+ io.puts ""
+ io.puts "It takes less than a minute, with one click Google and Github registration."
+ io.puts ""
+
+ if OSHelper.can_open?
+ case io.ask_yes_no("Open #{app_url}?")
+ when :yes
+ puts ""
+ io.task("Opening #{app_url}") do
+ OSHelper.open(app_url)
+ end
+ when :no
+ io.puts ""
+ io.puts "No problem, navigate to the following URL:"
+ io.puts ""
+ io.puts " #{IO::ANSI.colorize(app_url, :blue)}"
end
- when :no
+ else
io.puts ""
- io.puts "No problem, navigate to the following URL:"
+ io.puts "Please navigate to:"
io.puts ""
io.puts " #{IO::ANSI.colorize(app_url, :blue)}"
end
- else
+
io.puts ""
- io.puts "Please navigate to:"
+ io.puts "Once you obtain your API key, you can run the installer like"
io.puts ""
- io.puts " #{IO::ANSI.colorize(app_url, :blue)}"
- end
+ io.puts " #{IO::ANSI.colorize("bundle exec timber my-api-key", :blue)}"
+ io.puts ""
+ io.puts "See you soon! 🎈"
+ io.puts ""
+ else
+ api.event(:api_key_provided)
+ io.api = api
- io.puts ""
- io.puts "Once you obtain your API key, you can run the installer like"
- io.puts ""
- io.puts " #{IO::ANSI.colorize("bundle exec timber my-api-key", :blue)}"
- io.puts ""
- io.puts "See you soon! 🎈"
- io.puts ""
- else
- api = API.new(api_key)
- api.event(:started)
+ app = api.application!
- io.api = api
-
- app = api.application!
-
- Root.new(io, api).run(app)
+ Root.new(io, api).run(app)
+ end
+ rescue Exception => e
+ api.event(:exception, message: e.message, stacktrace: e.backtrace)
+ raise e
end
end
end
end
end
\ No newline at end of file