#!/usr/bin/env ruby # frozen_string_literal: true $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'thor' require 'leap_salesforce/parameters' require 'leap_salesforce/generator/generator' module LeapSalesforce # Executable for setting up Leap Salesforce class Exe < Thor include LeapSalesforce::Generator include LeapSalesforce::ExeHelpers OAUTH_WIKI = 'https://gitlab.com/leap-dojo/leap_salesforce/wikis/SetUpOAuthApp' desc 'init', 'Create new leap salesforce repository' option :setup_done, default: false, type: :boolean, banner: 'Whether setup is done' option :client_id, banner: 'OAuth2 client id' option :client_secret, banner: 'OAuth2 client secret' option :username, banner: 'Username' option :user_key, banner: 'Key to identify user by' option :password, banner: 'User password' option :environment, banner: 'Environment to set automation code up for' def init # Ask user to create OAuth application by following unless options[:setup_done] oauth_setup = input_for "Have you set up OAuth application by following #{OAUTH_WIKI} (y/n)?" exit if oauth_setup.downcase == 'n' end query_for_parameters generate_files binding, ['Gemfile', 'Rakefile', '.leap_salesforce.yml', '.rspec', { config: ['general.rb', { credentials: 'salesforce_oauth2.yml' }] }, { spec: %w[spec_helper.rb limit_spec.rb crud_eg_spec.rb] }] environment_content = read_template File.join('config', 'environments', 'specific_file.rb.erb'), binding generate_file File.join('config', 'environments', "#{@environment}.rb"), environment_content, overwrite: false puts 'Initial files created!' puts 'Installing gems' puts `bundle install` puts 'Creating initial Soql objects. See ".leap_salesforce.yml" for list' puts `rake leaps:create_soql_objects` puts 'Creating enums' puts `rake leaps:create_enums` end end end LeapSalesforce::Exe.start(ARGV)