Class: RuboCop::CLI
- Inherits:
-
Object
- Object
- RuboCop::CLI
- Defined in:
- lib/rubocop/cli.rb,
lib/rubocop/cli/command.rb,
lib/rubocop/cli/command/lsp.rb,
lib/rubocop/cli/environment.rb,
lib/rubocop/cli/command/base.rb,
lib/rubocop/cli/command/version.rb,
lib/rubocop/cli/command/show_cops.rb,
lib/rubocop/cli/command/init_dotfile.rb,
lib/rubocop/cli/command/show_docs_url.rb,
lib/rubocop/cli/command/execute_runner.rb,
lib/rubocop/cli/command/suggest_extensions.rb,
lib/rubocop/cli/command/auto_generate_config.rb
Overview
The CLI is a class responsible of handling all the command line interface logic.
Defined Under Namespace
Modules: Command Classes: Environment, Finished
Constant Summary collapse
- STATUS_SUCCESS =
0
- STATUS_OFFENSES =
1
- STATUS_ERROR =
2
- STATUS_INTERRUPTED =
Signal.list['INT'] + 128
- DEFAULT_PARALLEL_OPTIONS =
%i[ color config debug display_style_guide display_time display_only_fail_level_offenses display_only_failed editor_mode except extra_details fail_level fix_layout format ignore_disable_comments lint only only_guide_cops require safe autocorrect safe_autocorrect autocorrect_all ].freeze
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) ⇒ Integer
Entry point for the application logic.
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
24 25 26 27 |
# File 'lib/rubocop/cli.rb', line 24 def initialize @options = {} @config_store = ConfigStore.new end |
Instance Attribute Details
#config_store ⇒ Object (readonly)
Returns the value of attribute config_store.
22 23 24 |
# File 'lib/rubocop/cli.rb', line 22 def config_store @config_store end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/rubocop/cli.rb', line 22 def @options end |
Instance Method Details
#run(args = ARGV) ⇒ Integer
Entry point for the application logic. Here we do the command line arguments processing and inspect the target files.
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubocop/cli.rb', line 39 def run(args = ARGV) @options, paths = Options.new.parse(args) @env = Environment.new(@options, @config_store, paths) profile_if_needed do if @options[:init] run_command(:init) else parallel_by_default! apply_default_formatter execute_runners end end rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e warn e. STATUS_ERROR rescue RuboCop::Error => e warn Rainbow("Error: #{e.}").red STATUS_ERROR rescue Interrupt warn '' warn 'Exiting...' STATUS_INTERRUPTED rescue Finished STATUS_SUCCESS rescue OptionParser::InvalidOption => e warn e. warn 'For usage information, use --help' STATUS_ERROR rescue StandardError, SyntaxError, LoadError => e warn e. warn e.backtrace STATUS_ERROR end |