Skip to content

Commit

Permalink
KBP-121 #time 2h implement thor ask questions for cybele options
Browse files Browse the repository at this point in the history
  • Loading branch information
İsmail Akbudak committed Sep 11, 2017
1 parent 74e8468 commit e87c3d5
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

module Cybele
class AppGenerator < Rails::Generators::AppGenerator
@options = nil

# Default settings
class_option :database,
type: :string,
Expand All @@ -21,7 +23,13 @@ class AppGenerator < Rails::Generators::AppGenerator
aliases: '-h',
group: :cybele,
desc: 'Show cybele help message and quit'
# Custom settings
# Ask cybele options
class_option :skip_ask,
type: :boolean,
aliases: nil,
default: true,
group: :cybele,
desc: 'Skip ask for cybele options. Default: skip'
class_option :skip_create_database,
type: :boolean,
aliases: nil,
Expand All @@ -35,6 +43,20 @@ class AppGenerator < Rails::Generators::AppGenerator
group: :cybele,
desc: 'Skip sidekiq integration. Default: don\'t skip'

def initialize(*args)
super
# Set options
@options = options.dup

return if @options[:skip_ask]

say 'Ask cybele options', :green
option_with_ask_limited(:database, DATABASES)
option_with_ask_yes(:skip_create_database)
option_with_ask_yes(:skip_sidekiq)
@options.freeze
end

def setup_editor_config
say 'Add .editor_config file', :green
build :add_editor_config
Expand All @@ -51,22 +73,20 @@ def remove_files_we_dont_need
end

def setup_database
say 'Setting up database', :green
build :use_postgres_config_template if options[:database] == 'postgresql'
if options[:skip_create_database]
say 'don\'t create database', :yellow
else
build :create_database
if @options[:database] == 'postgresql'
say 'Set up postgresql template', :green
build :use_postgres_config_template
end

return if @options[:skip_create_database]
say 'Create database', :green
build :create_database
end

def setup_sidekiq
return if @options[:skip_sidekiq]
say 'Setting up sidekiq', :green
if options[:skip_sidekiq]
say 'don\'t use sidekiq', :yellow
else
build :configure_sidekiq
end
build :configure_sidekiq
end

def setup_responders
Expand All @@ -83,5 +103,19 @@ def goodbye
def get_builder_class
Cybele::AppBuilder
end

private

def option_with_ask_yes(key)
say "==> #{key.to_s.humanize}", :green
say 'Type for answer yes: y|yes', :green
say 'Type for answer no: n|no|any character', :yellow

@options = @options.merge(key => yes?('Ans :', :green))
end

def option_with_ask_limited(key, limits)
@options = @options.merge(key => ask("#{key.to_s.humanize} :", limited_to: limits))
end
end
end

0 comments on commit e87c3d5

Please sign in to comment.