Class: KBSecret::CLI::Command::Pass

Inherits:
Abstract
  • Object
show all
Defined in:
lib/kbsecret/cli/command/pass.rb

Overview

The implementation of kbsecret pass.

Instance Attribute Summary

Attributes inherited from Abstract

#cli

Instance Method Summary collapse

Methods inherited from Abstract

command_name, config

Constructor Details

#initialize(argv) ⇒ Pass



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kbsecret/cli/command/pass.rb', line 10

def initialize(argv)
  super(argv) do |cli|
    cli.slop do |o|
      o.banner = <<~HELP
        Usage:
          kbsecret pass [options] <record>
      HELP

      o.string "-s", "--session", "the session to search in", default: :default
      o.bool "-c", "--clipboard", "dump the password in the clipboard"
    end

    cli.dreck do
      string :label
    end

    cli.ensure_session!
  end
end

Instance Method Details

#run!Object

See Also:



41
42
43
44
45
46
47
# File 'lib/kbsecret/cli/command/pass.rb', line 41

def run!
  if cli.opts.clipboard?
    Clipboard.copy @record.password
  else
    puts @record.password
  end
end

#setup!Object

See Also:



31
32
33
# File 'lib/kbsecret/cli/command/pass.rb', line 31

def setup!
  @record = cli.session[cli.args[:label]]
end

#validate!Object

See Also:



36
37
38
# File 'lib/kbsecret/cli/command/pass.rb', line 36

def validate!
  cli.die "No such login record." unless @record && @record.type == :login
end