Module: Lich::Common::CLI::CLIConversion
- Defined in:
- documented/common/cli/cli_conversion.rb
Class Method Summary collapse
-
.conversion_needed?(data_dir) ⇒ Boolean
Checks if conversion is needed based on the presence of entry.dat and absence of entry.yaml.
-
.convert(data_dir, encryption_mode) ⇒ Boolean
Converts entry.dat to entry.yaml format with specified encryption mode.
-
.print_conversion_help_message ⇒ Object
Prints a help message for users regarding the conversion process.
Class Method Details
.conversion_needed?(data_dir) ⇒ Boolean
Checks if conversion is needed based on the presence of entry.dat and absence of entry.yaml
14 15 16 17 18 19 |
# File 'documented/common/cli/cli_conversion.rb', line 14 def self.conversion_needed?(data_dir) dat_file = File.join(data_dir, 'entry.dat') yaml_file = Lich::Common::GUI::YamlState.yaml_file_path(data_dir) File.exist?(dat_file) && !File.exist?(yaml_file) end |
.convert(data_dir, encryption_mode) ⇒ Boolean
Converts entry.dat to entry.yaml format with specified encryption mode
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'documented/common/cli/cli_conversion.rb', line 28 def self.convert(data_dir, encryption_mode) # Normalize encryption_mode to symbol if string is passed mode = encryption_mode.to_sym # Validate preconditions dat_file = File.join(data_dir, 'entry.dat') yaml_file = Lich::Common::GUI::YamlState.yaml_file_path(data_dir) unless File.exist?(dat_file) Lich.log "error: entry.dat not found at #{dat_file}" return false end if File.exist?(yaml_file) Lich.log "error: entry.yaml already exists at #{yaml_file}" return false end # Delegate to YamlState for the actual conversion # For enhanced mode, migrate_from_legacy will prompt user to create master password result = Lich::Common::GUI::YamlState.migrate_from_legacy(data_dir, encryption_mode: mode) unless result Lich.log "error: YamlState.migrate_from_legacy returned false" end result rescue StandardError => e Lich.log "error: Conversion failed: #{e.class}: #{e.}" Lich.log "error: Backtrace: #{e.backtrace.join("\n ")}" false end |
.print_conversion_help_message ⇒ Object
Prints a help message for users regarding the conversion process
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'documented/common/cli/cli_conversion.rb', line 64 def self. lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts "\n" + '=' * 80 $stdout.puts "Saved entries conversion required" $stdout.puts '=' * 80 $stdout.puts "\nYour login entries need to be converted to the new format." $stdout.puts "\nRun one of these commands:\n\n" $stdout.puts "For no encryption (least secure):" $stdout.puts " ruby #{lich_script} --convert-entries plaintext\n\n" $stdout.puts "For account-based encryption (standard):" $stdout.puts " ruby #{lich_script} --convert-entries standard\n\n" $stdout.puts "For master-password encryption (recommended):" $stdout.puts " ruby #{lich_script} --convert-entries enhanced\n\n" $stdout.puts '=' * 80 + "\n" end |