Class: Imap::Backup::CLI::Backup

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/imap/backup/cli/backup.rb

Overview

Runs backups of configured accounts

Instance Method Summary collapse

Methods included from Helpers

#account, included, #load_config, #requested_accounts

Constructor Details

#initialize(options) ⇒ Backup

Returns a new instance of Backup.



18
19
20
21
# File 'lib/imap/backup/cli/backup.rb', line 18

def initialize(options)
  super([])
  @options = options
end

Instance Method Details

#runvoid

This method returns an undefined value.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/imap/backup/cli/backup.rb', line 25

no_commands do
  def run
    config = load_config(**options)
    exit_code = nil
    accounts = requested_accounts(config)
    if accounts.none?
      Logger.logger.warn "No matching accounts found to backup"
      return
    end
    accounts.each do ||
      backup = Account::Backup.new(account: , refresh: refresh)
      backup.run
    rescue StandardError => e
      exit_code ||= choose_exit_code(e)
      message = <<~ERROR
        Backup for account '#{.username}' failed with error #{e}
        #{e.backtrace.join("\n")}
      ERROR
      Logger.logger.error message
      next
    end
    exit(exit_code) if exit_code
  end
end