Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI config overrides #126

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions defaults/liftoffrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# company:
# author:
# prefix:
# company_identifier:
############################################################################

configure_git: true
Expand Down
37 changes: 35 additions & 2 deletions lib/liftoff/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ module Liftoff
class CLI
def initialize(argv)
@argv = argv
@options = {}
end

def run
parse_command_line_options
LaunchPad.new.liftoff
LaunchPad.new.liftoff @options
end

private
Expand All @@ -17,7 +18,7 @@ def parse_command_line_options

def global_options
OptionParser.new do |opts|
opts.banner = 'usage: liftoff [-v | --version] [-h | --help]'
opts.banner = 'usage: liftoff [-v | --version] [-h | --help] [config options]'

opts.on('-v', '--version', 'Display the version and exit') do
puts "Version: #{Liftoff::VERSION}"
Expand All @@ -28,6 +29,38 @@ def global_options
puts opts
exit
end

opts.on('--[no-]cocoapods', 'Enable/Disable Cocoapods') do |use_cocoapods|
@options[:use_cocoapods] = use_cocoapods
end

opts.on('--[no-]git', 'Enable/Disable git') do |configure_git|
@options[:configure_git] = configure_git
end

opts.on('-t', '--indentation N', 'Set indentation level') do |indentation_level|
@options[:indentation_level] = indentation_level
end

opts.on('-n', '--name [PROJECT_NAME]', 'Set project name') do |name|
@options[:project_name] = name
end

opts.on('-c', '--company [COMPANY]', 'Set project company') do |company|
@options[:company] = company
end

opts.on('-a', '--author [AUTHOR]', 'Set project author') do |author|
@options[:author] = author
end

opts.on('-p', '--prefix [PREFIX]', 'Set project prefix') do |prefix|
@options[:prefix] = prefix
end

opts.on('-i', '--identifier [IDENTIFIER]', 'Set project company ID (com.example)') do |identifier|
@options[:company_identifier] = identifier
end
end
end
end
Expand Down
11 changes: 8 additions & 3 deletions lib/liftoff/configuration_parser.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
module Liftoff
class ConfigurationParser

def initialize(options)
@options = options
end

def project_configuration
@configuration ||= evaluated_configuration
end

private

def evaluated_configuration
default_configuration.
merge(user_configuration).
merge(local_configuration)
default_configuration
.merge(user_configuration)
.merge(local_configuration)
.merge(@options)
end

def default_configuration
Expand Down
7 changes: 2 additions & 5 deletions lib/liftoff/launchpad.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module Liftoff
class LaunchPad
def initialize
liftoffrc = ConfigurationParser.new.project_configuration
def liftoff(options)
liftoffrc = ConfigurationParser.new(options).project_configuration
@config = ProjectConfiguration.new(liftoffrc)
end

def liftoff
if project_exists?
perform_project_actions
else
Expand Down