Class: RuboCop::Server::CLI Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/server/cli.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The CLI is a class responsible of handling server command line interface logic.

Constant Summary collapse

STATUS_SUCCESS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Same exit status value as RuboCop::CLI.

0
STATUS_ERROR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

2
SERVER_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[
  --server --no-server --server-status --restart-server --start-server --stop-server
].freeze
EXCLUSIVE_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

(SERVER_OPTIONS - %w[--server --no-server]).freeze

Instance Method Summary collapse

Constructor Details

#initializeCLI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CLI.



30
31
32
# File 'lib/rubocop/server/cli.rb', line 30

def initialize
  @exit = false
end

Instance Method Details

#exit?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength

Returns:

  • (Boolean)


66
67
68
# File 'lib/rubocop/server/cli.rb', line 66

def exit?
  @exit
end

#run(argv = ARGV) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength



35
36
37
38
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
# File 'lib/rubocop/server/cli.rb', line 35

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)
  deleted_server_arguments = delete_server_argument_from(argv)

  if deleted_server_arguments.size >= 2
    return error("#{deleted_server_arguments.join(', ')} cannot be specified together.")
  end

  server_command = deleted_server_arguments.first

  if EXCLUSIVE_OPTIONS.include?(server_command) && argv.count > allowed_option_count
    return error("#{server_command} cannot be combined with other options.")
  end

  if server_command.nil?
    server_command = ArgumentsEnv.read_as_arguments.delete('--server') ||
                     ArgumentsFile.read_as_arguments.delete('--server')
  end

  run_command(server_command)

  STATUS_SUCCESS
end