kbsecret 0.8.0.pre.4 → 0.8.0.pre.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41fdcf73292b783109fc320d519927b865d3d699
4
- data.tar.gz: dbfe082cfbe08760603e9f31c7e9b3c7588581f2
3
+ metadata.gz: ac8d2f2070dfe623994a9fe08b79b9eed5ac8b4a
4
+ data.tar.gz: 88762582df2085091179d1f723585a25038f3ca7
5
5
  SHA512:
6
- metadata.gz: '090490e56abc99cb6a4f2febde1ce704b31bfa5d04d3635acd662f3609beba5fe4396f537bc397771d3426b1347d913c3f4b88b888b03da0c22eb24602ca4986'
7
- data.tar.gz: ae5305cffa2d072c8f96d23277b0625915bf0f957bf2f9b1956e97dca56c34b28aa4de3a77de867bd010d269202f4b9573dbcc35f45e1a4cbf6f39c994481d76
6
+ metadata.gz: 2690cb31def84423bdcf818e1379ac502221e6a196036658ee34e5b34c621bbcca59efcfbdfc6df52dce5e7d9e7c2f4450ce58fe555ced38dd20d6c6ecb23890
7
+ data.tar.gz: 1aea1c3940e0503106e1f13a07af5c1ed7c6639ab4d35b0c2a927cee0462316cc35f016af52b2e03e9acb457ca582f484418b73857baba06405679a6ec23a18d
data/bin/kbsecret CHANGED
@@ -156,10 +156,12 @@ end
156
156
 
157
157
  command = normalize(ARGV.shift || "help")
158
158
 
159
+ args = KBSecret::Config.command_args(command) + ARGV
160
+
159
161
  if builtin?(command)
160
- send command, *ARGV
162
+ send command, *args
161
163
  elsif external?(command) || internal?(command)
162
- exec expand(command), *ARGV
164
+ exec expand(command), *args
163
165
  else
164
166
  KBSecret::CLI.die "Unknown command: '#{command}'."
165
167
  end
data/lib/kbsecret/cli.rb CHANGED
@@ -6,6 +6,7 @@ require "dreck"
6
6
 
7
7
  module KBSecret
8
8
  # An encapsulation of useful methods for kbsecret's CLI.
9
+ # Most methods in this class assume that they are being called from the context of
9
10
  class CLI
10
11
  # @return [Slop::Result, nil] the result of option parsing, if requested
11
12
  # via {#slop}
@@ -39,16 +40,14 @@ module KBSecret
39
40
  # cmd.opts # => Slop::Result
40
41
  # cmd.args # => Dreck::Result
41
42
  def self.create(&block)
42
- cmd = CLI.new(&block)
43
- yield cmd
44
- cmd
43
+ CLI.new(&block)
45
44
  end
46
45
 
47
46
  # @api private
48
47
  # @deprecated see {create}
49
- def initialize(&block)
50
- @trailing = ARGV
51
- guard { instance_eval(&block) }
48
+ def initialize
49
+ @argv = ARGV.dup
50
+ guard { yield self }
52
51
  end
53
52
 
54
53
  # Parse options for a kbsecret utility, adding some default options for
@@ -58,7 +57,7 @@ module KBSecret
58
57
  # @return [Slop::Result] the result of argument parsing
59
58
  # @note This should be called within the block passed to {#initialize}.
60
59
  def slop(cmds: [], errors: true)
61
- @opts = Slop.parse suppress_errors: !errors do |o|
60
+ @opts = Slop.parse @argv, suppress_errors: !errors do |o|
62
61
  o.separator "Options:"
63
62
 
64
63
  yield o
@@ -78,7 +77,7 @@ module KBSecret
78
77
  end
79
78
  end
80
79
 
81
- @trailing = @opts.args
80
+ @argv = @opts.args
82
81
  end
83
82
 
84
83
  # Parse trailing arguments for a kbsecret utility, using the elements remaining
@@ -86,7 +85,7 @@ module KBSecret
86
85
  # @param errors [Boolean] whether or not to produce (strict) Dreck errors
87
86
  # @note *If* {#slop} is called, it must be called before this.
88
87
  def dreck(errors: true, &block)
89
- @args = Dreck.parse @trailing, strict: errors do
88
+ @args = Dreck.parse @argv, strict: errors do
90
89
  instance_eval(&block)
91
90
  end
92
91
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "yaml"
4
3
  require "fileutils"
4
+ require "inih"
5
+ require "shellwords"
6
+ require "yaml"
5
7
 
6
8
  module KBSecret
