Module: Lich::Common::CLI::CLIOrchestration
- Defined in:
- documented/common/cli/cli_orchestration.rb
Overview
Provides orchestration for CLI commands in the Lich application
Class Method Summary collapse
-
.check_conversion_needed_for_login ⇒ void
Checks if conversion is required before login.
-
.execute ⇒ void
Executes the CLI commands based on the provided arguments.
-
.handle_add_account ⇒ Integer
Handles the addition of a new account.
-
.handle_change_account_password ⇒ Integer
Handles the change of an account password.
-
.handle_change_encryption_mode ⇒ Integer
Handles the change of the encryption mode.
-
.handle_change_master_password ⇒ Integer
Handles the change of the master password.
-
.handle_convert_entries ⇒ Integer
Handles the conversion of entries to a specified encryption mode.
-
.handle_recover_master_password ⇒ Integer
Handles the recovery of the master password.
Class Method Details
.check_conversion_needed_for_login ⇒ void
This method returns an undefined value.
Checks if conversion is required before login.
50 51 52 53 54 55 56 |
# File 'documented/common/cli/cli_orchestration.rb', line 50 def self.check_conversion_needed_for_login # Check if conversion is required if Lich::Common::CLI::CLIConversion.conversion_needed?(DATA_DIR) Lich::Common::CLI::CLIConversion. exit 1 end end |
.execute ⇒ void
This method returns an undefined value.
Executes the CLI commands based on the provided arguments.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'documented/common/cli/cli_orchestration.rb', line 20 def self.execute ARGV.each do |arg| case arg when /^--change-account-password$/, /^-cap$/ handle_change_account_password when /^--add-account$/, /^-aa$/ handle_add_account when /^--change-master-password$/, /^-cmp$/ handle_change_master_password when /^--recover-master-password$/, /^-rmp$/ handle_recover_master_password when /^--convert-entries$/ handle_convert_entries when /^--change-encryption-mode$/, /^-cem$/ handle_change_encryption_mode end end # Check for conversion needed before login attempt # This is not an early-exit operation - it detects a precondition for login if ARGV.include?('--login') check_conversion_needed_for_login end end |
.handle_add_account ⇒ Integer
Handles the addition of a new account.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'documented/common/cli/cli_orchestration.rb', line 89 def self.handle_add_account idx = ARGV.index { |a| a =~ /^--add-account$|^-aa$/ } account = ARGV[idx + 1] password = ARGV[idx + 2] if account.nil? || password.nil? lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts 'error: Missing required arguments' $stdout.puts "Usage: ruby #{lich_script} --add-account ACCOUNT PASSWORD [--frontend FRONTEND]" $stdout.puts " or: ruby #{lich_script} -aa ACCOUNT PASSWORD [--frontend FRONTEND]" exit 1 end frontend = ARGV[ARGV.index('--frontend') + 1] if ARGV.include?('--frontend') exit Lich::Common::CLI::PasswordManager.add_account(account, password, frontend) end |
.handle_change_account_password ⇒ Integer
Handles the change of an account password.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'documented/common/cli/cli_orchestration.rb', line 65 def self.handle_change_account_password idx = ARGV.index { |a| a =~ /^--change-account-password$|^-cap$/ } account = ARGV[idx + 1] new_password = ARGV[idx + 2] if account.nil? || new_password.nil? lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts 'error: Missing required arguments' $stdout.puts "Usage: ruby #{lich_script} --change-account-password ACCOUNT NEWPASSWORD" $stdout.puts " or: ruby #{lich_script} -cap ACCOUNT NEWPASSWORD" exit 1 end exit Lich::Common::CLI::PasswordManager.change_account_password(account, new_password) end |
.handle_change_encryption_mode ⇒ Integer
Handles the change of the encryption mode.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'documented/common/cli/cli_orchestration.rb', line 206 def self.handle_change_encryption_mode idx = ARGV.index { |a| a =~ /^--change-encryption-mode$|^-cem$/ } mode_arg = ARGV[idx + 1] if mode_arg.nil? lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts 'error: Missing encryption mode' $stdout.puts "Usage: ruby #{lich_script} --change-encryption-mode MODE [--master-password PASSWORD]" $stdout.puts " ruby #{lich_script} -cem MODE [-mp PASSWORD]" $stdout.puts 'Modes: plaintext, standard, enhanced' exit 1 end new_mode = mode_arg.to_sym # Check for optional master password (for Enhanced mode, if automating) mp_index = ARGV.index('--master-password') || ARGV.index('-mp') master_password = ARGV[mp_index + 1] if mp_index exit Lich::Common::CLI::EncryptionModeChange.change_mode(new_mode, master_password) end |
.handle_change_master_password ⇒ Integer
Handles the change of the master password.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'documented/common/cli/cli_orchestration.rb', line 113 def self.handle_change_master_password idx = ARGV.index { |a| a =~ /^--change-master-password$|^-cmp$/ } old_password = ARGV[idx + 1] new_password = ARGV[idx + 2] if old_password.nil? lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts 'error: Missing required arguments' $stdout.puts "Usage: ruby #{lich_script} --change-master-password OLDPASSWORD [NEWPASSWORD]" $stdout.puts " or: ruby #{lich_script} -cmp OLDPASSWORD [NEWPASSWORD]" $stdout.puts 'Note: If NEWPASSWORD is not provided, you will be prompted for confirmation' exit 1 end exit Lich::Common::CLI::PasswordManager.change_master_password(old_password, new_password) end |
.handle_convert_entries ⇒ Integer
Handles the conversion of entries to a specified encryption mode.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'documented/common/cli/cli_orchestration.rb', line 149 def self.handle_convert_entries idx = ARGV.index('--convert-entries') encryption_mode_str = ARGV[idx + 1] if encryption_mode_str.nil? lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts 'error: Missing required argument' $stdout.puts "Usage: ruby #{lich_script} --convert-entries [plaintext|standard|enhanced]" exit 1 end unless %w[plaintext standard enhanced].include?(encryption_mode_str) $stdout.puts "error: Invalid encryption mode: #{encryption_mode_str}" $stdout.puts 'Valid modes: plaintext, standard, enhanced' exit 1 end # For enhanced mode, prompt for master password and store in keychain before conversion # This way migrate_from_legacy will find it in keychain and not try to show GUI dialog if encryption_mode_str == 'enhanced' master_password = Lich::Common::CLI::PasswordManager.prompt_and_confirm_password('Enter new master password for enhanced encryption') if master_password.nil? puts 'error: Master password creation cancelled' exit 1 end # Store password in keychain so ensure_master_password_exists finds it require_relative '../gui/master_password_manager' stored = Lich::Common::GUI::MasterPasswordManager.store_master_password(master_password) unless stored puts 'error: Failed to store master password in keychain' exit 1 end end # Perform conversion success = Lich::Common::CLI::CLIConversion.convert( DATA_DIR, encryption_mode_str ) if success $stdout.puts 'Conversion completed successfully!' exit 0 else $stdout.puts 'Conversion failed. Please check the logs for details.' exit 1 end end |
.handle_recover_master_password ⇒ Integer
Handles the recovery of the master password.
135 136 137 138 139 140 141 |
# File 'documented/common/cli/cli_orchestration.rb', line 135 def self.handle_recover_master_password idx = ARGV.index { |a| a =~ /^--recover-master-password$|^-rmp$/ } new_password = ARGV[idx + 1] # new_password is optional - if not provided, user will be prompted interactively exit Lich::Common::CLI::PasswordManager.recover_master_password(new_password) end |