Class: RuboCop::CLI
- Inherits:
-
Object
- Object
- RuboCop::CLI
- Defined in:
- lib/rubocop/cli.rb
Overview
The CLI is a class responsible of handling all the command line interface logic.
Instance Attribute Summary collapse
-
#config_store ⇒ Object
readonly
Returns the value of attribute config_store.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
-
#run(args = ARGV) ⇒ Fixnum
Entry point for the application logic.
- #trap_interrupt(runner) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 |
# File 'lib/rubocop/cli.rb', line 9 def initialize @options = {} @config_store = ConfigStore.new end |
Instance Attribute Details
#config_store ⇒ Object (readonly)
Returns the value of attribute config_store.
7 8 9 |
# File 'lib/rubocop/cli.rb', line 7 def config_store @config_store end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/rubocop/cli.rb', line 7 def @options end |
Instance Method Details
#run(args = ARGV) ⇒ Fixnum
Entry point for the application logic. Here we do the command line arguments processing and inspect the target files
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubocop/cli.rb', line 18 def run(args = ARGV) @options, paths = Options.new.parse(args) runner = Runner.new(@options, @config_store) trap_interrupt(runner) all_passed = runner.run(paths) display_error_summary(runner.errors) all_passed && !runner.aborting? ? 0 : 1 rescue Cop::AmbiguousCopName => e $stderr.puts "Ambiguous cop name #{e.} needs namespace " \ 'qualifier.' return 1 rescue => e $stderr.puts e. $stderr.puts e.backtrace return 1 end |
#trap_interrupt(runner) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cli.rb', line 38 def trap_interrupt(runner) Signal.trap('INT') do exit!(1) if runner.aborting? runner.abort $stderr.puts $stderr.puts 'Exiting... Interrupt again to exit immediately.' end end |