Sha256: ef4342e61c119918edea5507ae0300b82f5b4ca9811a6d35bea1e32b1bc1fb2f

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require "tty-prompt"

module RailsApp
  class CLI
    def self.start(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 the 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}")
        options_data = OptionsData.from_config(config_options)
      end

      assets = prompt.select("How would you like to manage assets?", %w[propshaft sprockets], default: options_data.default_assets)
      styling = prompt.select("How would you like to manage styling?", %w[bootstrap tailwind bulma postcss sass], default: options_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: options_data.default_database)

      # Collect all configuration options into a hash
      config_options = {
        app_name: app_name,
        assets: assets,
        styling: styling,
        database: database
      }

      # Ask the user if they wish to save their configuration
      if prompt.yes?("Do you wish to save your configuration?")
        # Iterate over the hash and set the configuration
        config_options.each do |key, value|
          next if key == :app_name
          config_file.set(key, value)
        end
        config_file.write(force: true)
        puts "Configuration saved successfully @ #{config_file.full_path}"
      end

      Command.new(config_options).run
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_app-0.8.0 lib/rails_app/cli.rb