Class: MiGA::Cli::Action::Rm

Inherits:
MiGA::Cli::Action show all
Defined in:
lib/miga/cli/action/rm.rb

Instance Attribute Summary

Attributes inherited from MiGA::Cli::Action

#cli

Instance Method Summary collapse

Methods inherited from MiGA::Cli::Action

#complete, #empty_action, #initialize, #launch, load, #name

Constructor Details

This class inherits a constructor from MiGA::Cli::Action

Instance Method Details

#parse_cliObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/miga/cli/action/rm.rb', line 7

def parse_cli
  cli.defaults = { remove: false }
  cli.parse do |opt|
    cli.opt_object(opt, %i[project dataset_opt result_opt])
    opt.on(
      '-R', '--remove',
      'Also remove all associated files',
      'By default, only unlinks from metadata'
    ) { |v| cli[:remove] = v }
  end
end

#performObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/miga/cli/action/rm.rb', line 19

def perform
  if cli[:result] && r = cli.load_result
    cli[:remove] ? r.remove! : r.unlink
  elsif d = cli.load_dataset
    cli.load_project.unlink_dataset(d.name)
    d.remove! if cli[:remove]
  else
    raise "You must define one of --result or --dataset"
  end
end