Created
May 31, 2019 18:30
-
-
Save pcreux/40bbdd8b7fde1156ace7e896c3a05875 to your computer and use it in GitHub Desktop.
Format 'bundle outdated' into a CSV file ordered by version delta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Run `bundle outdated | format_bundle_outdated` | |
# to get a CSV file listing the columns below for all outdated gems. | |
COLUMNS = [ "name", "newest", "installed", "requested", "groups", "delta" ].join(",") | |
class Version < Struct.new(:major, :minor, :patch, :beta) | |
def self.build(string) | |
new(*string.split('.').map(&:to_i)) | |
end | |
def to_s | |
[major, minor, patch, beta].compact.join('.') | |
end | |
def -(other) | |
major_delta = major.to_i - other.major.to_i | |
minor_delta = major_delta == 0 ? minor.to_i - other.minor.to_i : 0 | |
patch_delta = major_delta == 0 && minor_delta == 0 ? patch.to_i - other.patch.to_i : 0 | |
Version.new( | |
major_delta, | |
minor_delta, | |
patch_delta, | |
nil | |
) | |
end | |
end | |
rows = [] | |
$stdin.each_line do |line| | |
if match = line.match(/\* (\S+) \(/) | |
name = match[1] | |
end | |
if match = line.match(/newest ([0-9.]+)/) | |
newest = match[1] | |
end | |
if match = line.match(/installed ([0-9.]+)/) | |
installed = match[1] | |
end | |
if match = line.match(/requested ([0-9.]+)/) | |
requested = match[1] | |
end | |
if match = line.match(/in groups "(\S+)"/) | |
groups = match[1].split(",") | |
end | |
if name | |
newest_v = Version.build(newest) | |
installed_v = Version.build(installed) | |
delta_v = newest_v - installed_v | |
rows << [ | |
name, | |
newest, | |
installed, | |
requested, | |
groups, | |
delta_v.to_s | |
] | |
end | |
end | |
puts COLUMNS | |
rows.sort_by(&:last).each do |row| | |
puts row.join(",") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here you go. TL;DR: I've used
Gem::Version
to get a free starship operator. :-)