Class: Ec2ssh::Command::Migrate

Inherits:
Base
  • Object
show all
Defined in:
lib/ec2ssh/command/migrate.rb

Instance Attribute Summary

Attributes inherited from Base

#cli

Instance Method Summary collapse

Methods inherited from Base

#dotfile, #dotfile_path, #ssh_config_path

Constructor Details

#initialize(cli) ⇒ Migrate

Returns a new instance of Migrate.



8
9
10
# File 'lib/ec2ssh/command/migrate.rb', line 8

def initialize(cli)
  super
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ec2ssh/command/migrate.rb', line 12

def run
  migrator = Migrator.new dotfile_path
  version = migrator.check_version
  case version
  when '2'
    cli.red "Current dotfile version is #{version} (#{dotfile_path})"
    new_dotfile_str = migrator.migrate_from_2
    cli.red "Ec2ssh is migrating your dotfile to version 3 style as follows:"
    cli.yellow new_dotfile_str
    if cli.yes? "Are you sure to migrate #{dotfile_path} to version 3 style? (y/n)"
      backup_path = migrator.backup!
      puts "Creating backup as #{backup_path}"
      migrator.replace! new_dotfile_str
      cli.green 'Migrated successfully.'
    end
  when '3'
    cli.green "Current dotfile version is #{version} (#{dotfile_path})"
    cli.green 'Your dotfile is up-to-date.'
  end
end