Class: EasyAI::Command::Restore::Claude

Inherits:
EasyAI::Command::Restore show all
Defined in:
lib/easyai/command/restore/claude.rb

Constant Summary collapse

BACKUP_PATH =
File.expand_path('~/.easyai/backup/.claude.json').freeze
TARGET_PATH =
File.expand_path('~/.claude.json').freeze
KEYCHAIN_BACKUP_KEY =
'_easyai_keychain'.freeze

Constants inherited from EasyAI::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from EasyAI::Command

#args_help_flag

Instance Method Summary collapse

Methods inherited from EasyAI::Command

#initialize, options, run

Constructor Details

This class inherits a constructor from EasyAI::Command

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/easyai/command/restore/claude.rb', line 40

def run
  source = read_json(BACKUP_PATH)

  keychain_results = restore_keychain(source.delete(KEYCHAIN_BACKUP_KEY))

  target = File.exist?(TARGET_PATH) ? read_json(TARGET_PATH) : {}
  before_keys = target.keys

  merged = deep_merge(target, source)

  File.write(TARGET_PATH, JSON.pretty_generate(merged))
  File.chmod(0o600, TARGET_PATH) unless windows?

  report(before_keys, source.keys, merged.keys, keychain_results)
end

#validate!Object



35
36
37
38
# File 'lib/easyai/command/restore/claude.rb', line 35

def validate!
  super
  help! "备份文件不存在: #{BACKUP_PATH}\n请先运行 easyai backup claude 创建备份。" unless File.exist?(BACKUP_PATH)
end