Class: BitClust::Subcommands::ListCommand
- Inherits:
-
BitClust::Subcommand
- Object
- BitClust::Subcommand
- BitClust::Subcommands::ListCommand
- Defined in:
- lib/bitclust/subcommands/list_command.rb
Instance Method Summary collapse
- #exec(argv, options) ⇒ Object
-
#initialize ⇒ ListCommand
constructor
A new instance of ListCommand.
- #parse(argv) ⇒ Object
Methods inherited from BitClust::Subcommand
#align_progress_bar_title, #error, #help, #option_error, #srcdir_root
Constructor Details
#initialize ⇒ ListCommand
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. = "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 |
# File 'lib/bitclust/subcommands/list_command.rb', line 40 def exec(argv, ) 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
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 |