Class: BitClust::Subcommands::ListCommand

Inherits:
BitClust::Subcommand show all
Defined in:
lib/bitclust/subcommands/list_command.rb

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#error, #help, #option_error, #srcdir_root

Constructor Details

#initializeListCommand

Returns a new instance of ListCommand.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bitclust/subcommands/list_command.rb', line 14

def initialize
  super
  @mode = nil
  @parser.banner = "Usage: #{File.basename($0, '.*')} list (--library|--class|--method|--function)"
  @parser.on('--library', 'List libraries.') {
    @mode = :library
  }
  @parser.on('--class', 'List classes.') {
    @mode = :class
  }
  @parser.on('--method', 'List methods.') {
    @mode = :method
  }
  @parser.on('--function', 'List functions (C API).') {
    @mode = :function
  }
end

Instance Method Details

#exec(argv, options) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bitclust/subcommands/list_command.rb', line 39

def exec(argv, options)
  super
  case @mode
  when :library
    @db.libraries.map {|lib| lib.name }.sort.each do |name|
      puts name
    end
  when :class
    @db.classes.map {|c| c.name }.sort.each do |name|
      puts name
    end
  when :method
    @db.classes.sort_by {|c| c.name }.each do |c|
      c.entries.sort_by {|m| m.id }.each do |m|
        puts m.label
      end
    end
  when :function
    @db.functions.sort_by {|f| f.name }.each do |f|
      puts f.name
    end
  else
    raise "must not happen: @mode=#{@mode.inspect}"
  end
end

#parse(argv) ⇒ Object


32
33
34
35
36
37
# File 'lib/bitclust/subcommands/list_command.rb', line 32

def parse(argv)
  super
  unless @mode
    error 'one of (--library|--class|--method|--function) is required'
  end
end