Skip to content

Instantly share code, notes, and snippets.

@ys
Last active December 26, 2015 06:39
Show Gist options
  • Save ys/7108981 to your computer and use it in GitHub Desktop.
Save ys/7108981 to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
gem 'netrc'
gem 'octokit'
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.5)
faraday (0.8.8)
multipart-post (~> 1.2.0)
multipart-post (1.2.0)
netrc (0.7.7)
octokit (2.7.0)
sawyer (~> 0.5.2)
sawyer (0.5.2)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
PLATFORMS
ruby
DEPENDENCIES
netrc
octokit
require 'octokit'
class PuppetFileVersions
EX_USAGE = 64
def initialize(file_path)
@file_path = file_path
end
def run
exit_if_no_file
instance_eval(read_file)
end
private
def mod(name, version, options)
$stdout.puts "#{name} :: #{client.tags(options[:github_tarball]).first.name}"
rescue => e
$stdout.puts "#{name} :: no version found. #{e.message}"
end
def read_file
File.open(@file_path, "r") { |f| f.read }
end
def exit_if_no_file
unless @file_path
$stderr.puts 'usage: puppetv <puppetfile_path>'
exit EX_USAGE
end
end
def client
@client ||= Octokit::Client.new(netrc: true).tap do |client|
client.login
end
end
end
#!/usr/bin/env ruby
$: << File.expand_path('../', __FILE__)
require 'puppet_versions'
begin
PuppetFileVersions.new(ARGV.first).run
rescue => e
$stderr.puts "puppetv: Error: #{e.message}"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment