Class: RuboCop::Server::CLI Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/server/cli.rb |
Overview
The CLI is a class responsible of handling server command line interface logic.
Constant Summary
-
EXCLUSIVE_OPTIONS =
# File 'lib/rubocop/server/cli.rb', line 33(SERVER_OPTIONS - %w[--server --no-server]).freeze
-
NO_DETACH_OPTIONS =
# File 'lib/rubocop/server/cli.rb', line 34%w[--server --start-server --restart-server].freeze
-
SERVER_OPTIONS =
# File 'lib/rubocop/server/cli.rb', line 24%w[ --server --no-server --server-status --restart-server --start-server --stop-server --no-detach ].freeze
-
STATUS_ERROR =
# File 'lib/rubocop/server/cli.rb', line 222
-
STATUS_SUCCESS =
Same exit status value as
::RuboCop::CLI
.0
Class Method Summary
- .new ⇒ CLI constructor Internal use only
Instance Attribute Summary
- #exit? ⇒ Boolean readonly Internal use only
Instance Method Summary
- #run(argv = ARGV) Internal use only
- #allowed_option_count private Internal use only
- #delete_server_argument_from(all_arguments) private Internal use only
- #error(message) private Internal use only
-
#fetch_cache_root_path_from(arguments)
private
Internal use only
Metrics/MethodLength:
-
#process_arguments(argv)
private
Internal use only
Metrics/CyclomaticComplexity, Metrics/MethodLength.
-
#run_command(server_command, detach:)
private
Internal use only
Metrics/MethodLength:
- #use_server_option?(argv) ⇒ Boolean private Internal use only
Instance Attribute Details
#exit? ⇒ Boolean
(readonly)
# File 'lib/rubocop/server/cli.rb', line 52
def exit? @exit end
Instance Method Details
#allowed_option_count (private)
[ GitHub ]# File 'lib/rubocop/server/cli.rb', line 133
def allowed_option_count Cache.cache_root_path ? 2 : 1 end
#delete_server_argument_from(all_arguments) (private)
[ GitHub ]# File 'lib/rubocop/server/cli.rb', line 123
def delete_server_argument_from(all_arguments) SERVER_OPTIONS.each_with_object([]) do |server_option, server_arguments| server_arguments << all_arguments.delete(server_option) end.compact end
#error(message) (private)
[ GitHub ]# File 'lib/rubocop/server/cli.rb', line 137
def error( ) require 'rainbow' @exit = true warn Rainbow( ).red STATUS_ERROR end
#fetch_cache_root_path_from(arguments) (private)
Metrics/MethodLength:
# File 'lib/rubocop/server/cli.rb', line 112
def fetch_cache_root_path_from(arguments) cache_root = arguments.detect { |argument| argument.start_with?('--cache-root') } return unless cache_root if cache_root.start_with?('--cache-root=') cache_root.split('=')[1] else arguments[arguments.index(cache_root) + 1] end end
#process_arguments(argv) (private)
Metrics/CyclomaticComplexity, Metrics/MethodLength
# File 'lib/rubocop/server/cli.rb', line 59
def process_arguments(argv) server_arguments = delete_server_argument_from(argv) detach = !server_arguments.delete('--no-detach') if server_arguments.size >= 2 return error("#{server_arguments.join(', ')} cannot be specified together.") end server_command = server_arguments.first unless detach || NO_DETACH_OPTIONS.include?(server_command) return error("#{server_command} cannot be combined with --no-detach.") end if EXCLUSIVE_OPTIONS.include?(server_command) && argv.count > allowed_option_count return error("#{server_command} cannot be combined with #{argv[0]}.") end if server_command.nil? server_command = ArgumentsEnv.read_as_arguments.delete('--server') || ArgumentsFile.read_as_arguments.delete('--server') end run_command(server_command, detach: detach) STATUS_SUCCESS end
#run(argv = ARGV)
[ GitHub ]# File 'lib/rubocop/server/cli.rb', line 40
def run(argv = ARGV) unless Server.support_server? return error('RuboCop server is not supported by this Ruby.') if use_server_option?(argv) return STATUS_SUCCESS end Cache.cache_root_path = fetch_cache_root_path_from(argv) process_arguments(argv) end
#run_command(server_command, detach:) (private)
Metrics/MethodLength:
# File 'lib/rubocop/server/cli.rb', line 90
def run_command(server_command, detach:) case server_command when '--server' Server::ClientCommand::Start.new(detach: detach).run unless Server.running? when '--no-server' Server::ClientCommand::Stop.new.run if Server.running? when '--restart-server' @exit = true Server::ClientCommand::Restart.new.run when '--start-server' @exit = true Server::ClientCommand::Start.new(detach: detach).run when '--stop-server' @exit = true Server::ClientCommand::Stop.new.run when '--server-status' @exit = true Server::ClientCommand::Status.new.run end end
#use_server_option?(argv) ⇒ Boolean
(private)
# File 'lib/rubocop/server/cli.rb', line 129
def use_server_option?(argv) (argv & SERVER_OPTIONS).any? end