Class: BitClust::Subcommand

Inherits:
Object show all
Defined in:
lib/bitclust/subcommand.rb

Overview

Base class for bitclust subcommands.

Instance Method Summary collapse

Constructor Details

#initializeSubcommand

Returns a new instance of Subcommand.


14
15
16
17
18
19
20
# File 'lib/bitclust/subcommand.rb', line 14

def initialize
  @parser = OptionParser.new
  @parser.on_tail("-h", "--help", "Print this message and quit."){
    $stderr.puts help
    exit 0
  }
end

Instance Method Details

#error(message) ⇒ Object

TODO refactor


41
42
43
44
# File 'lib/bitclust/subcommand.rb', line 41

def error(message)
  $stderr.puts "#{File.basename($0, '.*')}: error: #{message}"
  exit 1
end

#exec(argv, options) ⇒ Object


30
31
32
33
34
35
36
37
38
# File 'lib/bitclust/subcommand.rb', line 30

def exec(argv, options)
  prefix = options[:prefix]
  error("no database given. Use --database option") unless prefix
  if options[:capi]
    @db = BitClust::FunctionDatabase.new(prefix)
  else
    @db = BitClust::MethodDatabase.new(prefix)
  end
end

#helpObject


26
27
28
# File 'lib/bitclust/subcommand.rb', line 26

def help
  @parser.help
end

#option_error(message) ⇒ Object


46
47
48
49
50
# File 'lib/bitclust/subcommand.rb', line 46

def option_error(message)
  $stderr.puts message
  $stderr.puts help
  exit 1
end

#parse(argv) ⇒ Object


22
23
24
# File 'lib/bitclust/subcommand.rb', line 22

def parse(argv)
  @parser.parse! argv
end

#srcdir_rootObject


52
53
54
# File 'lib/bitclust/subcommand.rb', line 52

def srcdir_root
  Pathname.new(__FILE__).realpath.dirname.parent.parent
end