#!/usr/bin/perl

# Support functionality for the TWiki Collaboration Platform, http://TWiki.org/
# 
# TWiki Shell 
# Oct 2004 - written by Rafael Alvarez based on a prototype by MartinCleaver 
#
# Assumes that the user has enough privileges to perform the required operations.
#
#-------------------------------------------------------------------------------
#
# For licensing info read license.txt file in the TWiki root.
# 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, published at 
# http://www.gnu.org/copyleft/gpl.html
#
#-------------------------------------------------------------------------------

use vars qw {
    $twikiLibPath
    $config
};



use diagnostics;


####################################################################################
####################################################################################


BEGIN {
    unshift @INC,"./lib";
}

# The shell starts here

use TWiki::Contrib::TWikiShellContrib::TWikiShell;
require TWiki::Contrib::TWikiShellContrib::Config;

my $configFileName = ".twikirc";    
if (-f "./".$configFileName) {
  do "./".$configFileName
} 

if (! defined($config)) {
  $config=new TWiki::Contrib::TWikiShellContrib::Config();
  $config->{configFileName}=$configFileName;
}

$config->handleParams();
$config->save();

my  $shell= new TWiki::Contrib::TWikiShellContrib::TWikiShell($config);

if ($config->{execute} && $config->{execute} ne "shell") {
#     $shell->cmd("sdk " . $config->{execute});
   $shell->cmd($config->{execute}) ;
}else {
    print "\n";
    $shell->splash();
    $shell->cmdloop();
}

$config->saveAndDispose();
