Class: EasyAI::Command::Backup::Claude
- Inherits:
-
EasyAI::Command::Backup
- Object
- CLAide::Command
- EasyAI::Command
- EasyAI::Command::Backup
- EasyAI::Command::Backup::Claude
- Defined in:
- lib/easyai/command/backup/claude.rb
Constant Summary collapse
- SOURCE_PATH =
File.('~/.claude.json').freeze
- BACKUP_DIR =
File.('~/.easyai/backup').freeze
- BACKUP_PATH =
File.join(BACKUP_DIR, '.claude.json').freeze
- EXCLUDED_KEYS =
%w[projects].freeze
- KEYCHAIN_LABEL =
'Claude Code-credentials'.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
Instance Method Summary collapse
Methods inherited from EasyAI::Command
Constructor Details
This class inherits a constructor from EasyAI::Command
Instance Method Details
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/easyai/command/backup/claude.rb', line 42 def run source = read_json(SOURCE_PATH) EXCLUDED_KEYS.each { |key| source.delete(key) } keychain_value = read_keychain_credential(KEYCHAIN_LABEL) if keychain_value source[KEYCHAIN_BACKUP_KEY] = { KEYCHAIN_LABEL => keychain_value } end target = File.exist?(BACKUP_PATH) ? read_json(BACKUP_PATH) : {} before_keys = target.keys merged = deep_merge(target, source) FileUtils.mkdir_p(BACKUP_DIR) File.write(BACKUP_PATH, JSON.pretty_generate(merged)) File.chmod(0o600, BACKUP_PATH) unless windows? report(before_keys, source.keys, merged.keys, keychain_value) end |
#validate! ⇒ Object
37 38 39 40 |
# File 'lib/easyai/command/backup/claude.rb', line 37 def validate! super help! "源文件不存在: #{SOURCE_PATH}\n请先登录 Claude Code 后再备份。" unless File.exist?(SOURCE_PATH) end |