From fdc1a6f3ec0115867bac58249210b19e8519f2c0 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 20 Oct 2016 09:23:26 +0200 Subject: [PATCH] new binary for copy --- bin/mpw-copy | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ i18n/en.yml | 3 +-- i18n/fr.yml | 3 +-- lib/mpw/cli.rb | 26 ++++++++++++++------- 4 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 bin/mpw-copy diff --git a/bin/mpw-copy b/bin/mpw-copy new file mode 100644 index 0000000..c49d361 --- /dev/null +++ b/bin/mpw-copy @@ -0,0 +1,63 @@ +#!/usr/bin/ruby +# MPW is a software to crypt and manage your passwords +# Copyright (C) 2016 Adrien Waksberg +# +# 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) diff --git a/i18n/en.yml b/i18n/en.yml index b4d2b15..cf10200 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -89,8 +89,7 @@ en: login: "Press to copy the login" password: "Press

to copy the password" otp_code: "Press to copy the otp code" - update: "Press to update the item" - delete: "Press to delete the item" + quit: "Press to quit" delete_key: valid: "Key has been deleted!" delete_item: diff --git a/i18n/fr.yml b/i18n/fr.yml index f7233af..8e878a1 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -89,8 +89,7 @@ fr: login: "Pressez pour copier l'identifiant" password: "Pressez

pour copier le mot de passe" otp_code: "Pressez pour copier le code OTP" - update: "Pressez pour mettre à jour l'élément" - delete: "Pressez pour supprimer l'élément" + quit: "Pressez pour quitter" delete_key: valid: "La clé a bien été supprimée!" delete_item: diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index e7764f2..8bfa7bd 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -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