Skip to content

Commit

Permalink
Implement puppet-metadata with various subcommands
Browse files Browse the repository at this point in the history
This implements a puppet-metadata executable which now only implements
the eol command to show which operating systems in metadata are end of
life.
  • Loading branch information
ekohl committed Mar 9, 2024
1 parent ca6a320 commit f1b04bb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions bin/puppet-metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env ruby

Check failure on line 1 in bin/puppet-metadata

View workflow job for this annotation

GitHub Actions / rubocop

Style/FrozenStringLiteralComment: Missing frozen string literal comment.
require 'optparse'
require 'json'
require 'puppet_metadata'

class Command

Check failure on line 6 in bin/puppet-metadata

View workflow job for this annotation

GitHub Actions / rubocop

Style/Documentation: Missing top-level documentation comment for `class Command`.
def initialize(arguments); end

Check failure on line 7 in bin/puppet-metadata

View workflow job for this annotation

GitHub Actions / rubocop

Style/RedundantInitialize: Remove unnecessary empty `initialize` method.

def metadata
@metadata ||= begin
@filename = 'metadata.json' if @filename.nil? || @filename.empty?

PuppetMetadata.read(@filename)
end
rescue StandardError => e
warn "Failed to read #{filename}: #{e}"
exit 2
end

def self.commands
Command.subclasses.to_h { |subclass| [subclass.command, subclass] }
end

def self.command
name.gsub(/Command$/, '')
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.downcase
end

def self.parser
raise NotImplementedError
end
end

class EolCommand < Command

Check failure on line 36 in bin/puppet-metadata

View workflow job for this annotation

GitHub Actions / rubocop

Style/Documentation: Missing top-level documentation comment for `class EolCommand`.
def initialize(arguments)
super

@filename = arguments.shift

# TODO: expose --at $DATE
eol = metadata.eol_operatingsystems

if eol.any?
width = eol.each_key.map(&:length).max

puts 'Found EOL operating systems'
eol.each do |os, versions|
puts "#{os.ljust(width)} #{versions.join(', ')}"
end
else
puts 'All operating systems up to date'
end
end
end

def main
command = ARGV[0]
command_class = Command.commands[command]
unless command_class
warn "Command '#{command}' not understood."
exit 2
end

command_class.new(ARGV[1..])
end

main
1 change: 1 addition & 0 deletions puppet_metadata.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = Gem::Requirement.new('>= 2.7', '< 4')

s.executables << 'metadata2gha'
s.executables << 'puppet-metadata'
s.files = Dir['lib/**/*.rb']
s.extra_rdoc_files = ['README.md']
s.rdoc_options << '--main' << 'README.md'
Expand Down

0 comments on commit f1b04bb

Please sign in to comment.