Class: RuboCop::CLI
- Inherits:
-
Object
- Object
- RuboCop::CLI
- Includes:
- Formatter::TextUtil
- Defined in:
- lib/rubocop/cli.rb
Overview
The CLI is a class responsible of handling all the command line interface logic.
Defined Under Namespace
Classes: Finished
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
Methods included from Formatter::TextUtil
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.
12 13 14 |
# File 'lib/rubocop/cli.rb', line 12 def config_store @config_store end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/rubocop/cli.rb', line 12 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
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) @options, paths = Options.new.parse(args) apply_default_formatter runner = Runner.new(@options, @config_store) trap_interrupt(runner) all_passed = runner.run(paths) display_warning_summary(runner.warnings) display_error_summary(runner.errors) maybe_print_corrected_source all_passed && !runner.aborting? && runner.errors.empty? ? 0 : 1 rescue RuboCop::Error => e $stderr.puts Rainbow("Error: #{e.}").red return 2 rescue Finished return 0 rescue StandardError, SyntaxError => e $stderr.puts e. $stderr.puts e.backtrace return 2 end |
#trap_interrupt(runner) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cli.rb', line 47 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 |