Class: CodeWeb::CLI
- Inherits:
-
Object
- Object
- CodeWeb::CLI
- Defined in:
- lib/code_web/cli.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Array<String>
Command line arguments.
-
#class_map ⇒ Map<Regexp,html_class>
Files/directories with specal emphasis.
-
#code_parser ⇒ Object
Returns the value of attribute code_parser.
-
#filenames ⇒ Array<String>
Regular expression filenames.
-
#output ⇒ Object
Returns the value of attribute output.
-
#report_generator ⇒ Object
Class that runs the report (i.e.: TextReport, HtmlReport).
Class Method Summary collapse
Instance Method Summary collapse
- #arg_regex ⇒ Object
- #arg_regex=(val) ⇒ Object
- #debug=(val) ⇒ Object
- #debug? ⇒ Boolean
- #display_results ⇒ Object
- #exit_on_error=(val) ⇒ Object
- #files_parsed ⇒ Object
-
#initialize(arguments) ⇒ CLI
constructor
A new instance of CLI.
- #method_calls ⇒ Object
- #method_regex=(val) ⇒ Object
- #parse_arguments ⇒ Object
- #parse_files ⇒ Object
- #run ⇒ Object
- #verbose=(val) ⇒ Object
Constructor Details
#initialize(arguments) ⇒ CLI
Returns a new instance of CLI.
38 39 40 41 42 |
# File 'lib/code_web/cli.rb', line 38 def initialize(arguments) @arguments = arguments @code_parser = CodeWeb::CodeParser.new @class_map = {} end |
Instance Attribute Details
#arguments ⇒ Array<String>
Returns command line arguments.
30 31 32 |
# File 'lib/code_web/cli.rb', line 30 def arguments @arguments end |
#class_map ⇒ Map<Regexp,html_class>
Returns files/directories with specal emphasis.
26 27 28 |
# File 'lib/code_web/cli.rb', line 26 def class_map @class_map end |
#code_parser ⇒ Object
Returns the value of attribute code_parser.
9 10 11 |
# File 'lib/code_web/cli.rb', line 9 def code_parser @code_parser end |
#filenames ⇒ Array<String>
Returns regular expression filenames.
34 35 36 |
# File 'lib/code_web/cli.rb', line 34 def filenames @filenames end |
#output ⇒ Object
Returns the value of attribute output.
36 37 38 |
# File 'lib/code_web/cli.rb', line 36 def output @output end |
#report_generator ⇒ Object
Returns class that runs the report (i.e.: TextReport, HtmlReport).
22 23 24 |
# File 'lib/code_web/cli.rb', line 22 def report_generator @report_generator end |
Class Method Details
.parse(args) ⇒ Object
5 6 7 |
# File 'lib/code_web/cli.rb', line 5 def self.parse(args) new(args).run end |
Instance Method Details
#arg_regex ⇒ Object
12 |
# File 'lib/code_web/cli.rb', line 12 def arg_regex ; code_parser.arg_regex ; end |
#arg_regex=(val) ⇒ Object
14 |
# File 'lib/code_web/cli.rb', line 14 def arg_regex=(val) ; code_parser.arg_regex = val ; end |
#debug=(val) ⇒ Object
17 |
# File 'lib/code_web/cli.rb', line 17 def debug=(val) ; code_parser.debug = val ; end |
#debug? ⇒ Boolean
18 |
# File 'lib/code_web/cli.rb', line 18 def debug? ; code_parser.debug? ; end |
#display_results ⇒ Object
96 97 98 99 |
# File 'lib/code_web/cli.rb', line 96 def display_results STDOUT.puts "parsed #{files_parsed} files" report_generator.new(method_calls, class_map, arg_regex, output).report end |
#exit_on_error=(val) ⇒ Object
15 |
# File 'lib/code_web/cli.rb', line 15 def exit_on_error=(val) ; code_parser.exit_on_error = val ; end |
#files_parsed ⇒ Object
11 |
# File 'lib/code_web/cli.rb', line 11 def files_parsed ; code_parser.file_count ; end |
#method_calls ⇒ Object
10 |
# File 'lib/code_web/cli.rb', line 10 def method_calls ; code_parser.method_calls ; end |
#method_regex=(val) ⇒ Object
13 |
# File 'lib/code_web/cli.rb', line 13 def method_regex=(val) ; code_parser.method_regex = val ; end |
#parse_arguments ⇒ Object
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 |
# File 'lib/code_web/cli.rb', line 50 def parse_arguments #defaults self.report_generator = ::CodeWeb::HtmlReport self.output = STDOUT #parsing the command line OptionParser.new do |opt| opt. = "Usage: code_web regex [file_name ...]" # opt.on('-n', '--requests=count', Integer, "Number of requests (default: #{requests})") { |v| options[:requests] = v } opt.on('-t', '--text', 'Use text reports') { |v| self.report_generator = ::CodeWeb::TextReport } opt.on('-a', '--arg ARG_REGEX', 'Only files with hash argument') { |v| self.arg_regex = Regexp.new(v) } opt.on('-o', '--output FILENAME', 'Output filename') { |v| self.output = (v == '-') ? STDOUT : File.new(v,'w') } opt.on('-e', '--error-out', 'exit on unknown tags') { |v| self.exit_on_error = true} opt.on('-V', '--verbose', 'verbose parsing') { |v| self.verbose = true} opt.on('-D', '--debug', 'debug parsing') { |v| self.debug = true} opt.on('-p', '--pattern FILENAME_REGEX=COLOR','color to emphasize a file') { |v| v = v.split('=') ; self.class_map[Regexp.new(v.first)] = v.last } opt.on('--byebug') { require "byebug" } opt.on('--pry') { require "pry" } opt.on_tail("-h", "--help", "Show this message") { puts opt ; exit } opt.on_tail("-v", "--version", "Show version_information") { puts "Code Web version #{CodeWeb::VERSION}" ; exit } opt.parse!(arguments) if arguments.length == 0 puts opt exit end end self.method_regex = Regexp.new(arguments[0]) self.filenames = arguments[1..-1] || "." end |
#parse_files ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/code_web/cli.rb', line 81 def parse_files filenames.each do |arg| arg = "#{arg}/**/*.rb" if Dir.exists?(arg) if File.exist?(arg) puts arg if debug? code_parser.parse arg else Dir[arg].each do |file_name| puts arg if debug? code_parser.parse(file_name) end end end end |
#run ⇒ Object
44 45 46 47 48 |
# File 'lib/code_web/cli.rb', line 44 def run parse_arguments parse_files display_results end |
#verbose=(val) ⇒ Object
16 |
# File 'lib/code_web/cli.rb', line 16 def verbose=(val) ; code_parser.verbose = val ; end |