# Use case for special integrations. It requires some use cases to be present # 1. `-export-select-options` # 2. `-export-registers` # 3. `-export-pack` # 4. `-export-sftp-push` require 'optparse/time' class EcoRake module Lib module Export class Payload < EcoRake::Lib::BaseTask INCLUDED_OPTIONS = %i[csv simulate].freeze FORWARD_RULES = { enviro: ->(enviro) { "-#{enviro}" }, simulate: '-simulate', csv: '-csv', full: ->(full) { full ? nil : '-delta' }, asat: ->(asat) { "-asatdate #{asat}" } }.freeze options_with_defaults true option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)' option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true # , default_lookup: :default_enviro option '-f', '--[no-]full', TrueClass, default: false, desc: 'If the PAYLOAD file is a full file (false: means delta)' option '-c', '--csv', TrueClass, default: true, desc: 'Generate files in csv format?' option '-a', '--asat [DATE]', Time, default: Time.now.iso8601, desc: 'Specifies the date when the export was done (default: now).' do |value| value&.iso8601 end option_forwarding(**FORWARD_RULES) def task(*_args) sh_chain(commands) do |ok, _res| exit 1 unless ok end end private def commands cmds = [] cmds << export_select_options cmds << export_registers cmds << export_pack cmds << export_sftp_push unless options[:simulate] cmds end def export_select_options forward_command('-export-select-options') end def export_registers forward_command('-export-registers') end def export_pack forward_command('-export-pack', :full, :asat) end def export_sftp_push base_command('-export-sftp-push') end def forward_command(use, *opts) raise "Expecting String with usecase. Given: #{use.class}" unless use.is_a?(String) cmd = [base_command(use)] cmd.push(*forward_options(*self.class::INCLUDED_OPTIONS, *opts)) cmd = yield(cmd) if block_given? string_cmd(*cmd) end def base_command(use = nil) string_cmd(ruby_runner, forward_option(:enviro), use) end end end end end