#! /usr/bin/ruby
# Usage: rip-list [-p] RIPENV
#
# Displays all installed packages and their versions for RIPENV.
# If RIPENV is omitted shows installed packages for the current
# RIPENV.
#
# If -p is passed, prints in a "parseable" deps.rip format.
#
# If -m is passed, prints the minimal list of packages needed to
# duplicate the current ripenv.

require 'rip/script'

if ARGV.delete('-m')
  exec "rip-list-minimal"
end

parse = ARGV.delete('-p')

puts "ripenv: #{RIPENV}", "" unless parse

rip("installed") do |package_path|
  if package = metadata(package_path)
    if parse
      puts "#{package.source} #{package.version(:long)}"
    else
      puts package
    end
  else
    warn "missing: #{package_path.chomp}" if parse.nil?
  end
end
