From 9818d2aca0cca373bb73300f2f6a65efbd910dc2 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Wed, 19 Mar 2014 23:06:04 -0700 Subject: [PATCH 1/8] Added ability to override all boolean & string liftoffrc config options with CLI arguments --- defaults/liftoffrc | 1 + lib/liftoff/cli.rb | 49 ++++++++++++++++++++++++++++++++++++++-- lib/liftoff/launchpad.rb | 7 ++---- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/defaults/liftoffrc b/defaults/liftoffrc index 3c92b68..902b6be 100644 --- a/defaults/liftoffrc +++ b/defaults/liftoffrc @@ -4,6 +4,7 @@ # company: # author: # prefix: +# company_identifier: ############################################################################ configure_git: true diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index be0f50e..0b2c637 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -2,11 +2,12 @@ module Liftoff class CLI def initialize(argv) @argv = argv + @liftoffrc = {} end def run parse_command_line_options - LaunchPad.new.liftoff + LaunchPad.new.liftoff @liftoffrc end private @@ -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}" @@ -28,6 +29,50 @@ def global_options puts opts exit end + + # Boolean Features + + opts.on('--[no-]cp', 'Enable/Disable Cocoapods') do |use_cocoapods| + @liftoffrc[:use_cocoapods] = use_cocoapods + end + + opts.on('--[no-]git', 'Enable/Disable git') do |configure_git| + @liftoffrc[:configure_git] = configure_git + end + + opts.on('--[no-]warnings', 'Enable/Disable warnings as errors') do |warnings_as_errors| + @liftoffrc[:warnings_as_errors] = warnings_as_errors + end + + opts.on('--[no-]todo-scripts', 'Enable/Disable installation of TODO scripts') do |install_todo_script| + @liftoffrc[:install_todo_script] = install_todo_script + end + + opts.on('--[no-]static-analyzer', 'Enable/Disable static analyzer') do |enable_static_analyzer| + @liftoffrc[:enable_static_analyzer] = enable_static_analyzer + end + + # String Features + + opts.on('-name', '--project_name', String, 'Set project name') do |name| + @liftoffrc[:project_name] = name + end + + opts.on('-c', '--company', String, 'Set project company') do |company| + @liftoffrc[:company] = company + end + + opts.on('-a', '--author', String, 'Set project author') do |author| + @liftoffrc[:author] = author + end + + opts.on('-p', '--prefix', String, 'Set project prefix') do |prefix| + @liftoffrc[:prefix] = prefix + end + + opts.on('-i', '--identifier', String, 'Set project company ID (com.example)') do |identifier| + @liftoffrc[:company_identifier] = identifier + end end end end diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index 95e7efb..9194b85 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -1,11 +1,8 @@ module Liftoff class LaunchPad - def initialize - liftoffrc = ConfigurationParser.new.project_configuration + def liftoff(cli_config) + liftoffrc = ConfigurationParser.new.project_configuration.merge(cli_config) @config = ProjectConfiguration.new(liftoffrc) - end - - def liftoff if project_exists? perform_project_actions else From a0925240155c3b00490544088bd7b6879f502c29 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 20 Mar 2014 01:01:07 -0700 Subject: [PATCH 2/8] Fixed string cli arguments --- lib/liftoff/cli.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index 0b2c637..34981d2 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -54,23 +54,23 @@ def global_options # String Features - opts.on('-name', '--project_name', String, 'Set project name') do |name| + opts.on('-n', '--project_name [PROJECT_NAME]', 'Set project name') do |name| @liftoffrc[:project_name] = name end - opts.on('-c', '--company', String, 'Set project company') do |company| + opts.on('-c', '--company [COMPANY]', 'Set project company') do |company| @liftoffrc[:company] = company end - opts.on('-a', '--author', String, 'Set project author') do |author| + opts.on('-a', '--author [AUTHOR]', 'Set project author') do |author| @liftoffrc[:author] = author end - opts.on('-p', '--prefix', String, 'Set project prefix') do |prefix| + opts.on('-p', '--prefix [PREFIX]', 'Set project prefix') do |prefix| @liftoffrc[:prefix] = prefix end - opts.on('-i', '--identifier', String, 'Set project company ID (com.example)') do |identifier| + opts.on('-i', '--identifier [IDENTIFIER]', 'Set project company ID (com.example)') do |identifier| @liftoffrc[:company_identifier] = identifier end end From 1cf1e175fdec07d7c2488e9ae1374f58b97f5a22 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 20 Mar 2014 02:34:35 -0700 Subject: [PATCH 3/8] added indentation_level cli option --- lib/liftoff/cli.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index 34981d2..ad3fe2d 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -30,7 +30,7 @@ def global_options exit end - # Boolean Features + # Boolean Options opts.on('--[no-]cp', 'Enable/Disable Cocoapods') do |use_cocoapods| @liftoffrc[:use_cocoapods] = use_cocoapods @@ -52,7 +52,13 @@ def global_options @liftoffrc[:enable_static_analyzer] = enable_static_analyzer end - # String Features + # Integer Options + + opts.on('-t', '--indentation_level N', 'Set indentation level') do |indentation_level| + @liftoffrc[:indentation_level] = indentation_level + end + + # String Options opts.on('-n', '--project_name [PROJECT_NAME]', 'Set project name') do |name| @liftoffrc[:project_name] = name From 0f9b24c6510f5f89c0785e42e6b8fdc04eca3c47 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 27 Mar 2014 12:29:15 -0400 Subject: [PATCH 4/8] - renamed @liftoffrc to @options in Liftoff::CLI - removed/renamed some CLI options - moved liftoffrc/cli_options merging from LaunchPad to ConfigurationParser --- lib/liftoff/cli.rb | 34 ++++++++++------------------- lib/liftoff/configuration_parser.rb | 7 +++++- lib/liftoff/launchpad.rb | 2 +- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index ad3fe2d..f7471b9 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -2,12 +2,12 @@ module Liftoff class CLI def initialize(argv) @argv = argv - @liftoffrc = {} + @options = {} end def run parse_command_line_options - LaunchPad.new.liftoff @liftoffrc + LaunchPad.new.liftoff @options end private @@ -32,52 +32,40 @@ def global_options # Boolean Options - opts.on('--[no-]cp', 'Enable/Disable Cocoapods') do |use_cocoapods| - @liftoffrc[:use_cocoapods] = use_cocoapods + 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| - @liftoffrc[:configure_git] = configure_git - end - - opts.on('--[no-]warnings', 'Enable/Disable warnings as errors') do |warnings_as_errors| - @liftoffrc[:warnings_as_errors] = warnings_as_errors - end - - opts.on('--[no-]todo-scripts', 'Enable/Disable installation of TODO scripts') do |install_todo_script| - @liftoffrc[:install_todo_script] = install_todo_script - end - - opts.on('--[no-]static-analyzer', 'Enable/Disable static analyzer') do |enable_static_analyzer| - @liftoffrc[:enable_static_analyzer] = enable_static_analyzer + @options[:configure_git] = configure_git end # Integer Options opts.on('-t', '--indentation_level N', 'Set indentation level') do |indentation_level| - @liftoffrc[:indentation_level] = indentation_level + @options[:indentation_level] = indentation_level end # String Options opts.on('-n', '--project_name [PROJECT_NAME]', 'Set project name') do |name| - @liftoffrc[:project_name] = name + @options[:project_name] = name end opts.on('-c', '--company [COMPANY]', 'Set project company') do |company| - @liftoffrc[:company] = company + @options[:company] = company end opts.on('-a', '--author [AUTHOR]', 'Set project author') do |author| - @liftoffrc[:author] = author + @options[:author] = author end opts.on('-p', '--prefix [PREFIX]', 'Set project prefix') do |prefix| - @liftoffrc[:prefix] = prefix + @options[:prefix] = prefix end opts.on('-i', '--identifier [IDENTIFIER]', 'Set project company ID (com.example)') do |identifier| - @liftoffrc[:company_identifier] = identifier + @options[:company_identifier] = identifier end end end diff --git a/lib/liftoff/configuration_parser.rb b/lib/liftoff/configuration_parser.rb index 9ab434f..ee53589 100644 --- a/lib/liftoff/configuration_parser.rb +++ b/lib/liftoff/configuration_parser.rb @@ -1,6 +1,10 @@ module Liftoff class ConfigurationParser + def initialize(cli_options) + @cli_options = cli_options + end + def project_configuration @configuration ||= evaluated_configuration end @@ -10,7 +14,8 @@ def project_configuration def evaluated_configuration default_configuration. merge(user_configuration). - merge(local_configuration) + merge(local_configuration). + merge(@cli_options) end def default_configuration diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index 2403db7..b2c7ee9 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -1,7 +1,7 @@ module Liftoff class LaunchPad def liftoff(cli_config) - liftoffrc = ConfigurationParser.new.project_configuration.merge(cli_config) + liftoffrc = ConfigurationParser.new(cli_config).project_configuration @config = ProjectConfiguration.new(liftoffrc) if project_exists? perform_project_actions From 62631e630dff09360d7973faca1152bbfe1e1b59 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 27 Mar 2014 14:15:51 -0400 Subject: [PATCH 5/8] dot on newline for multiline chained calls --- lib/liftoff/configuration_parser.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/liftoff/configuration_parser.rb b/lib/liftoff/configuration_parser.rb index ee53589..cf4e5f4 100644 --- a/lib/liftoff/configuration_parser.rb +++ b/lib/liftoff/configuration_parser.rb @@ -13,9 +13,9 @@ def project_configuration def evaluated_configuration default_configuration. - merge(user_configuration). - merge(local_configuration). - merge(@cli_options) + merge(user_configuration) + .merge(local_configuration) + .merge(@cli_options) end def default_configuration From ae45ca33737e2987e7bb5ff000427bf0d58c7671 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 27 Mar 2014 14:20:01 -0400 Subject: [PATCH 6/8] cli: `project_name`->`name`, `indentation_level`->`indentation` --- lib/liftoff/cli.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index f7471b9..dd68e92 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -42,13 +42,13 @@ def global_options # Integer Options - opts.on('-t', '--indentation_level N', 'Set indentation level') do |indentation_level| + opts.on('-t', '--indentation N', 'Set indentation level') do |indentation_level| @options[:indentation_level] = indentation_level end # String Options - opts.on('-n', '--project_name [PROJECT_NAME]', 'Set project name') do |name| + opts.on('-n', '--name [PROJECT_NAME]', 'Set project name') do |name| @options[:project_name] = name end From c8464ef7a219e8efd034d87619ddfdcaa8d16ee8 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 27 Mar 2014 14:21:30 -0400 Subject: [PATCH 7/8] dot on newline for multiline chained calls --- lib/liftoff/configuration_parser.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/liftoff/configuration_parser.rb b/lib/liftoff/configuration_parser.rb index cf4e5f4..23756b9 100644 --- a/lib/liftoff/configuration_parser.rb +++ b/lib/liftoff/configuration_parser.rb @@ -12,8 +12,8 @@ def project_configuration private def evaluated_configuration - default_configuration. - merge(user_configuration) + default_configuration + .merge(user_configuration) .merge(local_configuration) .merge(@cli_options) end From 83b3edd72b6ffb9e5d693ff50a4f516d91e92687 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 27 Mar 2014 14:27:34 -0400 Subject: [PATCH 8/8] - removed separation comments in CLI - renamed instances of "cli_options" and "cli_config" to just "options" --- lib/liftoff/cli.rb | 6 ------ lib/liftoff/configuration_parser.rb | 6 +++--- lib/liftoff/launchpad.rb | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index dd68e92..72c647c 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -30,8 +30,6 @@ def global_options exit end - # Boolean Options - opts.on('--[no-]cocoapods', 'Enable/Disable Cocoapods') do |use_cocoapods| @options[:use_cocoapods] = use_cocoapods end @@ -40,14 +38,10 @@ def global_options @options[:configure_git] = configure_git end - # Integer Options - opts.on('-t', '--indentation N', 'Set indentation level') do |indentation_level| @options[:indentation_level] = indentation_level end - # String Options - opts.on('-n', '--name [PROJECT_NAME]', 'Set project name') do |name| @options[:project_name] = name end diff --git a/lib/liftoff/configuration_parser.rb b/lib/liftoff/configuration_parser.rb index 23756b9..8ed32a4 100644 --- a/lib/liftoff/configuration_parser.rb +++ b/lib/liftoff/configuration_parser.rb @@ -1,8 +1,8 @@ module Liftoff class ConfigurationParser - def initialize(cli_options) - @cli_options = cli_options + def initialize(options) + @options = options end def project_configuration @@ -15,7 +15,7 @@ def evaluated_configuration default_configuration .merge(user_configuration) .merge(local_configuration) - .merge(@cli_options) + .merge(@options) end def default_configuration diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index b2c7ee9..cb4df71 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -1,7 +1,7 @@ module Liftoff class LaunchPad - def liftoff(cli_config) - liftoffrc = ConfigurationParser.new(cli_config).project_configuration + def liftoff(options) + liftoffrc = ConfigurationParser.new(options).project_configuration @config = ProjectConfiguration.new(liftoffrc) if project_exists? perform_project_actions