1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-22 02:40:04 +00:00

copy: disable clipboard option

This commit is contained in:
Adrien Waksberg 2016-10-20 13:49:17 +02:00
parent f5746d6af6
commit 73312b933f
2 changed files with 32 additions and 13 deletions

View file

@ -25,6 +25,7 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:clipboard] = true
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw copy [options]" opts.banner = "#{I18n.t('option.usage')}: mpw copy [options]"
@ -33,6 +34,10 @@ OptionParser.new do |opts|
options[:config] = config options[:config] = config
end end
opts.on('-d', '--disable-clipboard', I18n.t('option.clipboard')) do
options[:clipboard] = false
end
opts.on('-g', '--group NAME', I18n.t('option.group')) do |group| opts.on('-g', '--group NAME', I18n.t('option.group')) do |group|
options[:group] = group options[:group] = group
end end
@ -60,4 +65,4 @@ opts = { search: options[:pattern],
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])
cli.decrypt cli.decrypt
cli.copy(opts) cli.copy(options[:clipboard], opts)

View file

@ -287,7 +287,8 @@ class Cli
# Copy in clipboard the login and password # Copy in clipboard the login and password
# @args: item -> the item # @args: item -> the item
def clipboard(item) # clipboard -> enable clipboard
def clipboard(item, clipboard=true)
pid = nil pid = nil
# Security: force quit after 90s # Security: force quit after 90s
@ -304,10 +305,15 @@ class Cli
break break
when 'l', 'login' when 'l', 'login'
if clipboard
Clipboard.copy(item.user) Clipboard.copy(item.user)
puts I18n.t('form.clipboard.login').green puts I18n.t('form.clipboard.login').green
else
puts item.user
end
when 'p', 'password' when 'p', 'password'
if clipboard
Clipboard.copy(@mpw.get_password(item.id)) Clipboard.copy(@mpw.get_password(item.id))
puts I18n.t('form.clipboard.password').yellow puts I18n.t('form.clipboard.password').yellow
@ -316,9 +322,16 @@ class Cli
Clipboard.clear Clipboard.clear
end end
else
puts @mpw.get_password(item.id)
end
when 'o', 'otp' when 'o', 'otp'
if clipboard
Clipboard.copy(@mpw.get_otp_code(item.id)) Clipboard.copy(@mpw.get_otp_code(item.id))
else
puts @mpw.get_otp_code(item.id)
end
puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow
else else
@ -490,8 +503,9 @@ class Cli
end end
# Copy a password, otp, login # Copy a password, otp, login
# @args: options -> the option to search # @args: clipboard -> enable clipboard
def copy(options={}) # options -> the option to search
def copy(clipboard=true, options={})
items = @mpw.list(options) items = @mpw.list(options)
if items.length == 0 if items.length == 0
@ -500,7 +514,7 @@ class Cli
table(items) table(items)
item = get_item(items) item = get_item(items)
clipboard(item) clipboard(item, clipboard)
end end
rescue Exception => e rescue Exception => e
puts "#{I18n.t('display.error')} #14: #{e}".red puts "#{I18n.t('display.error')} #14: #{e}".red