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

Returns a new instance of 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 = "        Usage:\n          kbsecret pass [options] <record>\n      HELP\n\n      o.string \"-s\", \"--session\", \"the session to search in\", default: :default\n      o.bool \"-c\", \"--clipboard\", \"dump the password in the clipboard\"\n    end\n\n    cli.dreck do\n      string :label\n    end\n\n    cli.ensure_session!\n  end\nend\n"

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