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.
-
#wants_to_quit ⇒ Object
(also: #wants_to_quit?)
If set true while running, RuboCop will abort processing and exit gracefully.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
-
#run(args = ARGV) ⇒ Fixnum
Entry point for the application logic.
- #trap_interrupt ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
14 15 16 17 |
# File 'lib/rubocop/cli.rb', line 14 def initialize @options = {} @config_store = ConfigStore.new end |
Instance Attribute Details
#config_store ⇒ Object (readonly)
Returns the value of attribute config_store.
10 11 12 |
# File 'lib/rubocop/cli.rb', line 10 def config_store @config_store end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/rubocop/cli.rb', line 10 def @options end |
#wants_to_quit ⇒ Object Also known as: wants_to_quit?
If set true while running, RuboCop will abort processing and exit gracefully.
9 10 11 |
# File 'lib/rubocop/cli.rb', line 9 def wants_to_quit @wants_to_quit 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cli.rb', line 23 def run(args = ARGV) trap_interrupt @options, remaining_args = Options.new.parse(args) target_files = target_finder.find(remaining_args) inspector = FileInspector.new(@options) any_failed = inspector.process_files(target_files, @config_store) do wants_to_quit? end inspector.display_error_summary !any_failed && !wants_to_quit ? 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 ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cli.rb', line 47 def trap_interrupt Signal.trap('INT') do exit!(1) if wants_to_quit? self.wants_to_quit = true $stderr.puts $stderr.puts 'Exiting... Interrupt again to exit immediately.' end end |