Class: Dash::Cli::Main::Migrate

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/cli/main/migrate.rb

Overview

Moves a project from the legacy .kamal directory to .dash. Purely local - it never opens an SSH connection and never reads deploy.yml - and only ever runs when the operator asks for it, because silently rewriting someone's working tree is not a deploy tool's job.

Returns [message, color] pairs rather than printing: output belongs to the Thor command, and reaching into the Thor instance for say couples this class to a shell helper whose visibility changes between Thor versions.

Constant Summary collapse

CURRENT =
Dash::ProjectDirectory::CURRENT
LEGACY =
Dash::ProjectDirectory::LEGACY
LEGACY_ENV_PATTERN =
/\bKAMAL_[A-Z0-9_]+/
EXTRA_SCANNED_FILES =
[ "config/deploy.yml" ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dry_run: false) ⇒ Migrate

Returns a new instance of Migrate.



20
21
22
# File 'lib/dash/cli/main/migrate.rb', line 20

def initialize(dry_run: false)
  @dry_run = dry_run
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run.



18
19
20
# File 'lib/dash/cli/main/migrate.rb', line 18

def dry_run
  @dry_run
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dash/cli/main/migrate.rb', line 24

def run
  return [ [ "No #{LEGACY} directory to migrate.", nil ] ] unless Dir.exist?(LEGACY)

  if Dir.exist?(CURRENT)
    return [ [ "Both #{CURRENT} and #{LEGACY} exist. Merge them by hand, then remove #{LEGACY}.", :yellow ] ]
  end

  if dry_run
    [ [ "Would move #{LEGACY} to #{CURRENT}#{" with git mv" if tracked_by_git?}", nil ], *legacy_env_reference_lines ]
  else
    move
    [ [ "Moved #{LEGACY} to #{CURRENT}", :green ], *legacy_env_reference_lines ]
  end
end