class MiGA::Cli::Action::Get

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/get.rb, line 9
def parse_cli
  cli.defaults = {query: false, universe: :ncbi, db: :nuccore,
    get_md: false, only_md: false}
  cli.parse do |opt|
    cli.opt_object(opt, [:project, :dataset, :dataset_type])
    opt.on(
      '-I', '--ids ID1,ID2,...', Array,
      '(Mandatory unless -F) IDs in the remote database separated by commas'
      ){ |v| cli[:ids] = v }
    opt.on(
      '-U', '--universe STRING',
      "Universe of the remote database. By default: #{cli[:universe]}"
      ){ |v| cli[:universe] = v.to_sym }
    opt.on(
      '--db STRING',
      "Name of the remote database. By default: #{cli[:db]}"
      ){ |v| cli[:db] = v.to_sym }
    opt.on(
      '-F', '--file PATH',
      'Tab-delimited file (with header) listing the datasets to download',
      'The long form of most options are supported as header (without --)',
      'including: dataset, ids, universe, db, metadata',
      'For flags without value (like query) use true/false',
      'Unsupported values are: project, file, verbose, help, and debug'
      ){ |v| cli[:file] = v }
    opt.on(
      '-q', '--query',
      'Register the dataset as a query, not a reference dataset'
      ){ |v| cli[:query] = v }
    opt.on('--ignore-dup',
      'Ignore datasets that already exist'
      ){ |v| cli[:ignore_dup] = v }
    opt.on(
      '-d', '--description STRING',
      'Description of the dataset'
      ){ |v| cli[:description] = v }
    opt.on(
      '-c', '--comments STRING',
      'Comments on the dataset'
      ){ |v| cli[:comments] = v }
    opt.on(
      '-m', '--metadata STRING',
      'Metadata as key-value pairs separated by = and delimited by comma',
      'Values are saved as strings except for booleans (true / false) or nil'
      ){ |v| cli[:metadata] = v }
    opt.on(
      '--get-metadata',
      'Only download and update metadata for existing datasets'
      ){ |v| cli[:get_md] = v }
    opt.on(
      '--only-metadata',
      'Create datasets without input data but retrieve all metadata'
      ){ |v| cli[:only_md] = v }
    opt.on(
      '--api-key STRING',
      'API key for the given universe'
      ){ |v| cli[:api_key] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/get.rb, line 69
def perform
  glob = get_sub_cli
  p = cli.load_project
  glob.each do |sub_cli|
    rd = create_remote_dataset(sub_cli)
    next if rd.nil?
    if sub_cli[:get_md]
      update_metadata(sub_cli, p, rd)
    else
      create_dataset(sub_cli, p, rd)
    end
  end
end