Class: JRuby::Lint::CLI
- Inherits:
-
Object
- Object
- JRuby::Lint::CLI
- Defined in:
- lib/jruby/lint/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #process_options(args) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
6 7 8 |
# File 'lib/jruby/lint/cli.rb', line 6 def initialize(args) (args) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/jruby/lint/cli.rb', line 4 def @options end |
Instance Method Details
#process_options(args) ⇒ Object
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/jruby/lint/cli.rb', line 10 def (args) require 'optparse' require 'ostruct' @options = OpenStruct.new OptionParser.new do |opts| opts. = "Usage: jrlint [options] [files]" opts.separator "" opts.separator "Options:" opts.on('-C', '--chdir DIRECTORY', "Change working directory") do |v| Dir.chdir(v) end opts.on("-e", '--eval SCRIPT', "Lint an inline script") do |v| @options.eval ||= [] @options.eval << v end opts.on("-t", "--tag TAG", "Report findings tagged with TAG") do |v| @options. ||= [] @options. << v end opts.on('--text', 'print report as text') do @options.text = true end opts.on('--ansi', 'print report as ansi text') do @options.ansi = true end opts.on('--html [REPORT_FILE]', 'print report as html file') do |file| @options.html = file || 'jruby-lint.html' end opts.on_tail("-v", "--version", "Print version and exit") do require 'jruby/lint/version' puts "JRuby-Lint version #{VERSION}" exit end opts.on_tail("-h", "--help", "This message") do puts opts exit end end.parse!(args) @options.files = args.empty? ? nil : args end |
#run ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jruby/lint/cli.rb', line 60 def run require 'jruby/lint' require 'benchmark' project = JRuby::Lint::Project.new(@options) puts "JRuby-Lint version #{JRuby::Lint::VERSION}" time = Benchmark.realtime { project.run } term = @options.eval ? 'expression' : 'file' puts "Processed #{project.files.size} #{term}#{project.files.size == 1 ? '' : 's'} in #{'%0.02f' % time} seconds" if project.findings.empty? puts "OK" exit else puts "Found #{project.findings.size} items" exit 1 end end |