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.



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

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

Instance Method Details

#align_progress_bar_title(title) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/bitclust/subcommand.rb', line 63

def align_progress_bar_title(title)
  size = title.size
  if size > 14
    title[0..13] || raise
  else
    title + ' ' * (14 - size)
  end
end

#error(message) ⇒ Object

TODO refactor



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

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

#exec(argv, options) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/bitclust/subcommand.rb', line 37

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



33
34
35
# File 'lib/bitclust/subcommand.rb', line 33

def help
  @parser.help
end

#needs_database?Boolean

グローバル --database(options)を必要とするか。 DB パスを自前の引数で受けるサブコマンド(searchpage)は false を返す

Returns:

  • (Boolean)


29
30
31
# File 'lib/bitclust/subcommand.rb', line 29

def needs_database?
  true
end

#option_error(message) ⇒ Object



53
54
55
56
57
# File 'lib/bitclust/subcommand.rb', line 53

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

#parse(argv) ⇒ Object



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

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

#srcdir_rootObject



59
60
61
# File 'lib/bitclust/subcommand.rb', line 59

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