diff --git a/bin/mpw-update b/bin/mpw-update index 301b876..221c632 100644 --- a/bin/mpw-update +++ b/bin/mpw-update @@ -52,6 +52,10 @@ OptionParser.new do |opts| values[:pattern] = pattern end + opts.on('-r', '--random', I18n.t('option.random_password')) do + options[:password] = true + end + opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| options[:wallet] = wallet end @@ -63,4 +67,4 @@ cli = MPW::Cli.new(config, options[:sync]) cli.load_config cli.get_wallet(options[:wallet]) cli.decrypt -cli.update(values) +cli.update(options[:password], values) diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 3ad32be..9e8040e 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -423,12 +423,9 @@ class Cli # Form to add a new item # @args: password -> generate a random password def add(password=false) - options = text_editor('add_form', nil, password) - item = Item.new(options) - - if password - options[:password] = MPW::password(@config.password) - end + options = text_editor('add_form', nil, password) + item = Item.new(options) + options[:password] = MPW::password(@config.password) if password @mpw.add(item) @mpw.set_password(item.id, options[:password]) if options.has_key?(:password) @@ -442,8 +439,9 @@ class Cli end # Update an item - # @args: options -> the option to search - def update(options={}) + # @args: password -> generate a random password + # options -> the option to search + def update(password=false, options={}) items = @mpw.list(options) if items.length == 0 @@ -451,8 +449,9 @@ class Cli else table_items(items) if items.length > 1 - item = get_item(items) - options = text_editor('update_form', item) + item = get_item(items) + options = text_editor('update_form', item, password) + options[:password] = MPW::password(@config.password) if password item.update(options) @mpw.set_password(item.id, options[:password]) if options.has_key?(:password) diff --git a/templates/update_form.erb b/templates/update_form.erb index b942cf5..e5363f8 100644 --- a/templates/update_form.erb +++ b/templates/update_form.erb @@ -2,9 +2,9 @@ # <%= I18n.t('form.update_item.host') %> host: <%= item.host %> # <%= I18n.t('form.update_item.login') %> -user: <%= item.user %> +user: <%= item.user %><% if not password %> # <%= I18n.t('form.update_item.password') %> -password: +password: <% end %> # <%= I18n.t('form.update_item.group') %> group: <%= item.group %> # <%= I18n.t('form.update_item.protocol') %>