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

#align_progress_bar_title, #error, #help, #needs_database?, #option_error, #srcdir_root

Constructor Details

#initializeListCommand

Returns a new instance of ListCommand.



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

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bitclust/subcommands/list_command.rb', line 40

def exec(argv, options)
  super
  case @mode
  when :library
    db = @db
    db.is_a?(MethodDatabase) or raise "invalid database given. Use without --capi option"
    db.libraries.map {|lib| lib.name }.sort.each do |name|
      puts name
    end
  when :class
    db = @db
    db.is_a?(MethodDatabase) or raise "invalid database given. Use without --capi option"
    db.classes.map {|c| c.name }.sort.each do |name|
      puts name
    end
  when :method
    db = @db
    db.is_a?(MethodDatabase) or raise "invalid database given. Use without --capi option"
    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 = @db
    db.is_a?(FunctionDatabase) or raise "invalid database given. Use with --capi option"
    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



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

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