Class: Imap::Backup::CLI

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

Defined Under Namespace

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

Constant Summary collapse

VERSION_ARGUMENTS =
%w(-v --version).freeze
NAMESPACE_CONFIGURATION_DESCRIPTION =
<<~DESC.freeze
  Some IMAP servers use namespaces (i.e. prefixes like "INBOX"),
  while others, while others concatenate the names of subfolders
  with a charater ("delimiter") other than "/".

  In these cases there are two choices.

  You can use the `--automatic-namespaces` option.
  This wil query the source and detination servers for their
  namespace configuration and will adapt paths accordingly.
  This option requires that both the source and destination
  servers are available and work with the provided parameters
  and authentication.

  If automatic configuration does not work as desired, there are the
  `--source-prefix=`, `--source-delimiter=`,
  `--destination-prefix=` and `--destination-delimiter=` parameters.
  To check what values you should use, check the output of the
  `imap-backup remote namespaces EMAIL` command.
DESC

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

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

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/imap/backup/cli.rb', line 68

def self.exit_on_failure?
  true
end

.start(*args) ⇒ Object



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

def self.start(*args)
  version_argument = ARGV & VERSION_ARGUMENTS
  if version_argument.any?
    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



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



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

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



205
206
207
208
# File 'lib/imap/backup/cli.rb', line 205

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



222
223
224
225
# File 'lib/imap/backup/cli.rb', line 222

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

#setupObject



235
236
237
238
# File 'lib/imap/backup/cli.rb', line 235

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

#stats(email) ⇒ Object



255
256
257
258
# File 'lib/imap/backup/cli.rb', line 255

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

#versionObject



264
265
266
# File 'lib/imap/backup/cli.rb', line 264

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