From e4ea1981e3652e466267967354f04504ff089c64 Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Wed, 21 Jan 2015 22:49:42 -0300 Subject: [PATCH 1/4] Allow the user to specify a path from the CLI (#77) The CLI command now optionally takes a path to use as destination for the project. If now path is given by the user, the default of the project name is used. --- lib/liftoff/cli.rb | 4 ++-- lib/liftoff/launchpad.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index 35e088e..0cb1306 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -7,7 +7,7 @@ def initialize(argv) def run parse_command_line_options - LaunchPad.new.liftoff @options + LaunchPad.new.liftoff @options, @argv.first end private @@ -18,7 +18,7 @@ def parse_command_line_options def global_options OptionParser.new do |opts| - opts.banner = 'usage: liftoff [-v | --version] [-h | --help] [config options]' + opts.banner = 'usage: liftoff [-v | --version] [-h | --help] [config options] [path]' opts.on('-v', '--version', 'Display the version and exit') do puts "Version: #{Liftoff::VERSION}" diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index d6370eb..d969c66 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -2,7 +2,7 @@ module Liftoff class LaunchPad EX_NOINPUT = 66 - def liftoff(options) + def liftoff(options, path) liftoffrc = ConfigurationParser.new(options).project_configuration @config = ProjectConfiguration.new(liftoffrc) if project_exists? @@ -11,7 +11,7 @@ def liftoff(options) validate_template fetch_options - file_manager.create_project_dir(@config.project_name) do + file_manager.create_project_dir(path ? path : @config.project_name) do generate_project setup_cocoapods generate_templates From 5673abe0ccd1cf71632bb747c9a634fd8ca7f1d6 Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Wed, 4 Feb 2015 15:37:28 -0300 Subject: [PATCH 2/4] Move path to property and test it --- lib/liftoff/launchpad.rb | 4 ++-- lib/liftoff/project_configuration.rb | 9 +++++++-- spec/project_configuration_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index d969c66..c26b3c2 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -4,14 +4,14 @@ class LaunchPad def liftoff(options, path) liftoffrc = ConfigurationParser.new(options).project_configuration - @config = ProjectConfiguration.new(liftoffrc) + @config = ProjectConfiguration.new(liftoffrc, path) if project_exists? perform_project_actions else validate_template fetch_options - file_manager.create_project_dir(path ? path : @config.project_name) do + file_manager.create_project_dir(@config.path) do generate_project setup_cocoapods generate_templates diff --git a/lib/liftoff/project_configuration.rb b/lib/liftoff/project_configuration.rb index ee4f11c..5fbd9c0 100644 --- a/lib/liftoff/project_configuration.rb +++ b/lib/liftoff/project_configuration.rb @@ -23,9 +23,11 @@ class ProjectConfiguration attr_writer :author, :company_identifier, - :use_tabs + :use_tabs, + :path - def initialize(liftoffrc) + def initialize(liftoffrc, path = nil) + @path = path deprecations = DeprecationManager.new liftoffrc.each_pair do |attribute, value| if respond_to?("#{attribute}=") @@ -74,6 +76,9 @@ def test_target_groups @test_target_templates[@project_template] end + def path + @path || project_name + end private def normalized_company_name diff --git a/spec/project_configuration_spec.rb b/spec/project_configuration_spec.rb index e905b49..75d3c94 100644 --- a/spec/project_configuration_spec.rb +++ b/spec/project_configuration_spec.rb @@ -109,6 +109,28 @@ end end + describe '#path' do + context 'when the path is not given in the constructor' do + it 'return the project name' do + config = Liftoff::ProjectConfiguration.new({ + :project_name => 'My Cool Project' + }) + + expect(config.path).to eq 'My Cool Project' + end + + end + + context 'when the path is given by constructor' do + it 'return the given path' do + config = Liftoff::ProjectConfiguration.new({}, 'Another Path') + + expect(config.path).to eq 'Another Path' + end + end + + end + def build_config(name) app_templates = build_templates('app') test_templates = build_templates('test') From 11b874946fecc3fa8ce451a3e81f404f59396a46 Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Wed, 4 Feb 2015 16:14:59 -0300 Subject: [PATCH 3/4] Make logic a bit less awkward --- lib/liftoff/cli.rb | 3 ++- lib/liftoff/launchpad.rb | 4 ++-- lib/liftoff/project_configuration.rb | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index 0cb1306..f9dee62 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -7,13 +7,14 @@ def initialize(argv) def run parse_command_line_options - LaunchPad.new.liftoff @options, @argv.first + LaunchPad.new.liftoff @options end private def parse_command_line_options global_options.parse!(@argv) + @options[:path] = @argv.first end def global_options diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index c26b3c2..b0cd68f 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -2,9 +2,9 @@ module Liftoff class LaunchPad EX_NOINPUT = 66 - def liftoff(options, path) + def liftoff(options) liftoffrc = ConfigurationParser.new(options).project_configuration - @config = ProjectConfiguration.new(liftoffrc, path) + @config = ProjectConfiguration.new(liftoffrc) if project_exists? perform_project_actions else diff --git a/lib/liftoff/project_configuration.rb b/lib/liftoff/project_configuration.rb index 5fbd9c0..c4d9b06 100644 --- a/lib/liftoff/project_configuration.rb +++ b/lib/liftoff/project_configuration.rb @@ -26,8 +26,7 @@ class ProjectConfiguration :use_tabs, :path - def initialize(liftoffrc, path = nil) - @path = path + def initialize(liftoffrc) deprecations = DeprecationManager.new liftoffrc.each_pair do |attribute, value| if respond_to?("#{attribute}=") From d1da9c0542cedd22cad53dade2066f0bdf702f3e Mon Sep 17 00:00:00 2001 From: Juan Pablo Civile Date: Mon, 9 Feb 2015 14:42:23 -0300 Subject: [PATCH 4/4] Fix test, forgot to run it after refactor --- spec/project_configuration_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/project_configuration_spec.rb b/spec/project_configuration_spec.rb index 75d3c94..5e28981 100644 --- a/spec/project_configuration_spec.rb +++ b/spec/project_configuration_spec.rb @@ -111,7 +111,7 @@ describe '#path' do context 'when the path is not given in the constructor' do - it 'return the project name' do + it 'returns the project name' do config = Liftoff::ProjectConfiguration.new({ :project_name => 'My Cool Project' }) @@ -121,9 +121,11 @@ end - context 'when the path is given by constructor' do - it 'return the given path' do - config = Liftoff::ProjectConfiguration.new({}, 'Another Path') + context 'when the path is given in the constructor' do + it 'returns the given path' do + config = Liftoff::ProjectConfiguration.new({ + :path => 'Another Path' + }) expect(config.path).to eq 'Another Path' end