Top Level Namespace

Defined Under Namespace

Modules: Pwl Classes: Hash

Constant Summary collapse

EXIT_CODES =
{
  :success               => Pwl::Message.new('Success.'),
  :aborted               => Pwl::Message.new('Aborted by user.', 1),
  :passwords_dont_match  => Pwl::ErrorMessage.new('Passwords do not match.', 2),
  :no_value_found        => Pwl::Message.new('No value found for <%= name %>.', 3, :name => 'NAME'),
  :file_exists           => Pwl::ErrorMessage.new('There already exists a store at <%= file %>. Use --force to overwrite it or --file to specify a different store.', 4, :file => 'FILE'),
  :file_not_found        => Pwl::ErrorMessage.new('Store file <%= file %> could not be found.', 5, :file => 'FILE'),
  :name_blank            => Pwl::ErrorMessage.new('Name may not be blank.', 6),
  :value_blank           => Pwl::ErrorMessage.new('Value may not be blank.', 7),
  :list_empty            => Pwl::Message.new('List is empty.', 8),
  :list_empty_filter     => Pwl::Message.new('No names found that match filter <%= filter %>.', 9, :filter => 'FILTER'),
  :validation_new_failed => Pwl::ErrorMessage.new('<%= message %>.', 10, :message => 'Validation of new master password failed'),
}
DEFAULT_STORE_FILE =
File.expand_path("~/.#{program(:name)}.pstore")
DEFAULT_EXPORT_TEMPLATE =
File.join(File.dirname(__FILE__), *%w[.. templates export.html.erb])

Instance Method Summary collapse

Instance Method Details

#exit_with(error_code, verbose, msg_args = {}) ⇒ Object



247
248
249
250
251
252
253
254
255
256
# File 'bin/pwl', line 247

def exit_with(error_code, verbose, msg_args = {})
  msg = EXIT_CODES[error_code]
  raise "No message defined for error #{error_code}" if !msg

  if msg.error? || verbose # always print errors; messages only when verbose
    STDERR.puts msg.to_s(msg_args)
  end

  exit(msg.exit_code)
end

#get_password(prompt, gui = false) ⇒ Object



258
259
260
# File 'bin/pwl', line 258

def get_password(prompt, gui = false)
  (gui ? Pwl::Dialog::Password.new(program(:name), prompt) : Pwl::Dialog::ConsolePasswordDialog.new(prompt)).get_input
end

#get_text(prompt, gui = false) ⇒ Object



262
263
264
# File 'bin/pwl', line 262

def get_text(prompt, gui = false)
  (gui ? Pwl::Dialog::Text.new(program(:name), prompt) : Pwl::Dialog::ConsoleTextDialog.new(prompt)).get_input
end

#validate!(pwd) ⇒ Object



266
267
268
# File 'bin/pwl', line 266

def validate!(pwd)
  Pwl::Store.password_policy.validate!(pwd)
end