kbsecret 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c844ec45d84acd1d1d5d6878e529033ed635b40
4
- data.tar.gz: '0295353f72349f8d4093e8deb9c4997fdeeedf5e'
3
+ metadata.gz: ef3c6ce21470ae9c4b272d68120299f23eaba85d
4
+ data.tar.gz: 0104f269fbd814723b3b9e482bdedc9636cb0872
5
5
  SHA512:
6
- metadata.gz: 5b766fd0d88a38d6a62c8c8e045e23614ea1e587765357a4eb133ab4c636cd92f8284f7b8cc830ba150286429c268a60775a71f5b627b5ebf0d4a9398473f90e
7
- data.tar.gz: a173436a8c6f76bae01f8b93f69f4d9aaa87f350065b649ee681b437a2fd98a8e44785552373e684acfb09178a2e27cb8cc7fbf1caa3834a869c8ad89b253dd5
6
+ metadata.gz: 022ab311dd0bc0d31214fa684f078425fb92fc8c54f8eb47103078655b0678deab27bb49b338691fe416e4b3ab66402f4e4c78cd625684d92c50035b94c396b3
7
+ data.tar.gz: cf4b0df49500576fdf41d0fbf4c755510925208767670df105c6a1cbefec6fd1f5f3448c3069187be74aa3a92cc22b6582789019fccf07012a57c8f0e683bc43
@@ -17,6 +17,7 @@ cmd = CLI.new do
17
17
  o.bool "-a", "--show-all", "show everything in each secret (i.e. metadata)"
18
18
  end
19
19
 
20
+ ensure_type!
20
21
  ensure_session!
21
22
  end
22
23
 
@@ -8,10 +8,10 @@ require "tty-prompt"
8
8
  include KBSecret
9
9
 
10
10
  # allows for abbreviated types (e.g., `kbsecret new env ...`)
11
- TYPE_ALIASES = Abbrev.abbrev(Record.record_types).freeze
11
+ TYPE_ALIASES = Hash.new { |_, k| k }.update(Abbrev.abbrev(Record.record_types)).freeze
12
12
 
13
- cmd = CLI.new do
14
- slop do |o|
13
+ cmd = CLI.create do |c|
14
+ c.slop do |o|
15
15
  o.banner = <<~EOS
16
16
  Usage:
17
17
  kbsecret new [options] <type> <label>
@@ -24,13 +24,14 @@ cmd = CLI.new do
24
24
  o.bool "-e", "--echo", "echo input to tty (only affects interactive input)"
25
25
  end
26
26
 
27
- dreck do
27
+ c.dreck do
28
28
  string :type
29
29
  string :label
30
- list :string, :fields
30
+ list :string, :fields if c.opts.args?
31
31
  end
32
32
 
33
- ensure_session!
33
+ c.ensure_type! :argument
34
+ c.ensure_session!
34
35
  end
35
36
 
36
37
  type = cmd.args[:type]
@@ -20,22 +20,32 @@ module KBSecret
20
20
  attr_reader :session
21
21
 
22
22
  # Encapsulate both the options and trailing arguments passed to a `kbsecret` command.
23
+ # @yield [CLI] the {CLI} instance to specify
24
+ # @return [CLI] the command's initial state
23
25
  # @example
24
- # cmd = KBSecret::CLI.new do
25
- # slop do |o|
26
+ # cmd = KBSecret::CLI.create do |c|
27
+ # c.slop do |o|
26
28
  # o.string "-s", "--session", "session label"
27
29
  # o.bool "-f", "--foo", "whatever"
28
30
  # end
29
31
  #
30
- # dreck do
32
+ # c.dreck do
31
33
  # string :name
32
34
  # end
33
35
  #
34
- # ensure_session!
36
+ # c.ensure_session!
35
37
  # end
36
38
  #
37
39
  # cmd.opts # => Slop::Result
38
40
  # cmd.args # => Dreck::Result
41
+ def self.create(&block)
42
+ cmd = CLI.new(&block)
43
+ yield cmd
44
+ cmd
45
+ end
46
+
47
+ # @api private
48
+ # @deprecated see {create}
39
49
  def initialize(&block)
40
50
  @trailing = ARGV
41
51
  guard { instance_eval(&block) }
@@ -97,6 +107,11 @@ module KBSecret
97
107
  @session = Session.new label: label
98
108
  end
99
109
 
110
+ def ensure_type!(where = :option)
111
+ type = where == :option ? @opts[:type] : @args[:type]
112
+ Record.class_for type
113
+ end
114
+
100
115
  # "Guard" a block by propagating any exceptions as fatal (unrecoverable)
101
116
  # errors.
102
117
  # @return [Object] the result of the block
@@ -9,14 +9,14 @@ module KBSecret
9
9
  class RecordLoadError < KBSecretError
10
10
  def initialize(path)
11
11
  base = File.basename(path)
12
- super "Failed to load record in file: #{base}"
12
+ super "Failed to load record in file: '#{base}'"
13
13
  end
14
14
  end
15
15
 
16
16
  # Raised during record creation if an unknown record type is requested.
17
17
  class RecordTypeUnknownError < KBSecretError
18
18
  def initialize(type)
19
- super "Unknown record type: #{type}"
19
+ super "Unknown record type: '#{type}'"
20
20
  end
21
21
  end
22
22
 
@@ -23,9 +23,12 @@ module KBSecret
23
23
  end
24
24
 
25
25
  # @param type [String, Symbol] the record type
26
- # @return [Class, nil] the record class corresponding to the given type
26
+ # @return [Class] the record class corresponding to the given type
27
+ # @raise [RecordTypeUnknownError] if the requested type is unknown
27
28
  def self.class_for(type)
28
- record_classes.find { |c| c.type == type.to_sym }
29
+ klass = record_classes.find { |c| c.type == type.to_sym }
30
+ raise RecordTypeUnknownError, type unless klass
31
+ klass
29
32
  end
30
33
 
31
34
  # @param type [String, Symbol] the record type
@@ -39,6 +42,7 @@ module KBSecret
39
42
  # @param session [Session] the session to load into
40
43
  # @param path [String] the fully-qualified record path
41
44
  # @return [Record::AbstractRecord] the loaded record
45
+ # @raise [RecordLoadError] if an error occurs during record loading
42
46
  # @api private
43
47
  def self.load_record!(session, path)
44
48
  hsh = JSON.parse(File.read(path), symbolize_names: true)
@@ -63,7 +63,6 @@ module KBSecret
63
63
  # arguments does not match the record type's constructor
64
64
  def add_record(type, label, *args)
65
65
  klass = Record.class_for(type.to_sym)
66
- raise RecordTypeUnknownError, type unless klass
67
66
 
68
67
  arity = klass.instance_method(:initialize).arity - 2
69
68
  raise RecordCreationArityError.new(arity, args.size) unless arity == args.size
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "0.6.3"
5
+ VERSION = "0.6.4"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kbsecret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-08 00:00:00.000000000 Z
11
+ date: 2017-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fpm