kbsecret 1.3.0.pre.2 → 1.3.0.pre.3

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
  SHA256:
3
- metadata.gz: 62e332544af0910c66dda052deace55c038f308734a6f61327338c02bd6d0c6c
4
- data.tar.gz: 8e436c956c7713519b6ade1085866b1669d42b6a26bbdc4655151e7b0f295017
3
+ metadata.gz: 917f766026ce5e43c4294706d146e44d159d0af0eebd4d088b8408bc85d7a6af
4
+ data.tar.gz: b7feb36ed986661d85076a19d1ad360ae099a2e0fadf09db9ccf6ba90b9fc84d
5
5
  SHA512:
6
- metadata.gz: 22f83a0907bdd794f823ae45c8ad9a264a5083221a483eaa0f26322383f695d7c01d172158e3770b32c220ac95a29cd7942f7c5584e4d6f5d953d50a19c48649
7
- data.tar.gz: 54112352f2a7b65a20deac137aaa52623f286d2e158dbf22d0c27c49ad5b3e3f444067a765ac8ff441dc3ea3d4a6e1d2832f532e2419a34cc3eb730301a425f1
6
+ metadata.gz: 59e7acebf02007b3ba23758496b5014723e2dfc9e735ae500bed07b83e2151e6f4462c5b156e6483dc1be867d5022efd911eff00d7202593baf45abf99941c89
7
+ data.tar.gz: 63e9b439194409c429a1fb404d18354f732520d33b0e7d95810b6acba14c052c8a036e1b6fb8128b4a18c922105f16270f92c012ef3092ea5ead2004d94b589d
data/README.md CHANGED
@@ -3,7 +3,7 @@ KBSecret ![](https://avatars1.githubusercontent.com/u/31023996?s=50&v=4)
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/kbsecret.svg)](https://badge.fury.io/rb/kbsecret)
5
5
  [![Build Status](https://travis-ci.org/kbsecret/kbsecret.svg?branch=master)](https://travis-ci.org/kbsecret/kbsecret)
6
- [![Coverage Status](https://coveralls.io/repos/github/kbsecret/kbsecret/badge.svg)](https://coveralls.io/github/kbsecret/kbsecret?branch=coveralls)
6
+ [![Coverage Status](https://codecov.io/gh/kbsecret/kbsecret/branch/master/graph/badge.svg)](https://codecov.io/gh/kbsecret/kbsecret)
7
7
 
8
8
  KBSecret is a command line utility and library for managing *secrets*.
9
9
 
data/bin/kbsecret CHANGED
@@ -4,36 +4,13 @@
4
4
  require "kbsecret"
5
5
  require "fileutils"
6
6
 
7
- BUILTIN_CMDS = %w[help version commands types].freeze
8
-
9
- EXT_PATHS = ENV["PATH"].split(File::PATH_SEPARATOR).map do |path|
10
- Dir[File.join(path, "kbsecret-*")]
11
- end.flatten.uniq.freeze
12
-
13
- EXT_CMDS = EXT_PATHS.map do |c|
14
- File.basename(c, File.extname(c)).sub!("kbsecret-", "")
15
- end.freeze
16
-
17
- FLAGS = Hash.new { |_, k| k }.update(
7
+ FLAG_ALIASES = Hash.new { |_, k| k }.update(
18
8
  "--help" => "help",
19
9
  "-h" => "help",
20
10
  "--version" => "version",
21
11
  "-v" => "version"
22
12
  ).freeze
23
13
 
24
- ALL_CMDS = (FLAGS.keys + BUILTIN_CMDS + KBSecret::CLI::Command.command_names + EXT_CMDS).freeze
25
-
26
- KBSECRET_HELP = <<~KBSECRET_HELP
27
- Usage:
28
- kbsecret <command> <args ...>
29
-
30
- Available commands:
31
- #{ALL_CMDS.join(", ")}
32
-
33
- For more information about a particular command, try:
34
- kbsecret help <command>
35
- KBSECRET_HELP
36
-
37
14
  def migrate_configs
38
15
  old_conf_dir = File.expand_path("~/.config/kbsecret")
39
16
 
@@ -43,104 +20,29 @@ def migrate_configs
43
20
  FileUtils.rm_rf old_conf_dir
44
21
  end
45
22
 
46
- def internal?(cmd)
47
- KBSecret::CLI::Command.command_names.include?(cmd)
48
- end
49
-
50
- def external?(cmd)
51
- EXT_CMDS.include?(cmd)
52
- end
53
-
54
- def builtin?(cmd)
55
- BUILTIN_CMDS.include?(cmd)
56
- end
57
-
58
23
  def flag?(cmd)
59
- FLAGS.keys.include?(cmd)
24
+ FLAG_ALIASES.keys.include?(cmd)
60
25
  end
61
26
 
62
27
  def normalize(cmd)
63
- KBSecret::Config.unalias_command(FLAGS[cmd])
28
+ KBSecret::Config.unalias_command(FLAG_ALIASES[cmd])
64
29
  end
65
30
 
66
31
  def expand(cmd)
67
- return cmd if flag?(cmd) || builtin?(cmd)
32
+ return cmd unless KBSecret::CLI::Command.external?(cmd)
68
33
 
69
34
  "kbsecret-#{cmd}"
70
35
  end
71
36
 
72
- def help(*args)
73
- command = normalize args.shift
74
- if command.nil?
75
- puts KBSECRET_HELP
76
- elsif builtin? command
77
- send "#{command}_help"
78
- elsif internal? command
79
- exec expand(command), "--help"
80
- elsif external? command
81
- KBSecret::CLI.die "Help is not available for external commands."
82
- else
83
- KBSecret::CLI.die "Unknown command: #{command}."
84
- end
85
- end
86
-
87
- # lol
88
- def help_help
89
- puts <<~HELP_HELP
90
- Usage:
91
- kbsecret help <command>
92
-
93
- For a list of all commands, see:
94
- kbsecret help
95
- HELP_HELP
96
- end
97
-
98
- def version(*_args)
99
- puts <<~VERSION
100
- kbsecret version #{KBSecret::VERSION}.
101
- VERSION
102
- end
103
-
104
- def version_help
105
- puts <<~VERSION_HELP
106
- Usage:
107
- kbsecret version
108
- VERSION_HELP
109
- end
110
-
111
- def commands(*_args)
112
- puts ALL_CMDS.join("\n")
113
- end
114
-
115
- def commands_help
116
- puts <<~COMMANDS_HELP
117
- Usage:
118
- kbsecret commands
119
- COMMANDS_HELP
120
- end
121
-
122
- def types(*_args)
123
- puts KBSecret::Record.record_types.join("\n")
124
- end
125
-
126
- def types_help
127
- puts <<~TYPES_HELP
128
- Usage:
129
- kbsecret types
130
- TYPES_HELP
131
- end
132
-
133
37
  migrate_configs
134
38
 
135
39
  command = normalize(ARGV.shift || "help")
136
40
 
137
41
  args = KBSecret::Config.command_args(command) + ARGV
138
42
 
139
- if builtin?(command)
140
- send command, *args
141
- elsif internal?(command)
43
+ if KBSecret::CLI::Command.internal?(command)
142
44
  KBSecret::CLI::Command.run! command, *args
143
- elsif external?(command)
45
+ elsif KBSecret::CLI::Command.external?(command)
144
46
  exec expand(command), *args
145
47
  else
146
48
  KBSecret::CLI.die "Unknown command: #{command}."
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBSecret
4
+ class CLI
5
+ module Command
6
+ # The implementation of `kbsecret commands`.
7
+ class Commands < Abstract
8
+ def initialize(argv)
9
+ super(argv) do |cli|
10
+ cli.slop do |o|
11
+ o.banner = <<~HELP
12
+ Usage:
13
+ kbsecret commands [options]
14
+ HELP
15
+
16
+ o.bool "-e", "--external-only", "list only external commands"
17
+ o.bool "-i", "--internal-only", "list only internal commands"
18
+ end
19
+ end
20
+ end
21
+
22
+ # @see Command::Abstract#run!
23
+ def run!
24
+ cmds = if cli.opts.external_only?
25
+ Command.external_command_names
26
+ elsif cli.opts.internal_only?
27
+ Command.internal_command_names
28
+ else
29
+ Command.all_command_names
30
+ end
31
+
32
+ puts cmds.join "\n"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBSecret
4
+ class CLI
5
+ module Command
6
+ # The implementation of `kbsecret help`.
7
+ class Help < Abstract
8
+ def initialize(argv)
9
+ super(argv) do |cli|
10
+ cli.slop do |o|
11
+ o.banner = <<~HELP
12
+ Usage:
13
+ kbsecret help <command>
14
+
15
+ For a list of all commands, see:
16
+ kbsecret help
17
+ HELP
18
+ end
19
+
20
+ cli.dreck errors: false do
21
+ string :command
22
+ end
23
+ end
24
+ end
25
+
26
+ # @return [String] the top-level "help" string for `kbsecret`
27
+ def toplevel_help
28
+ <<~KBSECRET_HELP
29
+ Usage:
30
+ kbsecret <command> <args ...>
31
+
32
+ Available commands:
33
+ #{Command.all_command_names.join(", ")}
34
+
35
+ For more information about a particular command, try:
36
+ kbsecret help <command>
37
+ KBSECRET_HELP
38
+ end
39
+
40
+ # @see Command::Abstract#run!
41
+ def run!
42
+ command = cli.args[:command]
43
+
44
+ if command.empty?
45
+ puts toplevel_help
46
+ elsif Command.internal?(command)
47
+ Command.run! command, "--help"
48
+ elsif Command.external?(command)
49
+ cli.die "Help is not available for external commands."
50
+ else
51
+ cli.die "Unknown command: #{command}."
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -58,7 +58,7 @@ module KBSecret
58
58
  generator = KBSecret::Generator.new(cli.opts[:generator]) if cli.opts.generate?
59
59
 
60
60
  fields = if cli.opts.terse?
61
- STDIN.read.chomp.split cli.opts[:ifs]
61
+ CLI.stdin.read.chomp.split cli.opts[:ifs]
62
62
  else
63
63
  prompt = TTY::Prompt.new
64
64
  klass = Record.class_for(@type)
@@ -47,7 +47,7 @@ module KBSecret
47
47
  # @see Command::Abstract#run!
48
48
  def run!
49
49
  contents = if @filename == "-"
50
- STDIN.read
50
+ KBSecret::CLI.stdin.read
51
51
  elsif File.file?(@filename)
52
52
  File.read(@filename)
53
53
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBSecret
4
+ class CLI
5
+ module Command
6
+ # The implementation of `kbsecret types`.
7
+ class Types < Abstract
8
+ def initialize(argv)
9
+ super(argv) do |cli|
10
+ cli.slop do |o|
11
+ o.banner = <<~HELP
12
+ Usage:
13
+ kbsecret types
14
+ HELP
15
+ end
16
+ end
17
+ end
18
+
19
+ # @see Command::Abstract#run!
20
+ def run!
21
+ puts KBSecret::Record.record_types.join("\n")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBSecret
4
+ class CLI
5
+ module Command
6
+ # The implementation of `kbsecret version`.
7
+ class Version < Abstract
8
+ def initialize(argv)
9
+ super(argv) do |cli|
10
+ cli.slop do |o|
11
+ o.banner = <<~HELP
12
+ Usage:
13
+ kbsecret version
14
+ HELP
15
+ end
16
+ end
17
+ end
18
+
19
+ # @see Command::Abstract#run!
20
+ def run!
21
+ puts "kbsecret version #{KBSecret::VERSION}."
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -6,35 +6,67 @@ Dir[File.join(__dir__, "command/*.rb")].each { |t| require_relative t }
6
6
 
7
7
  module KBSecret
8
8
  class CLI
9
- # The namespace for {KBSecret}'s internal commands.
9
+ # The namespace for {KBSecret}'s commands.
10
10
  module Command
11
11
  module_function
12
12
 
13
- # @return [Array<Class>] the class objects of all non-abstract commands
14
- def command_classes
13
+ # The fully-qualified paths of all external commands visible to {KBSecret}.
14
+ # @return [Array<String>] the fully-qualified paths of all external commands
15
+ def external_command_paths
16
+ ENV["PATH"].split(File::PATH_SEPARATOR).map do |path|
17
+ Dir[File.join(path, "kbsecret-*")]
18
+ end.flatten.uniq.freeze
19
+ end
20
+
21
+ # The CLI-friendly names of all external commands
22
+ def external_command_names
23
+ external_command_paths.map do |c|
24
+ File.basename(c, File.extname(c)).sub!("kbsecret-", "")
25
+ end.freeze
26
+ end
27
+
28
+ # @return [Boolean] whether or not there is an external command with the given name
29
+ def external?(command_name)
30
+ external_command_names.include?(command_name)
31
+ end
32
+
33
+ # @return [Array<Class>] the class objects of all non-abstract internal commands
34
+ def internal_command_classes
15
35
  klasses = constants.map(&Command.method(:const_get)).grep(Class)
16
36
  klasses.delete(Command::Abstract)
17
37
  klasses
18
38
  end
19
39
 
20
- # @return [Array<String>] the CLI-friendly names of all commands
21
- def command_names
22
- command_classes.map(&:command_name)
40
+ # @return [Array<String>] the CLI-friendly names of all internal commands
41
+ def internal_command_names
42
+ internal_command_classes.map(&:command_name)
23
43
  end
24
44
 
25
45
  # @param command_name [String] the CLI-friendly name of the command
26
- # @return [Class, nil] the command class corresponding to the given name, or `nil`
27
- def command_for(command_name)
28
- klass = command_classes.find { |c| c.command_name == command_name }
46
+ # @return [Class, nil] the command class corresponding to the given name, or `nil` if the name
47
+ # does not correspond to an internal command
48
+ def internal_command_for(command_name)
49
+ klass = internal_command_classes.find { |c| c.command_name == command_name }
29
50
  # TODO: raise here if nil?
30
51
  klass
31
52
  end
32
53
 
33
- # @param command_name [String] the CLI-friendly name of the command to run
54
+ # @return [Boolean] whether or not there is an internal command with the given name
55
+ def internal?(command_name)
56
+ internal_command_names.include?(command_name)
57
+ end
58
+
59
+ # @return [Array<String>] the CLI-friendly names of all commands, internal and external
60
+ def all_command_names
61
+ internal_command_names + external_command_names
62
+ end
63
+
64
+ # @param command_name [String] the CLI-friendly name of the internal command to run
34
65
  # @param args [Array<String>] the arguments, if any, to pass to the command
66
+ # @note This method only takes **internal** command names.
35
67
  # @return [void]
36
68
  def run!(command_name, *args)
37
- klass = command_for command_name
69
+ klass = internal_command_for command_name
38
70
  cmd = klass.new(args)
39
71
  cmd.setup!
40
72
  cmd.validate!
data/lib/kbsecret/cli.rb CHANGED
@@ -60,7 +60,7 @@ module KBSecret
60
60
  guard { yield self }
61
61
  end
62
62
 
63
- # Parse options for a kbsecret utility, adding some default options for
63
+ # Parse options for a `kbsecret` command, adding some default options for
64
64
  # introspection, verbosity, and help output.
65
65
  # @param cmds [Array<String>] additional commands to print in `--introspect-flags`
66
66
  # @param errors [Boolean] whether or not to produce Slop errors
@@ -91,7 +91,7 @@ module KBSecret
91
91
  @argv = @opts.args
92
92
  end
93
93
 
94
- # Parse trailing arguments for a kbsecret utility, using the elements remaining
94
+ # Parse trailing arguments for a `kbsecret` command, using the elements remaining
95
95
  # after options have been removed and interpreted via {#slop}.
96
96
  # @param errors [Boolean] whether or not to produce (strict) Dreck errors
97
97
  # @note *If* {#slop} is called, it must be called before this.
@@ -151,7 +151,7 @@ module KBSecret
151
151
  def guard
152
152
  yield
153
153
  rescue => e
154
- STDERR.puts e.backtrace if @opts&.debug?
154
+ self.stderr.puts e.backtrace if @opts&.debug?
155
155
  die "#{e.to_s.capitalize}."
156
156
  end
157
157
 
@@ -159,7 +159,7 @@ module KBSecret
159
159
  # @param msg [String] the message to print
160
160
  # @return [void]
161
161
  def info(msg)
162
- STDERR.puts "#{GREEN["Info"]}: #{msg}"
162
+ self.stderr.puts "#{GREEN["Info"]}: #{msg}"
163
163
  end
164
164
 
165
165
  # Print an information message, but only if verbose output has been enabled.
@@ -184,7 +184,7 @@ module KBSecret
184
184
  # @return [void]
185
185
  def warn(msg)
186
186
  return if @opts.no_warn?
187
- STDERR.puts "#{YELLOW["Warning"]}: #{msg}"
187
+ self.stderr.puts "#{YELLOW["Warning"]}: #{msg}"
188
188
  end
189
189
 
190
190
  # Print an error message and terminate.
@@ -196,22 +196,38 @@ module KBSecret
196
196
  abort pretty
197
197
  end
198
198
 
199
- class << self
200
- # Print an error message and terminate.
201
- # @param msg [String] the message to print
202
- # @return [void]
203
- # @note This method does not return!
204
- def die(msg)
205
- pretty = "#{RED["Fatal"]}: #{msg}"
206
- abort pretty
207
- end
199
+ # Print an error message and terminate.
200
+ # @param msg [String] the message to print
201
+ # @return [void]
202
+ # @note This method does not return!
203
+ def self.die(msg)
204
+ pretty = "#{RED["Fatal"]}: #{msg}"
205
+ abort pretty
206
+ end
208
207
 
209
- # Finds a reasonable default field separator by checking the environment first
210
- # and then falling back to ":".
211
- # @return [String] the field separator
212
- def ifs
213
- ENV["IFS"] || ":"
214
- end
208
+ # Finds a reasonable default field separator by checking the environment first
209
+ # and then falling back to ":".
210
+ # @return [String] the field separator
211
+ def self.ifs
212
+ ENV["IFS"] || ":"
213
+ end
214
+
215
+ # @return [IO] the IO object corresponding to the current standard input
216
+ # @note Internal `kbsecret` commands should use this, and not `STDIN`.
217
+ def self.stdin
218
+ $stdin
219
+ end
220
+
221
+ # @return [IO] the IO object corresponding to the current standard output
222
+ # @note Internal `kbsecret` commands should use this, and not `STDOUT`.
223
+ def self.stdout
224
+ $stdout
225
+ end
226
+
227
+ # @return [IO] the IO object corresponding to the current standard error
228
+ # @note Internal `kbsecret` commands should use this, and not `STDERR`.
229
+ def self.stderr
230
+ $stderr
215
231
  end
216
232
  end
217
233
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module KBSecret
4
4
  # kbsecret's current version
5
- VERSION = "1.3.0.pre.2"
5
+ VERSION = "1.3.0.pre.3"
6
6
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kbsecret
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.pre.2
4
+ version: 1.3.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-31 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: aruba
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.0.0.pre.alpha.2
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 1.0.0.pre.alpha.2
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: minitest
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +72,14 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: '0.16'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: '0.16'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: yard
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -227,12 +213,14 @@ files:
227
213
  - lib/kbsecret/cli.rb
228
214
  - lib/kbsecret/cli/command.rb
229
215
  - lib/kbsecret/cli/command/abstract.rb
216
+ - lib/kbsecret/cli/command/commands.rb
230
217
  - lib/kbsecret/cli/command/conf.rb
231
218
  - lib/kbsecret/cli/command/cp.rb
232
219
  - lib/kbsecret/cli/command/dump_fields.rb
233
220
  - lib/kbsecret/cli/command/env.rb
234
221
  - lib/kbsecret/cli/command/generator.rb
235
222
  - lib/kbsecret/cli/command/generators.rb
223
+ - lib/kbsecret/cli/command/help.rb
236
224
  - lib/kbsecret/cli/command/list.rb
237
225
  - lib/kbsecret/cli/command/login.rb
238
226
  - lib/kbsecret/cli/command/new.rb
@@ -243,6 +231,8 @@ files:
243
231
  - lib/kbsecret/cli/command/sessions.rb
244
232
  - lib/kbsecret/cli/command/stash_file.rb
245
233
  - lib/kbsecret/cli/command/todo.rb
234
+ - lib/kbsecret/cli/command/types.rb
235
+ - lib/kbsecret/cli/command/version.rb
246
236
  - lib/kbsecret/config.rb
247
237
  - lib/kbsecret/exceptions.rb
248
238
  - lib/kbsecret/generator.rb