#!/usr/bin/env ruby require 'yaml' CONFIG_FILE = ['/etc/salesforce.yaml','~/.salesforce.yaml'] config = nil CONFIG_FILE.each do |cf| cf = File.expand_path cf if File.exists? cf config = YAML::load File.open(cf).read break end end if config.nil? puts "error: /etc/salesforce.yaml or ~/.salesforce.yaml not found" exit 1 end require 'salesforcedeploytool' program :version, SalesforceDeployTool::VERSION program :description, 'A cli tool to help manage and deploy salesforce environments with git' command :init do |c| c.syntax = 'sf init [options]' c.summary = 'Initialize salesforce environment from git' c.description = "Clone the #{config[:git_repo]} to #{config[:git_dir]}" c.example 'usage', 'sf init' c.action do |args, options| # Initialize sfdt = SalesforceDeployTool::App.new config # Clone sfdt.clone end end command :pull do |c| c.syntax = 'sf pull' c.summary = 'Pull code from the environment' c.description = "Pull code from environment and update #{config[:git_dir]}" c.example 'usage:', 'sf pull' c.example 'usage:', 'sf pull -c -d' c.option "--no-clean", "Do not clean the currrent source code before pulling" c.option "--debug", "Verbose output" c.option "--env NAME", "use 'prod' to deploy production or sandbox name" c.action do |args, options| # Parameter validation: if options.env.nil? puts "error: please specify the environment to pull from using --env" exit 1 end config[:env] = options.env config[:debug] = options.debug.nil? ? false : true # Initialize sfdt = SalesforceDeployTool::App.new config # Clean all files from repo sfdt.clean_git_dir unless options.no_clean # Pull the changes sfdt.pull "INFO: Pulling changes from #{config[:env]}" end end command :push do |c| c.syntax = 'sf push [options]' c.summary = 'Push code into a sandbox' c.description = '' c.example 'description', "Push the code that is located into #{config[:git_dir]} into the active sandbox" c.option "--env NAME", "use 'prod' to deploy production or sandbox name" c.option "--debug", "Verbose output" c.option "--test", "Deploy and test" c.option "--exclude LIST", "a CSV list of metadata to exclude when creating destructiveChange.xml" c.option "--append", "Disable destructive change and do an append deploy" c.action do |args, options| # Parameter validation: if options.env.nil? puts "error: please specify the environment to pull from using --env" exit 1 end config[:env] = options.env config[:debug] = options.debug.nil? ? false : true config[:test] = options.test.nil? ? false : true # Initialize sfdt = SalesforceDeployTool::App.new config # Pull changes from sandbox to temporary directory: config_tmp = config.clone config_tmp[:git_dir] = config_tmp[:tmp_dir] FileUtils.rm_rf config_tmp[:git_dir] if File.exists? config_tmp[:git_dir] sfdt_tmp = SalesforceDeployTool::App.new config_tmp sfdt_tmp.clone sfdt_tmp.clean_git_dir sfdt_tmp.pull "INFO: Pulling changes from #{config[:env]} to temporary directory #{config[:tmp_dir]} to generate destructiveChanges.xml " # Create destructiveChanges.xml if ! options.append puts "INFO: Creating destructive changes xml" dc_gen = Dcgen::App.new dc_gen.master = File.join(config[:git_dir],'src') dc_gen.destination = File.join(config[:tmp_dir],'src') dc_gen.output = File.join(config[:git_dir],'src','destructiveChanges.xml') dc_gen.exclude = options.exclude.split(',') unless options.exclude.nil? # Capture stdout when running generate_destructive_Changes, TODO: fix dcgen stringio = StringIO.new stdout_tmp = $stdout $stdout = stringio unless options.debug dc_gen.generate_destructive_changes $stdout = stdout_tmp end # Finally push: sfdt.push end end default_command :help