class KBSecret::CLI::Command::Generator

The implementation of `kbsecret generator`.

Constants

SUBCOMMANDS

The list of subcommands supported by `kbsecret generator`.

Public Class Methods

new(argv) click to toggle source
Calls superclass method KBSecret::CLI::Command::Abstract::new
# File lib/kbsecret/cli/command/generator.rb, line 11
        def initialize(argv)
          super(argv) do |cli|
            cli.slop cmds: SUBCOMMANDS do |o|
              o.banner = <<~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

Public Instance Methods

run!() click to toggle source

@see Command::Abstract#run!

# 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!() click to toggle source

@see Command::Abstract#setup!

# File lib/kbsecret/cli/command/generator.rb, line 35
def setup!
  @subcmd = cli.args[:command]
end
validate!() click to toggle source

@see Command::Abstract#validate!

# File lib/kbsecret/cli/command/generator.rb, line 40
def validate!
  cli.die "Unknown subcommand: #{@subcmd}." unless SUBCOMMANDS.include?(@subcmd)
end