class EcoRake module Lib module Files class Decrypt < EcoRake::Lib::BaseTask options_with_defaults true option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)' option '-l', '--list', TrueClass, desc: 'Lists available gpg feed files' option '-d', '--folder NAME', default: '.', desc: 'Source local folder' attr_const :ignore_mdc_error, default: false def task(*_args) return display_target_files if options[:list] return warn_missing_file if target_files.empty? status = 0 target_files.each do |file| delete_file(gpg_to_csv_filename(file)) stat = sh_continue(decrypt_command(file, ignore_mdc_error: ignore_mdc_error)) status = stat unless stat.zero? end delete_file(*target_files, message: "Deleting files from '#{source_folder}'") unless options[:simulate] exit status unless status.zero? end def display_target_files puts "Source gpg files ('#{source_folder}'):" target_files.each {|file| puts " • #{File.basename(file)}"} end def warn_missing_file puts "Could not find any file in folder '#{source_folder}'" end private # Amont the `target_files` the last in alphabetic order. def latest_file @latest_file ||= target_files.last end def target_files @target_files ||= gpg_files(source_folder) end def source_folder @source_folder ||= File.expand_path(options[:folder]) end end end end end