Class: KBSecret::CLI::Command::Abstract Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/kbsecret/cli/command/abstract.rb

Overview

This class is abstract.

Represents an abstract KBSecret command that can be subclassed to produce a more useful command. List is an example of this.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Abstract

Returns a new instance of Abstract.

Parameters:

  • argv (String)

    the arguments to call the command with


24
25
26
27
28
29
# File 'lib/kbsecret/cli/command/abstract.rb', line 24

def initialize(argv)
  @cli = CLI.create(argv) { |_o| nil }
  @cli.guard do
    yield @cli if block_given?
  end
end

Instance Attribute Details

#cliCLI (readonly)

Returns the CLI state corresponding to the command.

Returns:

  • (CLI)

    the CLI state corresponding to the command


11
12
13
# File 'lib/kbsecret/cli/command/abstract.rb', line 11

def cli
  @cli
end

Class Method Details

.command_nameString

Returns the command's CLI-friendly name.

Examples:

KBSecret::CLI::Command::StashFile # => "stash-file"

Returns:

  • (String)

    the command's CLI-friendly name


16
17
18
19
20
21
# File 'lib/kbsecret/cli/command/abstract.rb', line 16

def self.command_name
  name.split("::")
      .last
      .gsub(/([^A-Z])([A-Z]+)/, '\1-\2')
      .downcase
end

.configHash?

Returns the configuration for the command, if any.

Returns:

  • (Hash, nil)

    the configuration for the command, if any.


32
33
34
# File 'lib/kbsecret/cli/command/abstract.rb', line 32

def self.config
  KBSecret::Config.command(command_name)
end

Instance Method Details

#run!Object

This method is abstract.

Runs the command. Implemented by children.


50
51
52
# File 'lib/kbsecret/cli/command/abstract.rb', line 50

def run!
  nil
end

#setup!Object

This method is abstract.

Sets up any state used by the command. Implemented by children.


38
39
40
# File 'lib/kbsecret/cli/command/abstract.rb', line 38

def setup!
  nil
end

#validate!Object

This method is abstract.

Runs any validation checks required by the command. Implemented by children.


44
45
46
# File 'lib/kbsecret/cli/command/abstract.rb', line 44

def validate!
  nil
end