Class: S7n::S7nCli::EntryShowCommand

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) ⇒ EntryShowCommand

Returns a new instance of EntryShowCommand.



451
452
453
454
455
456
457
# File 'lib/s7n/s7ncli/entry_command.rb', line 451

def initialize(*args)
  super
  @config["show_secret"] = false
  @options.push(IntOption.new("id", _("Entry ID.")),
                BoolOption.new("s", "show_secret",
                               _("Show value of secret attributes.")))
end

Instance Method Details

#run(argv) ⇒ Object

コマンドを実行する。



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/s7n/s7ncli/entry_command.rb', line 460

def run(argv)
  option_parser.parse!(argv)
  if argv.length > 0
    config["id"] = argv.shift.to_i
  end
  if config["id"].nil?
    puts(_("Too few arguments."))
    help
    return true
  end
  entries = world.entry_collection.entries
  entry = entries.find { |entry|
    entry.id == config["id"]
  }
  if !entry
    raise NoSuchEntry.new("id" => config["id"])
  end
  display_entry(entry)
  if config["show_secret"]
    # TODO: undo スタックに操作を追加する。
    entry.rate += 1
    puts(_("Changed rate to %d.") % entry.rate)
    world.changed = true
  end
  return true
end