class MiGA::Cli::Action::Add

Public Class Methods

INPUT_TYPES() click to toggle source
# File lib/miga/cli/action/add.rb, line 101
def INPUT_TYPES
  @@INPUT_TYPES
end

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/add.rb, line 7
def parse_cli
  cli.expect_files = true
  cli.defaults = { ref: true, ignore_dups: false }
  cli.parse do |opt|
    opt.separator 'You can create multiple datasets with a single command; '          'simply pass all the files at the end: {FILES...}'
    opt.separator 'If -D is passed, only one dataset will be added. '          'Otherwise, dataset names will be determined by the file paths (see -R)'
    opt.separator ''
    cli.opt_object(opt, [:project, :dataset_opt, :dataset_type_req])
    opt.on(
      '-q', '--query',
      'Register the dataset as a query, not a reference dataset'
    ) { |v| cli[:ref] = !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(
      '-R', '--name-regexp REGEXP', Regexp,
      'Regular expression indicating how to extract the name from the path',
      'By default for paired files:',
      "'#{MiGA::Cli.FILE_REGEXP(true)}'",
      'By default for other files:',
      "'#{MiGA::Cli.FILE_REGEXP}'"
    ) { |v| cli[:regexp] = v }
    opt.on(
      '--prefix STRING',
      'Prefix to all the dataset names'
    ) { |v| cli[:prefix] = v }
    opt.on(
      '-i', '--input-type STRING',
      'Type of input data, one of the following:',
      *self.class.INPUT_TYPES.map { |k, v| "~ #{k}: #{v[0]}" }
    ) { |v| cli[:input_type] = v.downcase.to_sym }
    opt.on(
      '--ignore-dups',
      'Continue with a warning if a dataset already exists'
    ) { |v| cli[:ignore_dups] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/add.rb, line 58
def perform
  p = cli.load_project
  cli.ensure_par(type: '-t')
  files, file_type = get_files_and_type

  paired = cli[:input_type].to_s.include?('_paired')
  cli[:regexp] ||= MiGA::Cli.FILE_REGEXP(paired)

  cli.say 'Creating datasets:'
  files.each do |file|
    d = create_dataset(file, p)
    next if d.nil?

    copy_file_to_project(file, file_type, d, p)
    cli.add_metadata(d)
    p.add_dataset(d.name)
    res = d.first_preprocessing(true)
    cli.say "  result: #{res}"
  end
end