mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 05:47:53 +00:00
new binary for copy
This commit is contained in:
parent
1745585fb8
commit
fdc1a6f3ec
4 changed files with 83 additions and 12 deletions
63
bin/mpw-copy
Normal file
63
bin/mpw-copy
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/ruby
|
||||
# MPW is a software to crypt and manage your passwords
|
||||
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'optparse'
|
||||
require 'mpw/config'
|
||||
require 'mpw/cli'
|
||||
|
||||
# --------------------------------------------------------- #
|
||||
# Options
|
||||
# --------------------------------------------------------- #
|
||||
|
||||
options = {}
|
||||
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "#{I18n.t('option.usage')}: mpw copy [options]"
|
||||
|
||||
opts.on('-c', '--config PATH', I18n.t('option.config')) do |config|
|
||||
options[:config] = config
|
||||
end
|
||||
|
||||
opts.on('-g', '--group NAME', I18n.t('option.group')) do |group|
|
||||
options[:group] = group
|
||||
end
|
||||
|
||||
opts.on('-h', '--help', I18n.t('option.help')) do
|
||||
puts opts
|
||||
exit 0
|
||||
end
|
||||
|
||||
opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern|
|
||||
options[:pattern] = pattern
|
||||
end
|
||||
|
||||
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
|
||||
options[:wallet] = wallet
|
||||
end
|
||||
end.parse!
|
||||
|
||||
config = MPW::Config.new(options[:config])
|
||||
cli = MPW::Cli.new(config, options[:sync])
|
||||
|
||||
opts = { search: options[:pattern],
|
||||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.copy(opts)
|
|
@ -89,8 +89,7 @@ en:
|
|||
login: "Press <l> to copy the login"
|
||||
password: "Press <p> to copy the password"
|
||||
otp_code: "Press <o> to copy the otp code"
|
||||
update: "Press <u> to update the item"
|
||||
delete: "Press <d> to delete the item"
|
||||
quit: "Press <q> to quit"
|
||||
delete_key:
|
||||
valid: "Key has been deleted!"
|
||||
delete_item:
|
||||
|
|
|
@ -89,8 +89,7 @@ fr:
|
|||
login: "Pressez <l> pour copier l'identifiant"
|
||||
password: "Pressez <p> pour copier le mot de passe"
|
||||
otp_code: "Pressez <o> pour copier le code OTP"
|
||||
update: "Pressez <u> pour mettre à jour l'élément"
|
||||
delete: "Pressez <d> pour supprimer l'élément"
|
||||
quit: "Pressez <q> pour quitter"
|
||||
delete_key:
|
||||
valid: "La clé a bien été supprimée!"
|
||||
delete_item:
|
||||
|
|
|
@ -314,19 +314,12 @@ class Cli
|
|||
Clipboard.copy(@mpw.get_otp_code(item.id))
|
||||
puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow
|
||||
|
||||
when 'd', 'delete'
|
||||
break if delete(item)
|
||||
|
||||
when 'u', 'update', 'e', 'edit'
|
||||
update(item)
|
||||
|
||||
else
|
||||
puts "----- #{I18n.t('form.clipboard.help.name')} -----".cyan
|
||||
puts I18n.t('form.clipboard.help.login')
|
||||
puts I18n.t('form.clipboard.help.password')
|
||||
puts I18n.t('form.clipboard.help.otp_code')
|
||||
puts I18n.t('form.clipboard.help.update')
|
||||
puts I18n.t('form.clipboard.help.delete')
|
||||
puts I18n.t('form.clipboard.help.quit')
|
||||
next
|
||||
end
|
||||
end
|
||||
|
@ -489,6 +482,23 @@ class Cli
|
|||
puts "#{I18n.t('display.error')} #16: #{e}".red
|
||||
end
|
||||
|
||||
# Copy a password, otp, login
|
||||
# @args: options -> the option to search
|
||||
def copy(options={})
|
||||
items = @mpw.list(options)
|
||||
|
||||
if items.length == 0
|
||||
puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
|
||||
else
|
||||
table(items)
|
||||
|
||||
item = get_item(items)
|
||||
clipboard(item)
|
||||
end
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('display.error')} #14: #{e}".red
|
||||
end
|
||||
|
||||
# Export the items in a CSV file
|
||||
# @args: file -> the destination file
|
||||
# options -> option to search
|
||||
|
|
Loading…
Reference in a new issue