Class: S7n::S7nCli::EntryCollectionImportCommand
- Defined in:
- lib/s7n/s7ncli/entry_collection_command.rb
Overview
機密情報をインポートするコマンドを表現する。
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(*args) ⇒ EntryCollectionImportCommand
constructor
A new instance of EntryCollectionImportCommand.
-
#run(argv) ⇒ Object
コマンドを実行する。.
Methods inherited from Command
#aliases, create_instance, #description, #help, #name, #option_parser, split_name_and_argv, #usage
Constructor Details
#initialize(*args) ⇒ EntryCollectionImportCommand
Returns a new instance of EntryCollectionImportCommand.
18 19 20 21 22 23 24 |
# File 'lib/s7n/s7ncli/entry_collection_command.rb', line 18 def initialize(*args) super @config["type"] = "gpass" @config["path"] = "~/.gpass/passwords.gps" @options.push(StringOption.new("type", _("type")), StringOption.new("path", _("path"))) end |
Instance Method Details
#run(argv) ⇒ Object
コマンドを実行する。
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/s7n/s7ncli/entry_collection_command.rb', line 27 def run(argv) option_parser.parse!(argv) if argv.length > 0 config["path"] = argv.shift end case config["type"] when "gpass" path = File.(config["path"]) if !File.file?(path) raise NotExist.new(path) end puts(_("Import the entry collection in the GPass file: %s") % path) gpass_file = GPassFile.new begin msg = _("Enter the master passphrase for GPass(^D is cancel): ") passphrase = S7nCli.input_string_without_echo(msg) if passphrase ec = gpass_file.read(passphrase, path) # TODO: UNDO スタックにタグの追加と機密情報の追加の操作を積む。 world.entry_collection.merge(ec) world.changed = true puts(_("Imported %d entries.") % ec.entries.length) else canceled end rescue InvalidPassphrase => e puts(e.) retry end else raise ArgumentError, _("not supported type: %s") % config["type"] end return true end |