Class: MthdsPool::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/mthdspool/cli.rb

Instance Method Summary collapse

Instance Method Details

#parse_options(argv) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mthdspool/cli.rb', line 4

def parse_options argv
  options={}
  opts = OptionParser.new do |o|
    o.banner = "Usage: mthdspool [-v] [-h] command [<args>]"
    o.separator ""
    o.on("-h", "--help", "Print this help.") {
      $stderr.puts(opts)
    }
    o.on("-v", "--version", "Print version.") {
      return $stderr.puts(VERSION)
    }
    o.on("-l", "--library [library]", "Library path") { |l|
      options[:libs] = l
    }
    o.on("-r", "--require [require]", "Require path") { |r|
      options[:reqr] = r
    }
    o.on("-g", "--gemfile [gemfile]", "Gemfile") { |g|
      options[:gemfile] = g
    }
    o.on("-i", "--inspect [inspect]", "Instance to inspect") { |i|
      options[:nspct] = i
    }
    o.on("-f", "--filter [filter]", "Object methods filter") { |f|
      options[:filter] = f
    }
    o.separator ""
    o.separator ">  = inherited method."
    o.separator "<  = object specific method."
    o.separator "IM = instance method."
    o.separator "SM = Singleton method."
    o.separator ""
    o.separator "Examples:"
    o.separator "mthdspool -o String -l ~/code/app/lib/app -f methods"
    o.separator "mthdspool -o String -f methods"
    o.separator "mthdspool -o \\$stderr -f methods"
    o.separator "mthdspool -i CONST -r ~/code/app/lib/app/test/test_helper.rb"
  end
  opts.parse!(argv) rescue return $stderr.puts(opts)
  prnt = Mthds.new(options)
  case
  when options.has_key?(:obj);  prnt.objects_methods
  when options.has_key?(:nspct); prnt.inspect_instance
  end
end