7
9
  # Global and per-session configuration for kbsecret.
@@ -14,6 +16,10 @@ module KBSecret
14
16
  # @api private
15
17
  CONFIG_FILE = File.join(CONFIG_DIR, "config.yml").freeze
16
18
 
19
+ # The command configuration file.
20
+ # @api private
21
+ COMMAND_CONFIG_FILE = File.join(CONFIG_DIR, "commands.ini").freeze
22
+
17
23
  # Configuration facets used for method generation.
18
24
  # @api private
19
25
  CONFIG_FACETS = {
@@ -65,6 +71,26 @@ module KBSecret
65
71
  @config[key]
66
72
  end
67
73
 
74
+ # Fetch the configuration for a `kbsecret` command.
75
+ # @param cmd [String] the short name of the command
76
+ # @return [Hash, nil] the command's configuration
77
+ # @example
78
+ # # retrieves the config for `kbsecret-list`
79
+ # Config.command("list") # => { "args" => "...", }
80
+ def self.command(cmd)
81
+ @command_config[cmd]
82
+ end
83
+
84
+ # Fetch the configured default arguments for a `kbsecret` command.
85
+ # @param cmd [String] the short name of the command
86
+ # @return [Array] the command's default arguments
87
+ # @note Default arguments are split according to normal shell splitting rules.
88
+ # @example
89
+ # Config.command_args("list") # => ["--show-all"]
90
+ def self.command_args(cmd)
91
+ @command_config.dig(cmd, "args")&.shellsplit || []
92
+ end
93
+
68
94
  # @!method session(label)
69
95
  # Retrieve a session's configuration.
70
96
  # @param label [String, Symbol] the session's label
@@ -134,12 +160,18 @@ module KBSecret
134
160
  end
135
161
  end
136
162
 
137
- if File.exist?(CONFIG_FILE)
138
- user_config = YAML.load_file(CONFIG_FILE)
139
- else
140
- user_config = DEFAULT_CONFIG
141
- FileUtils.mkdir_p CONFIG_DIR
142
- end
163
+ user_config = if File.exist?(CONFIG_FILE)
164
+ YAML.load_file(CONFIG_FILE)
165
+ else
166
+ FileUtils.mkdir_p CONFIG_DIR
167
+ DEFAULT_CONFIG
168
+ end
169
+
170
+ @command_config = if File.exist?(COMMAND_CONFIG_FILE)
171
+ INIH.load(COMMAND_CONFIG_FILE)
172
+ else
173
+ {}
174
+ end
143
175
 
144
176
  @config = DEFAULT_CONFIG.merge(user_config)
145
177
  @config[:sessions].merge!(DEFAULT_SESSION)
@@ -122,12 +122,13 @@ module KBSecret
122
122
  # @param body [Hash<Symbol, String>] a mapping of the record's data fields
123
123
  # @note Creation does *not* sync the new record; see {#sync!} for that.
124
124
  def initialize(session, label, **body)
125
- @session = session
126
- @timestamp = Time.now.to_i
127
- @label = label.to_s
128
- @type = self.class.type
129
- @data = { @type => body }
130
- @path = File.join(session.directory, "#{label}.json")
125
+ @session = session
126
+ @timestamp = Time.now.to_i
127
+ @label = label.to_s
128
+ @type = self.class.type
129
+ @data = { @type => body }
130
+ @path = File.join(session.directory, "#{label}.json")
131
+ @defer_sync = false
131
132
 
132
133
  populate_internal_fields
133
134
  end
@@ -137,11 +138,12 @@ module KBSecret
137
138
  # @return [void]
138
139
  # @api private
139
140
  def initialize_from_hash(hsh)
140
- @timestamp = hsh[:timestamp]
141
- @label = hsh[:label]
142
- @type = hsh[:type].to_sym
143
- @data = hsh[:data]
144
- @path = File.join(session.directory, "#{label}.json")
141
+ @timestamp = hsh[:timestamp]
142
+ @label = hsh[:label]
143
+ @type = hsh[:type].to_sym
144
+ @data = hsh[:data]
145
+ @path = File.join(session.directory, "#{label}.json")
146
+ @defer_sync = false
145
147
  end
146
148
 
147
149
  # @!method data_fields
data/lib/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "0.8.0.pre.4"
5
+ VERSION = "0.8.0.pre.5"
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.8.0.pre.4
4
+ version: 0.8.0.pre.5
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-24 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fpm
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.2.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: inih
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.1'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.1'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: keybase-unofficial
127
141
  requirement: !ruby/object:Gem::Requirement