Skip to content

Commit

Permalink
Trap interrupt during option input
Browse files Browse the repository at this point in the history
* Extract OptionFetcher
  This class handles fetching the options from the user, and manages the
  various interrupt signals during input

Fixes #81
  • Loading branch information
gfontenot committed Mar 12, 2014
1 parent 25158cd commit 88f55e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/liftoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require 'liftoff/git_setup'
require 'liftoff/launchpad'
require 'liftoff/object_picker'
require 'liftoff/option_fetcher'
require 'liftoff/project'
require 'liftoff/project_builder'
require 'liftoff/project_configuration'
Expand Down
7 changes: 2 additions & 5 deletions lib/liftoff/launchpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def liftoff
private

def fetch_options
@config.project_name = ask('Project name? ') { |q| q.default = @config.project_name }
@config.company = ask('Company name? ') { |q| q.default = @config.company }
@config.author = ask('Author name? ') { |q| q.default = @config.author }
@config.prefix = ask('Prefix? ') { |q| q.default = @config.prefix }.upcase
OptionFetcher.new(@config).fetch_options
end

def perform_project_actions
Expand Down Expand Up @@ -69,7 +66,7 @@ def enable_warnings
def enable_static_analyzer
xcode_helper.enable_static_analyzer(@config.enable_static_analyzer)
end

def open_project
`open -a "Xcode" .`
end
Expand Down
26 changes: 26 additions & 0 deletions lib/liftoff/option_fetcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Liftoff
class OptionFetcher
def initialize(configuration)
@configuration = configuration
end

def fetch_options
fetch_option_for(:project_name, 'Project name')
fetch_option_for(:company, 'Company name')
fetch_option_for(:author, 'Author name')
fetch_option_for(:prefix, 'Prefix')
end

private

def fetch_option_for(attribute, prompt)
value = ask("#{prompt}? ") { |q| q.default = @configuration.public_send(attribute) }
@configuration.public_send("#{attribute}=", value)
rescue EOFError
puts
fetch_option_for(attribute, prompt)
rescue Interrupt
exit 1
end
end
end

0 comments on commit 88f55e4

Please sign in to comment.