#!/usr/bin/ruby

#//------------------------------------------------
COPYRIGHT = <<"_COPYRIGHT_"
Copyright (C) 2000 Akira Higuchi <a@kondara.org>
Copyright (C) 2000 Motonobu Ichimura <famao@kondara.org>
Copyright (C) 2000 Tenkou N. Hattori <tnh@kondara.org>
Copyright (C) 2000 Kondara Project <http://www.kondara.org/>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
_COPYRIGHT_
#//------------------------------------------------

#//------------------------------------------------
require 'optparse'

binary_path = File.dirname($0)

#//------------------------------------------------
realargv = ARGV.clone
ARGV.options {|o|
  Version = '0.92.8'
  o.banner = "#{COPYRIGHT}\n"
  o.banner << "Usage:\n"
  o.banner << "\t#{$0} [-knvcfqx] install [packages...]\n"
  o.banner << "\t#{$0} [-knvcfq] upgrade\n"
  o.banner << "\t#{$0} [-nvcq] noinstall\n"
  o.banner << "\t#{$0} [-nvcq] noexist\n"
  o.banner << "\t#{$0} [-nvcq] whatprovides [item...]\n"
  o.banner << "\t#{$0} [-knvcfqx] get [packages...]\n"
  o.banner << "\t#{$0} [-knvcfq] get-all\n"
  o.banner << "\t#{$0} [-knvcfq] installall\n"
  o.banner << "\t#{$0} [-knvcfq] repair\n"
  o.banner << "\t#{$0} [-knvf] remove [packages...]\n"
  o.banner << "\t#{$0} clean\n"
  o.banner << "Options:\n"
  o.on('-k', 'with kernel')
  o.on('-n', 'no execute')
  o.on('-v', 'verbose mode')
  o.on('-f', 'force mode')
  o.on('-q', 'don\'t update database')
  o.on('-x', 'ignore $holds[] in mph.conf')
  o.on('-c <file>', 'read configurations from <file>')
  o.parse!
}

#//------------------------------------------------
if ARGV.size() == 0 then
  puts ARGV.options.help
  exit(0)
end

sCommand = ARGV[0]

asCommands = [
  'install', 'installall', 'upgrade', 'noinstall', 'noexist',
  'whatprovides', 'get', 'get-all', 'remove', 'clean' ,'repair' ]
if asCommands.index(sCommand).nil? then
  puts ARGV.options.help
  exit(0)
end

args = ""
cmd = ""

case sCommand
when 'install','upgrade','get','get-all','installall','repair'
  cmd = "#{binary_path}/mph-get-install "
  args = realargv.join(" ")
when 'noinstall','noexist','whatprovides'
  cmd = "#{binary_path}/mph-get-search "
  args = realargv.join(" ")
when 'remove'
  cmd = "#{binary_path}/mph-get-remove "
  args = realargv.join(" ")
when 'clean'
  cmd = "#{binary_path}/mph-get-clean "
else
  exit -1
end
cmd += args
exec(cmd)

### :nodoc:
### Local Variables:
### mode: ruby
### ruby-indent-level: 2
### indent-tabs-mode: nil
### End:
