#!/usr/bin/env ruby
#--
# Copyright 2010 Red Hat, Inc.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#++

def usage
    puts <<USAGE
== Synopsis

oo-cartridge-info: Gets the descriptor for a given cartridge name

== Usage

oo-cartridge-info [CART]

Options:
-h|--help:
   Prints this message

USAGE
end

require 'rubygems'
require 'openshift-origin-node'
require 'openshift-origin-common'
opts = GetoptLong.new(
    ["--porcelain",         "-q", GetoptLong::NO_ARGUMENT],
    ["--debug",             "-d", GetoptLong::NO_ARGUMENT],
    ["--help",              "-?", GetoptLong::NO_ARGUMENT]
)

args = {}
begin
    opts.each{ |k,v| args[k]=v }
rescue GetoptLong::Error => e
    usage
    exit -100
end

if args["--help"]
  usage
  exit -1
end

$oo_debug = true if args['--debug']
$porcelain = args['--porcelain'] ? true : false

cart_name = ARGV.shift
cart_found = false

begin
  cart_info = OpenShift::Node.get_cartridge_info(cart_name, $porcelain, $oo_debug)
  puts cart_info
rescue Exception => e
  $stderr.puts(e.message)
  exit -1
else
  exit 0
end
