Skip to content

Commit

Permalink
Add command line flags
Browse files Browse the repository at this point in the history
This adds the ability to override specific `liftoffrc` options from the
command line when running `liftoff`.

Available flags are:

    --[no-]cocoapods                 Enable/Disable Cocoapods
    --[no-]git                       Enable/Disable git
    -t, --indentation N              Set indentation level
    -n, --name [PROJECT_NAME]        Set project name
    -c, --company [COMPANY]          Set project company
    -a, --author [AUTHOR]            Set project author
    -p, --prefix [PREFIX]            Set project prefix
    -i, --identifier [IDENTIFIER]    Set project company ID (com.example)

Added ability to override all boolean & string liftoffrc config options with CLI arguments

Fixed string cli arguments

added indentation_level cli option

- renamed @liftoffrc to @options in Liftoff::CLI
- removed/renamed some CLI options
- moved liftoffrc/cli_options merging from LaunchPad to ConfigurationParser

dot on newline for multiline chained calls

cli: `project_name`->`name`, `indentation_level`->`indentation`

dot on newline for multiline chained calls

- removed separation comments in CLI
- renamed instances of "cli_options" and "cli_config" to just "options"
  • Loading branch information
jpsim authored and gfontenot committed Mar 27, 2014
1 parent d93e362 commit 080b30d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
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

0 comments on commit 080b30d

Please sign in to comment.