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

Added a liftoffrc config flag to only prompt on attributes with no specified default value #127

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/liftoffrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enable_static_analyzer: true
indentation_level: 4
use_tabs: false
use_cocoapods: true
strict_prompts: false

run_script_phases:
- todo.sh: Warn for TODO and FIXME comments
Expand Down
4 changes: 4 additions & 0 deletions lib/liftoff/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def global_options
exit
end

opts.on('--[no-]strict-prompts', 'Enable/Disable strict prompts') do |strict_prompts|
Copy link
Member

Choose a reason for hiding this comment

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

Does this work? I thought we couldn't have hyphens in the flag? Or was that just for flags that take a value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works for flags that already have a modifier. That's why it works for --[no-]strict-prompts but not for --indentation-level. optparse has some pretty eccentric parsing logic.

Copy link
Member

Choose a reason for hiding this comment

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

God that's stupid.

@options[:strict_prompts] = strict_prompts
end

opts.on('--[no-]cocoapods', 'Enable/Disable Cocoapods') do |use_cocoapods|
@options[:use_cocoapods] = use_cocoapods
end
Expand Down
11 changes: 9 additions & 2 deletions lib/liftoff/option_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ def fetch_options
private

def fetch_option_for(attribute, prompt)
value = ask("#{prompt}? ") { |q| q.default = @configuration.public_send(attribute) }
@configuration.public_send("#{attribute}=", value)
default = @configuration.public_send(attribute)
if prompt_for_default?(default)
value = ask("#{prompt}? ") { |q| q.default = default }
@configuration.public_send("#{attribute}=", value)
end
rescue EOFError
puts
fetch_option_for(attribute, prompt)
rescue Interrupt
exit 1
end

def prompt_for_default?(default)
!default || !@configuration.strict_prompts
Copy link
Member

Choose a reason for hiding this comment

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

This still bugs me, sorry. Talked it over with some ruby folks, and we kind of settled on flipping this conditional and using unless on line 18:

def skip_prompt?(default)
  default && @configuration.strict_prompts
end

My brain doesn't do as many backflips with it written out this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

end
end
end
3 changes: 2 additions & 1 deletion lib/liftoff/project_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ProjectConfiguration
:application_target_groups,
:unit_test_target_groups,
:use_cocoapods,
:run_script_phases
:run_script_phases,
:strict_prompts

attr_writer :author,
:company_identifier,
Expand Down