Class: Pwl::Commands::Init
Instance Method Summary collapse
Methods inherited from Base
default_locker_file, exit_codes_help
Instance Method Details
#call(args, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pwl/commands/init.rb', line 4 def call(args, ) locker_file = locker_file(, true) msg "Attempting to initialize new locker at #{locker_file}" if .verbose # Locker checks this too, but we want to fail fast. exit_with(:is_dir, .verbose, :file => locker_file) if File.exists?(locker_file) && File.directory?(locker_file) exit_with(:file_exists, .verbose, :file => locker_file) if File.exists?(locker_file) && !.force begin begin master_password = get_password('Enter new master password:', .gui) end while begin validate!(master_password) # Basic idea from http://stackoverflow.com/questions/136793/is-there-a-do-while-loop-in-ruby rescue Pwl::InvalidMasterPasswordError => e msg e. .gui || STDIN.tty? # only continue the loop when in interactive mode end # Ask for password confirmation if running in interactive mode (terminal) if STDIN.tty? && master_password != get_password('Enter master password again:', .gui) exit_with(:passwords_dont_match, .verbose) end rescue Pwl::Dialog::Cancelled exit_with(:aborted, .verbose) end new_locker(, master_password) msg "Successfully initialized new locker at #{locker_file}" if .verbose end |