class MiGA::Cli::Action::Archive

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/archive.rb, line 8
def parse_cli
  cli.parse do |opt|
    opt.on(
      '-o', '--tarball PATH',
      '(Mandatory) Path to the archive to be created ending in .tar.gz'
    ) { |v| cli[:tarball] = v }
    opt.on(
      '-f', '--folder STRING',
      'Name of the output folder. By default: name of the source project'
    ) { |v| cli[:folder] = v }
    cli.opt_object(opt, [:project, :dataset_opt])
    cli.opt_filter_datasets(opt)
  end
end
perform() click to toggle source
# File lib/miga/cli/action/archive.rb, line 23
def perform
  cli.ensure_par(tarball: '-o')
  unless cli[:tarball] =~ /\.tar\.gz$/
    raise 'The tarball path (-o) must have .tar.gz extension'
  end

  cli[:folder] ||= cli.load_project.name
  ds = cli.load_and_filter_datasets

  open_tarball do |tar|
    # Datasets
    cli.say 'Archiving datasets'
    each_file_listed(ds) do |rel_path, abs_path|
      add_file_to_tar(tar, rel_path, abs_path)
    end

    # Project
    cli.say 'Archiving project'
    pmd = cli.load_project.metadata.dup
    pmd[:datasets] = ds.map(&:name)
    add_string_to_tar(tar, 'miga.project.json', pmd.to_json)
    add_string_to_tar(tar, 'daemon/daemon.json', '{}')
  end
end