class KBSecret::CLI::Command::Rm
The implementation of `kbsecret rm`.
Public Class Methods
new(argv)
click to toggle source
Calls superclass method
KBSecret::CLI::Command::Abstract::new
# File lib/kbsecret/cli/command/rm.rb, line 10 def initialize(argv) super(argv) do |cli| cli.slop do |o| o.banner = <<~HELP Usage: kbsecret rm [options] <record [record ...]> HELP o.string "-s", "--session", "the session containing the record", default: :default o.bool "-i", "--interactive", "ask for confirmation before deleting" end cli.dreck do list :string, :labels end cli.ensure_session! end end
Public Instance Methods
run!()
click to toggle source
# File lib/kbsecret/cli/command/rm.rb, line 43 def run! $VERBOSE = nil # tty-prompt blasts us with irrelevant warnings on 2.4 tty = TTY::Prompt.new confirm = if cli.opts.interactive? tty.yes?("Delete '#{@selected_records.join(", ")}'?") else true end @selected_records.each { |r| cli.session.delete_record(r.label) } if confirm end
setup!()
click to toggle source
# File lib/kbsecret/cli/command/rm.rb, line 31 def setup! @selected_records = cli.session.records.select do |record| cli.args[:labels].include? record.label end end
validate!()
click to toggle source
@see Command::Abstract#validate!
# File lib/kbsecret/cli/command/rm.rb, line 38 def validate! cli.die "No such record(s)." if @selected_records.empty? end