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
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/codesake/cli.rb', line 9
def parse(command_line)
@options = {}
return {:vulnerabilities=>:all} if (command_line.nil?) or (command_line.send(:empty?))
begin
option_parser =OptionParser.new do |opts|
executable_name = File.basename($PROGRAM_NAME)
opts.banner =
"codesake v#{Codesake::VERSION} - (C) 2012 - [email protected]\nReviews one or more source file for security issues.\n\nUsage #{executable_name} [options] sources\n"
opts.on("-v", "--version", "Show codesake version") do
@options[:version] = true
end
opts.on("-V", "--verbose", "Be verbose") do
@options[:verbose] = true
end
opts.on("-k KEYWORDS", "--add-keys", "Add the command separated list of strings as reserved keywords") do |val|
@options[:keywords] = val.trim.split(",")
end
opts.on("-o TARGET", "--output", "Write output to file, to json string or to db usin SQLite3") do |val|
@options[:output]=:screen
val=val.trim
@options[:output]=val.to_sym if (val.to_sym == :file) or (val.to_sym == :json) or (val.to_sym == :db)
end
opts.on("-C", "--confirmed-vulnerabilities", "Show only confirmed vulnerabilities") do
@options[:vulnerabilities] = :confirmed
end
opts.on("-A", "--all-vulnerabilities", "Show all vulnerabilities found [default]") do
@options[:vulnerabilities] = :all
end
end
rest = option_parser.parse(command_line)
@targets = []
@targets = build_target_list(rest[0].split(" ")) if expect_targets? and (! rest.empty?) and (! rest[0].nil?)
@options[:vulnerabilities] = :all if @options[:vulnerabilities].nil?
rescue OptionParser::InvalidOption => e
@options={:error=>true, :message=>e.message}
end
@options
end
|