Class: Rails::Worktrees::Command

Inherits:
Object
  • Object
show all
Includes:
EnvironmentSupport, GitOperations, NamePicking, Output, PostCreateSupport, WorkspacePaths
Defined in:
lib/rails/worktrees/command.rb,
lib/rails/worktrees/command/output.rb,
lib/rails/worktrees/command/name_picking.rb,
lib/rails/worktrees/command/git_operations.rb,
lib/rails/worktrees/command/workspace_paths.rb,
lib/rails/worktrees/command/environment_support.rb,
lib/rails/worktrees/command/post_create_support.rb

Overview

Creates or attaches worktrees for the current repository. rubocop:disable Metrics/ClassLength

Defined Under Namespace

Modules: EnvironmentSupport, GitOperations, NamePicking, Output, PostCreateSupport, WorkspacePaths

Constant Summary collapse

REMOVE_SUBCOMMANDS =
%w[remove delete].freeze
DOCTOR_SUBCOMMAND =
'doctor'.freeze
SETUP_SUBCOMMAND =
'setup'.freeze
UPDATE_SUBCOMMAND =
'update'.freeze

Constants included from NamePicking

NamePicking::FILE_ENCODING

Constants included from GitOperations

GitOperations::GIT_REPOSITORY_ENV_KEYS

Instance Method Summary collapse

Constructor Details

#initialize(argv:, io:, env:, cwd:, configuration:) ⇒ Command

Returns a new instance of Command.



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/worktrees/command.rb', line 26

def initialize(argv:, io:, env:, cwd:, configuration:)
  @argv = argv.dup
  @stdin = io.fetch(:stdin)
  @stdout = io.fetch(:stdout)
  @stderr = io.fetch(:stderr)
  @env = env
  @cwd = cwd
  @configuration = configuration
  extract_flags!
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
# File 'lib/rails/worktrees/command.rb', line 37

def run
  meta_command_result = handle_meta_command
  return meta_command_result unless meta_command_result.nil?

  execute_requested_command
rescue Error => e
  @stderr.puts("Error: #{e.message}")
  1
end