Class: PuppetMetadata::BaseCommand
- Inherits:
-
Object
- Object
- PuppetMetadata::BaseCommand
- Defined in:
- lib/puppet_metadata/base_command.rb
Overview
The base command. All actual commands should inherit from this.
Direct Known Subclasses
Class Method Summary collapse
- .command ⇒ Object
- .commands ⇒ Object
-
.parser(_options) ⇒ OptionParser
Return a parser.
Instance Method Summary collapse
- #filename ⇒ Object
-
#initialize(arguments, options) ⇒ BaseCommand
constructor
A new instance of BaseCommand.
- #metadata ⇒ Object
-
#run ⇒ Object
Actual implementation of the command.
Constructor Details
#initialize(arguments, options) ⇒ BaseCommand
Returns a new instance of BaseCommand.
6 7 8 9 |
# File 'lib/puppet_metadata/base_command.rb', line 6 def initialize(arguments, ) @arguments = arguments @options = end |
Class Method Details
.command ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/puppet_metadata/base_command.rb', line 28 def self.command name.gsub(/Command$/, '') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('_', '-') .downcase end |
.commands ⇒ Object
22 23 24 25 26 |
# File 'lib/puppet_metadata/base_command.rb', line 22 def self.commands PuppetMetadata::Command.load_commands subclasses.to_h { |subclass| [subclass.command, subclass] } end |
.parser(_options) ⇒ OptionParser
Return a parser. The program name should be overridden with a description
41 42 43 |
# File 'lib/puppet_metadata/base_command.rb', line 41 def self.parser() raise NotImplementedError end |
Instance Method Details
#filename ⇒ Object
11 12 13 |
# File 'lib/puppet_metadata/base_command.rb', line 11 def filename @filename ||= @options.fetch(:filename, 'metadata.json') end |
#metadata ⇒ Object
15 16 17 18 19 20 |
# File 'lib/puppet_metadata/base_command.rb', line 15 def @metadata ||= PuppetMetadata.read(filename) rescue StandardError => e warn "Failed to read #{filename}: #{e}" exit 2 end |
#run ⇒ Object
Actual implementation of the command
46 47 48 |
# File 'lib/puppet_metadata/base_command.rb', line 46 def run raise NotImplementedError end |