class MiGA::Cli::Action::GetDb

Public Instance Methods

complete() click to toggle source
Calls superclass method MiGA::Cli::Action#complete
# File lib/miga/cli/action/get_db.rb, line 72
def complete
  @ftp.close unless @ftp.nil?
  super
end
empty_action() click to toggle source
# File lib/miga/cli/action/get_db.rb, line 68
def empty_action
  cli.puts 'Downloading latest version of the default database'
end
parse_cli() click to toggle source
# File lib/miga/cli/action/get_db.rb, line 10
def parse_cli
  cli.defaults = {
    database: :recommended,
    version: :latest,
    local: File.expand_path('.miga_db', ENV['MIGA_HOME']),
    host: 'ftp://microbial-genomes.org/db',
    pb: true,
    overwrite: true
  }
  cli.parse do |opt|
    opt.on(
      '-n', '--database STRING',
      "Name of the database to download. By default: #{cli[:database]}"
    ) { |v| cli[:database] = v.to_sym }
    opt.on(
      '--db-version STRING',
      "Database version to download. By default: #{cli[:version]}"
    ) { |v| cli[:version] = v.to_sym }
    opt.on(
      '-l', '--local-dir PATH',
      "Local directory to store the database. By default: #{cli[:local]}"
    ) { |v| cli[:local] = v }
    opt.on(
      '-h', '--host STRING',
      "Remote host of the database. By default: #{cli[:host]}"
    ) { |v| cli[:db] = v.to_sym }
    opt.on(
      '--list',
      'List available databases and exit'
    ) { |v| cli[:list_databases] = v }
    opt.on(
      '--list-versions',
      'List available versions of the database and exit'
    ) { |v| cli[:list_versions] = v }
    opt.on(
      '--no-overwrite',
      'Exit without downloading if the target database already exists'
    ) { |v| cli[:overwrite] = v }
    opt.on('--no-progress', 'Supress progress bars') { |v| cli[:pb] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/get_db.rb, line 52
def perform
  @ftp = remote_connection
  manif = remote_manifest(@ftp)
  cli.puts "# Host: #{manif[:host]}"
  cli.puts "# Manifest last update: #{manif[:last_update]}"
  list_databases(manif) and return
  db = db_requested(manif)
  list_versions(db) and return
  ver = version_requested(db)
  check_target and return
  file = download_file(@ftp, ver[:path])
  check_digest(ver, file)
  unarchive(file)
  register_database(manif, db, ver)
end