Class: S7n::S7nCli::EntryAddCommand

Inherits:
Command
  • Object
show all
Includes:
EntryCommandUtils
Defined in:
lib/s7n/s7ncli/entry_command.rb

Overview

機密情報を追加するコマンドを表現する。

Constant Summary

Constants included from EntryCommandUtils

S7n::S7nCli::EntryCommandUtils::EDITING_USAGE

Instance Attribute Summary

Attributes inherited from Command

#config, #options, #world

Instance Method Summary collapse

Methods included from EntryCommandUtils

#apply_entry_changes, #command_loop, #dispatch_command, #display_entry, #input_attribute_name, #input_attribute_type, #input_secret, #input_tags, #input_value

Methods inherited from Command

#aliases, create_instance, #description, #help, #name, #option_parser, split_name_and_argv, #usage

Constructor Details

#initialize(*args) ⇒ EntryAddCommand

Returns a new instance of EntryAddCommand.



330
331
332
333
334
335
336
337
338
# File 'lib/s7n/s7ncli/entry_command.rb', line 330

def initialize(*args)
  super
  @config["tags"] = []
  @config["attributes"] = []
  @options.push(StringOption.new("n", "name", _("Name.")),
                ArrayOption.new("t", "tags", _("Tags.")),
                IntOption.new("c", "copy", "ID",
                              _("Entry ID that is copied.")))
end

Instance Method Details

#run(argv) ⇒ Object

コマンドを実行する。



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/s7n/s7ncli/entry_command.rb', line 348

def run(argv)
  option_parser.parse!(argv)
  if argv.length > 0
    config["name"] = argv.shift
  end
  if argv.length > 0
    config["tags"].push(*argv.shift.split(","))
  end
  if config["copy"]
    from_entry = world.entry_collection.find(config["copy"])
    if !from_entry
      raise NoSuchEntry.new("id" => config["copy"])
    end
  end
  puts(_("Add the entry."))
  @entry = Entry.new
  if from_entry
    @entry.add_attributes(from_entry.duplicate_attributes)
  end
  @attributes = @entry.attributes.select { |attr|
    attr.editable?
  }
  attr = @entry.get_attribute("name")
  if config["name"]
    attr.value = config["name"]
  end
  if attr.value.to_s.empty?
    puts(_("Edit attribute: %s") % _(attr.name))
    attr.value =
      input_value(attr.display_value, attr.secret?, attr.protected?)
  end
  if config["tags"].length > 0
    @tags = config["tags"]
  else
    @tags = @entry.tags
  end
  if @tags.empty?
    @tags = input_tags(@tags) || []
  end
  command_loop
  return true
end

#saveObject

機密情報を追加する。



341
342
343
344
345
# File 'lib/s7n/s7ncli/entry_command.rb', line 341

def save
  apply_entry_changes
  # TODO: undo スタックに操作を追加する。
  world.entry_collection.add_entries(@entry)
end