lib/rubocop/stylecheck/cli.rb in rubocop-stylecheck-0.1.1 vs lib/rubocop/stylecheck/cli.rb in rubocop-stylecheck-0.1.2
- old
+ new
@@ -1,8 +1,37 @@
module Rubocop
module Stylecheck
module Cli
class << self
+ def run(options)
+ if Rubocop::Stylecheck.direct
+ direct_run(options)
+ else
+ run_via_sh(options)
+ end
+ end
+
+ def direct_run(options)
+ require "rubocop"
+ require "benchmark"
+
+ cli = RuboCop::CLI.new
+ result = 0
+
+ time = Benchmark.realtime do
+ result = cli.run(options)
+ end
+
+ puts "Finished in #{time} seconds" if cli.options[:debug]
+ exit result
+ end
+
+ def run_via_sh(options)
+ system "bundle exec rubocop #{options.join(' ')}" do |ok, _res|
+ abort "Fix code style errors" unless ok
+ end
+ end
+
def options
options = ["--fail-level", "refactor"]
options += ["--rails"] if defined?(Rails)
options
end