#!/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 'parsearg'

binary_path = File.dirname($0)

#//------------------------------------------------
def m_ShowUsage()
  print( "#{COPYRIGHT}\n" )
  print( "Usage:\n" )
  print( "\t#{$0} [-knvcfqx] install [packages...]\n" )
  print( "\t#{$0} [-knvcfq] upgrade\n" )
  print( "\t#{$0} [-nvcq] noinstall\n" )
  print( "\t#{$0} [-nvcq] noexist\n" )
  print( "\t#{$0} [-nvcq] whatprovides [item...]\n" )
  print( "\t#{$0} [-knvcfqx] get [packages...]\n" )
  print( "\t#{$0} [-knvcfq] get-all\n" )
  print( "\t#{$0} [-knvcfq] repair\n" )
  print( "\t#{$0} [-knvf] remove [packages...]\n" )
  print( "\t#{$0} clean\n" )
  print( "Options:\n" );
  print( "\t-k\twith kernel\n" )
  print( "\t-n\tno execute\n" )
  print( "\t-v\tverbose mode\n" )
  print( "\t-f\tforce mode\n" )
  print( "\t-c <file>\tread configurations from <file>\n" )
  print( "\t-q\tdon't update database\n" )
  print( "\t-x\tignore $holds[] in mph.conf\n" )
end

#//------------------------------------------------
$USAGE = 'm_ShowUsage()'
realargv = ARGV.clone
parseArgs(0, nil, 'knvfqx', 'c:')

#//------------------------------------------------
if ARGV.size() == 0 then
  m_ShowUsage()
  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
  m_ShowUsage()
  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:
