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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/codetip/app/commander.rb', line 17
def run(argv = ARGV)
begin
opts = {}
if argv.length > 0
loop {
case argv[0]
when /^-(h|-help)$/i then
argv.shift
puts "Usage: codetip [options] <location>"
puts
puts "Options:"
puts "\t-h, --help\tDisplays what you are looking at"
puts "\t-r, --restrict\tRestrict file search. e.g, '.js' or '*.{js,cpp}'"
puts "\t-u, --username\tOnly display comments mentioning username"
puts
puts "Example:"
puts "\tcodetip --username='kurt_wagner' -r '*.{js,pl}' ~/path/to/project"
puts
return
when /^-(r|-opts[:restrict])(=(.+))?$/i then
if !$3.nil?
opts[:restrict] = $3
argv.shift
else
argv.shift
opts[:restrict] = argv.shift
end
when /^-(u|-username)(=(.+))?$/i then
if !$3.nil?
opts[:username] = $3
argv.shift
else
argv.shift
opts[:username] = argv.shift
end
when /^-/ then
puts "Unknown option: #{argv.shift}"
else
directory = argv.shift
opts[:path] = directory.gsub(/\/+$/, '') if !directory.nil?
break
end
}
end
parse(opts[:path] || '.', opts[:restrict] || "*", opts[:username]).each do |filename, types|
puts filename.red.bold;
types.each do |type, |
if .count > 0
puts "[ #{type.upcase} ]".blue.bold
.each do ||
puts " Line #{[:line]} - ".gray + [:message].highlightMessage
end
puts
end
end
end
rescue Exception => e
puts e.message
end
end
|