Class: KBSecret::CLI::Command::Abstract Abstract
- Inherits:
-
Object
- Object
- KBSecret::CLI::Command::Abstract
- Defined in:
- lib/kbsecret/cli/command/abstract.rb
Overview
Direct Known Subclasses
Commands, Conf, Cp, DumpFields, Env, Generator, Generators, Help, List, Login, New, Pass, RawEdit, Rm, Session, Sessions, StashEdit, StashFile, Todo, Types, Version
Instance Attribute Summary collapse
-
#cli ⇒ CLI
readonly
The CLI state corresponding to the command.
Class Method Summary collapse
-
.command_name ⇒ String
The command's CLI-friendly name.
-
.config ⇒ Hash?
The configuration for the command, if any.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Abstract
constructor
A new instance of Abstract.
-
#run! ⇒ Object
abstract
Runs the command.
-
#setup! ⇒ Object
abstract
Sets up any state used by the command.
-
#validate! ⇒ Object
abstract
Runs any validation checks required by the command.
Constructor Details
#initialize(argv) ⇒ Abstract
Returns a new instance of Abstract.
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
#cli ⇒ CLI (readonly)
Returns 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_name ⇒ String
Returns 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 |
.config ⇒ Hash?
Returns 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
Runs the command. Implemented by children.
50 51 52 |
# File 'lib/kbsecret/cli/command/abstract.rb', line 50 def run! nil end |
#setup! ⇒ Object
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
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 |