Make version output colorful
This commit is contained in:
parent
6a81f0959d
commit
6e313e2272
@ -7,8 +7,11 @@
|
||||
require 'net/http'
|
||||
require 'json'
|
||||
require_relative '../config/config'
|
||||
require 'term/ansicolor'
|
||||
|
||||
module SlackBuilder
|
||||
extend Term::ANSIColor
|
||||
|
||||
# Remote repository for a single package.
|
||||
class Repository
|
||||
# Request the latest tag in the given repository.
|
||||
@ -72,16 +75,26 @@ module SlackBuilder
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_for_latest(package_name, repository)
|
||||
package_path = Pathname.new Dir.glob("#{CONFIG[:repository]}/*/#{package_name}").first
|
||||
package_category = package_path.dirname.basename.to_s
|
||||
package = Package.parse("#{package_category}/#{package_name}", File.read("#{package_path}/#{package_name}.info"))
|
||||
module_function
|
||||
|
||||
# Checks if there is a new version for the package and returns the latest
|
||||
# version if an update is available, otherwise returns nil.
|
||||
def check_for_latest(package_name, repository)
|
||||
package = find_package_info package_name
|
||||
latest_version = repository.latest
|
||||
|
||||
if package.version == latest_version
|
||||
puts "#{package_name} is up to date."
|
||||
puts green "#{package_name} is up to date (Version #{package.version})."
|
||||
nil
|
||||
else
|
||||
puts "#{package_name}: Current version is #{package.version}, #{latest_version} is available."
|
||||
puts red "#{package_name}: Current version is #{package.version}, #{latest_version} is available."
|
||||
latest_version
|
||||
end
|
||||
end
|
||||
|
||||
private_class_method def find_package_info(package_name)
|
||||
package_path = Pathname.new Dir.glob("#{CONFIG[:repository]}/*/#{package_name}").first
|
||||
package_category = package_path.dirname.basename.to_s
|
||||
Package.parse("#{package_category}/#{package_name}", File.read("#{package_path}/#{package_name}.info"))
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user