Class: Libis::RosettaChecker::SubCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/libis/rosetta_checker/sub_command.rb

Direct Known Subclasses

FilesToIngestCleanup

Class Method Summary collapse

Class Method Details

.commandObject

Raises:

  • (RuntimeError)


10
11
12
# File 'lib/libis/rosetta_checker/sub_command.rb', line 10

def self.command
  raise RuntimeError, 'Method should be overwritten'
end

.helpObject



18
19
20
# File 'lib/libis/rosetta_checker/sub_command.rb', line 18

def self.help
  self.options('-h')
end

.options(*argv) ⇒ Object



22
23
24
25
26
# File 'lib/libis/rosetta_checker/sub_command.rb', line 22

def self.options(*argv)
  argv = ARGV if argv.empty?
  @config ||= self.options_class.new "#{RosettaChecker.main_command} #{self.command}"
  parse_options(argv)
end

.options_classObject

Raises:

  • (RuntimeError)


14
15
16
# File 'lib/libis/rosetta_checker/sub_command.rb', line 14

def self.options_class
  raise RuntimeError, 'Method should be overwritten'
end

.parse_options(argv) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/libis/rosetta_checker/sub_command.rb', line 28

def self.parse_options(argv)
  OptionParser.new do |opts|
    @config.define opts
    opts.on '-h', '--help', 'Show this help' do
      puts opts
      exit
    end
  end.order!(argv)
end

.runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/libis/rosetta_checker/sub_command.rb', line 38

def self.run
  self.options
  instance = self.new(@config)
  instance.run(ARGV)
rescue OptionParser::ParseError => e
  puts "ERROR: #{e.message}"
  puts ''
  self.help
rescue StandardError => e
  $stderr.puts "ERROR: #{e.message} @ #{e.backtrace.first}"
    ap e.backtrace
rescue Interrupt
  $stderr.puts "ERROR: Interrupted."
ensure
    instance.finalize if instance
end

.short_descObject

Raises:

  • (RuntimeError)


6
7
8
# File 'lib/libis/rosetta_checker/sub_command.rb', line 6

def self.short_desc
  raise RuntimeError, 'Method should be overwritten'
end

.subcommandsObject



55
56
57
# File 'lib/libis/rosetta_checker/sub_command.rb', line 55

def self.subcommands
  Hash[ObjectSpace.each_object(Class).select {|klass| klass < self}.map {|klass| [klass.command, klass]}]
end