Class: KBSecret::CLI::Command::RawEdit

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

Overview

The implementation of kbsecret raw-edit.

Instance Attribute Summary

Attributes inherited from Abstract

#cli

Instance Method Summary collapse

Methods inherited from Abstract

command_name, config

Constructor Details

#initialize(argv) ⇒ RawEdit

Returns a new instance of RawEdit.



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

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

      o.string "-s", "--session", "the session to search in", default: :default
    end

    cli.dreck do
      string :label
    end

    cli.ensure_session!
  end
end

Instance Method Details

#run!Object

See Also:



39
40
41
42
# File 'lib/kbsecret/cli/command/raw_edit.rb', line 39

def run!
  Process.spawn("#{ENV["EDITOR"]} #{@record.path}")
  @record.sync! # just to bump the timestamp
end

#setup!Object

See Also:



28
29
30
# File 'lib/kbsecret/cli/command/raw_edit.rb', line 28

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

#validate!Object

See Also:



33
34
35
36
# File 'lib/kbsecret/cli/command/raw_edit.rb', line 33

def validate!
  cli.die "Missing $EDITOR." unless ENV["EDITOR"]
  cli.die "No such record." unless @record
end