Class: Imap::Backup::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers
Defined in:
lib/imap/backup/cli.rb,
lib/imap/backup/cli/local.rb,
lib/imap/backup/cli/setup.rb,
lib/imap/backup/cli/utils.rb,
lib/imap/backup/cli/backup.rb,
lib/imap/backup/cli/remote.rb,
lib/imap/backup/cli/single.rb,
lib/imap/backup/cli/helpers.rb,
lib/imap/backup/cli/restore.rb,
lib/imap/backup/cli/local/check.rb,
lib/imap/backup/cli/single/backup.rb,
lib/imap/backup/cli/folder_enumerator.rb

Overview

Top-level cli call handler

Defined Under Namespace

Modules: Helpers Classes: Backup, FolderEnumerator, Local, Remote, Restore, Setup, Single, Stats, Transfer, Utils

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#account, #load_config, #options, #requested_accounts

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/imap/backup/cli.rb', line 72

def self.exit_on_failure?
  true
end

.start(args) ⇒ Object

Overrides Thor’s method to handle ‘–version’ and rearrange parameters if ‘help’ is passed



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/imap/backup/cli.rb', line 51

def self.start(args)
  if args.include?("--version")
    new.version
    exit 0
  end

  # By default, commands like `imap-backup help foo bar`
  # are handled by listing all `foo` methods, whereas the user
  # probably wants the detailed help for the `bar` method.
  # Move initial "help" argument to after any subcommand,
  # so we get help for the requested subcommand method.
  first_argument_is_help = ARGV[0] == "help"
  second_argument_is_subcommand = subcommands.include?(ARGV[1])
  if first_argument_is_help && second_argument_is_subcommand
    help, subcommand = ARGV.shift(2)
    ARGV.unshift(subcommand, help)
  end
  super
end

Instance Method Details

#backupObject

Runs account backups



90
91
92
93
# File 'lib/imap/backup/cli.rb', line 90

def backup
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  Backup.new(non_logging_options).run
end

#migrate(source_email, destination_email) ⇒ Object

Migrates emails from one account to another



151
152
153
154
# File 'lib/imap/backup/cli.rb', line 151

def migrate(source_email, destination_email)
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  Transfer.new(:migrate, source_email, destination_email, non_logging_options).run
end

#mirror(source_email, destination_email) ⇒ Object

Keeps one email account in line with another



211
212
213
214
# File 'lib/imap/backup/cli.rb', line 211

def mirror(source_email, destination_email)
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  Transfer.new(:mirror, source_email, destination_email, non_logging_options).run
end

#restore(email = nil) ⇒ Object

Restores backed up meails to an account



229
230
231
232
# File 'lib/imap/backup/cli.rb', line 229

def restore(email = nil)
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  Restore.new(email, non_logging_options).run
end

#setupObject

Runs the menu-driven setup program



243
244
245
246
# File 'lib/imap/backup/cli.rb', line 243

def setup
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  CLI::Setup.new(non_logging_options).run
end

#stats(email) ⇒ Object

Prints various statistics about a configured account



267
268
269
270
# File 'lib/imap/backup/cli.rb', line 267

def stats(email)
  non_logging_options = Imap::Backup::Logger.setup_logging(options)
  Stats.new(email, non_logging_options).run
end

#versionObject

Prints the program version



277
278
279
# File 'lib/imap/backup/cli.rb', line 277

def version
  Kernel.puts "imap-backup #{Imap::Backup::VERSION}"
end