class MiGA::Cli::Action::Edit

Public Instance Methods

parse_cli() click to toggle source
# File lib/miga/cli/action/edit.rb, line 7
def parse_cli
  cli.parse do |opt|
    cli.opt_object(opt, [:project, :dataset_opt])
    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(
      '--activate',
      'Activate dataset; requires -D'
    ) { |v| cli[:activate] = v }
    opt.on(
      '--inactivate [reason]',
      'Inactivate dataset; requires -D',
      'The argument is optional: reason to inactivate dataset'
    ) { |v| cli[:activate] = false ; cli[:reason] = v }
  end
end
perform() click to toggle source
# File lib/miga/cli/action/edit.rb, line 27
def perform
  obj = cli.load_project_or_dataset
  unless cli[:activate].nil?
    cli.ensure_par(
      { dataset: '-D' },
      '%<name>s is mandatory with --[in-]activate: please provide %<flag>s'
    )
    cli[:activate] ? obj.activate! : obj.inactivate!(cli[:reason])
  end
  cli.add_metadata(obj)
  obj.save
end