Class: Imap::Backup::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Migrate, Mirror
Defined in:
lib/imap/backup/cli.rb,
lib/imap/backup/cli/local.rb,
lib/imap/backup/cli/setup.rb,
lib/imap/backup/cli/stats.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/options.rb,
lib/imap/backup/cli/restore.rb,
lib/imap/backup/cli/local/check.rb,
lib/imap/backup/cli/single/backup.rb

Overview

Top-level cli call handler

Defined Under Namespace

Modules: Helpers, Migrate, Mirror Classes: Backup, Local, Options, Remote, Restore, Setup, Single, Stats, Transfer, Utils

Constant Summary

Constants included from Mirror

Mirror::LONG_DESCRIPTION

Constants included from Helpers

Helpers::NAMESPACE_CONFIGURATION_DESCRIPTION

Constants included from Migrate

Migrate::LONG_DESCRIPTION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mirror

included

Methods included from Helpers

#account, included, #load_config, #options, #requested_accounts

Methods included from Migrate

included

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/imap/backup/cli.rb', line 53

def self.exit_on_failure?
  true
end

.start(args) ⇒ void

This method returns an undefined value.

Overrides Thor's method to handle '--version' and rearrange parameters if 'help' is passed



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/imap/backup/cli.rb', line 32

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

#backupvoid

This method returns an undefined value.

Runs account backups



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

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

#copy(source_email, destination_email) ⇒ void

This method returns an undefined value.

Copies messages from one email account to another



137
138
139
140
# File 'lib/imap/backup/cli.rb', line 137

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

#restore(email = nil) ⇒ void

This method returns an undefined value.

Restores backed up emails to an account



174
175
176
177
# File 'lib/imap/backup/cli.rb', line 174

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

#setupvoid

This method returns an undefined value.

Runs the menu-driven setup program



189
190
191
192
# File 'lib/imap/backup/cli.rb', line 189

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

#stats(email) ⇒ void

This method returns an undefined value.

Prints various statistics about a configured account



215
216
217
218
# File 'lib/imap/backup/cli.rb', line 215

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

#versionvoid

This method returns an undefined value.

Prints the program version



226
227
228
# File 'lib/imap/backup/cli.rb', line 226

def version
  Kernel.puts I18n.t("cli.version", version: Imap::Backup::VERSION)
end