Class: RailsApp::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_app/cli.rb

Class Method Summary collapse

Class Method Details

.create_app(app_name, args) ⇒ Object



43
44
45
# File 'lib/rails_app/cli.rb', line 43

def self.create_app(app_name, args)
  Command.new(app_name, args).run
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_app/cli.rb', line 28

def self.menu(prompt, option_data = nil)
  assets = prompt.select("How would you like to manage assets?", %w[propshaft sprockets], default: option_data&.default_assets)
  styling = prompt.select("How would you like to manage styling?", %w[bootstrap tailwind bulma postcss sass], default: option_data&.default_styling)
  database = prompt.select("Which database would you like to use?", %w[postgresql sqlite3 mysql trilogy oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc], default: option_data&.default_database)
  skip_spring = prompt.yes?("Would you like to SKIP spring?", default: option_data&.default_action_mailer)
  action_mailer = prompt.yes?("Would you like to SKIP Action Mailer?", default: option_data&.default_action_mailer)
  action_mailbox = prompt.yes?("Would you like to SKIP Action Mailbox?", default: option_data&.default_action_mailbox)
  action_text = prompt.yes?("Would you like to SKIP Action Text?", default: option_data&.default_action_text)
  action_storage = prompt.yes?("Would you like to SKIP Active Storage?", default: option_data&.default_action_storage)
  action_cable = prompt.yes?("Would you like to SKIP Active Cable?", default: option_data&.default_action_cable)

  {assets: assets, styling: styling, database: database, skip_spring: skip_spring, action_mailer: action_mailer,
   action_mailbox: action_mailbox, action_text: action_text, action_storage: action_storage, action_cable: action_cable}
end

.save_config(prompt, config_file, config_options) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/rails_app/cli.rb', line 47

def self.save_config(prompt, config_file, config_options)
  if prompt.yes?("Do you wish to save your configuration?")
    config_options.each do |key, value|
      config_file.set(key, value)
    end
    config_file.write(force: true)
    puts "Configuration saved successfully @ #{config_file.full_path}"
  end
end

.start(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_app/cli.rb', line 7

def self.start(args)
  # puts "args: #{args}"
  prompt = TTY::Prompt.new
  options_data = OptionsData.new(args)
  config_file = ConfigFile.new

  app_name = options_data.app_name || prompt.ask("What is the name of your application?", required: true)

  # Read from existing configuration and ask the user if they want to use it
  config_options = config_file.read

  if config_options && prompt.yes?("Do you want to use this configuration? #{config_options}")
    create_app(app_name, config_options) # standard:disable Style/IdenticalConditionalBranches
  else
    config_options = menu(prompt, options_data) # open cli menus to get user input
    # puts "config_options: #{config_options}"
    save_config(prompt, config_file, config_options) # save their configuration
    create_app(app_name, config_options) # standard:disable Style/IdenticalConditionalBranches
  end
end