Class: KBSecret::CLI::Command::Generator
- Defined in:
- lib/kbsecret/cli/command/generator.rb
Overview
The implementation of kbsecret generator
.
Constant Summary collapse
- SUBCOMMANDS =
The list of subcommands supported by
kbsecret generator
. %w[new rm].freeze
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(argv) ⇒ Generator
constructor
A new instance of Generator.
- #run! ⇒ Object
- #setup! ⇒ Object
- #validate! ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(argv) ⇒ Generator
Returns a new instance of Generator.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kbsecret/cli/command/generator.rb', line 11 def initialize(argv) super(argv) do |cli| cli.slop cmds: SUBCOMMANDS do |o| o. = <<~HELP Usage: kbsecret generator [options] <new|rm> <generator> HELP o.string "-F", "--format", "the format of the secrets generated", default: "hex" o.integer "-l", "--length", "the length, in bytes, of the secrets generated", default: 16 o.bool "-f", "--force", "force generator creation (ignore overwrite)" end cli.dreck do string :command string :generator end cli.ensure_generator! :argument if cli.args[:command] == "rm" end end |
Instance Method Details
#run! ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kbsecret/cli/command/generator.rb', line 45 def run! case @subcmd when "new" if Config.generator?(cli.args[:generator]) && !cli.opts.force? cli.die "Refusing to overwrite an existing generator without --force." end Config.configure_generator(cli.args[:generator], format: cli.opts[:format], length: cli.opts[:length]) when "rm" Config.deconfigure_generator(cli.args[:generator]) end end |
#setup! ⇒ Object
35 36 37 |
# File 'lib/kbsecret/cli/command/generator.rb', line 35 def setup! @subcmd = cli.args[:command] end |
#validate! ⇒ Object
40 41 42 |
# File 'lib/kbsecret/cli/command/generator.rb', line 40 def validate! cli.die "Unknown subcommand: #{@subcmd}." unless SUBCOMMANDS.include?(@subcmd) end |