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
43 changes: 41 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,44 @@ def global_options
puts opts
exit
end

# Boolean Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need these comments.


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

# Integer Options

opts.on('-t', '--indentation_level N', 'Set indentation level') do |indentation_level|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use dashes consistently here? --indentation-level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately we can't. optparse sees --indentation-level as -level with a modifier of --indentation. Just as it does with --no-warnings. That's why I'm using underscores here. If optparse has an override for this, then great! But I didn't find it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gross. I'll ask around.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do --indentationlevel. But that's not really better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could just use --indentation here, and --name instead of --project_name. I feel like those look better even if they aren't quite as descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so how's this for all the flags:

--[no-]cocoapods
--[no-]git
--indentation N ... alias -t
--name [PROJECT_NAME] ... alias -n
--company [COMPANY] ... alias -c
--author [AUTHOR] ... alias -a
--prefix [PREFIX] ... alias -p
--identifier [IDENTIFIER] ... alias -i

It's not at all obvious that -t maps to indentation, but -i is taken (rightfully so).

@options[:indentation_level] = indentation_level
end

# String Options

opts.on('-n', '--project_name [PROJECT_NAME]', 'Set project name') do |name|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto above. This should probably be --project-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
7 changes: 6 additions & 1 deletion lib/liftoff/configuration_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Liftoff
class ConfigurationParser

def initialize(cli_options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this argument options consistently? Here as well as in Launchpad?

@cli_options = cli_options
end

def project_configuration
@configuration ||= evaluated_configuration
end
Expand All @@ -10,7 +14,8 @@ def project_configuration
def evaluated_configuration
default_configuration.
merge(user_configuration).
merge(local_configuration)
merge(local_configuration).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place the . on the next line, together with the method name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new addition to our style guide, but it would probably be good to go ahead and make this change now since we're messing around in here.

merge(@cli_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(cli_config)
liftoffrc = ConfigurationParser.new(cli_config).project_configuration
@config = ProjectConfiguration.new(liftoffrc)
end

def liftoff
if project_exists?
perform_project_actions
else
Expand Down