/*************************************************************************** * Copyright (C) 2005 by Christof Donat * * cdonat@gmx.de * * * * 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. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include "cmdlineparser.h" #include "configfile.h" #include "logger.h" #include "transaction.h" using std::string; using std::vector; using std::cerr; using std::endl; using boost::shared_ptr; using boost::scoped_ptr; using boost::starts_with; void printErrorMessage(Transaction& transact, vector& options) { shared_ptr p = transact.getParsed(); string FailedOption = options[0]; if( starts_with(FailedOption,"--") ) FailedOption = FailedOption.substr(2); else if( starts_with(FailedOption,"-") ) FailedOption = FailedOption.substr(1,2); cerr << "Error on Commandline at Parameter '"<< FailedOption; if( p->m_error == commandline::NeedCall ) cerr << ": call specific Parameter before call"; cerr << endl; } void printUsage(char* cmdname) { cerr << "Usage: " << endl << endl; cerr << cmdname << " [--test|-t]" << endl; cerr << "[--ignoreerrors|-e]" << endl; cerr << "[--verbosity=|-v ]" << endl; cerr << "[--quiet|-q]" << endl; cerr << "[--runas=|-r ]" << endl; cerr << "[--ticket=|-T ]" << endl; cerr << "[--config=|-C ]" << endl; cerr << "[--default-display:|-D ]" << endl; cerr << "[(--only:=|-W =)" << endl; cerr << " ... (--only:=|-W =)]" << endl; cerr << "[(--setall:=|-S =)" << endl; cerr << " ... (--setall:=|-S =)]" << endl; cerr << " [(--unsetall:property_1|-U property_1) ... (--unsetall:property_n|-U property_n)]" << endl; cerr << "[(--global-order:[=(asc|desc|a|d)]|-O [=(asc|desc|a|d)])" << endl; cerr << " ..." << endl; cerr << " (--global-order:[=(asc|desc|a|d)]|-O [=(asc|desc|a|d)]]" << endl; cerr << " [--ignoreerrors|-E]" << endl; cerr << "(--call:.|-c .)" << endl; cerr << " [--force]" << endl; cerr << " [--ignoreerror|-e]" << endl; cerr << " [--display:|-d ]" << endl; cerr << " [(--where:=|-w =)" << endl; cerr << " ... (--where:=|-w =)]" << endl; cerr << " [(--set:=|-s =)" << endl; cerr << " ... (--set:=|-s =)]" << endl; cerr << " [(--input:|-i )" << endl; cerr << " ... (--input:|-i )]" << endl; cerr << " [(--passinput:|-p )" << endl; cerr << " ... (--passinput:|-p )]" << endl; cerr << " [(--infile:=|-f =)" << endl; cerr << " ... (--infile:=|-f =)]" << endl; cerr << " [(--unset:property_1_1|-u property_1_1]) ... (--unset:property_1_n|-u property_1_n])]" << endl; cerr << " [(--order:[=(asc|desc|a|d)]|-o [=(asc|desc|a|d)])" << endl; cerr << " ..." << endl; cerr << " [--globals|-l]" << endl; cerr << " ..." << endl; cerr << " (--order:[=(asc|desc|a|d)]|-o [=(asc|desc|a|d)]]" << endl; cerr << " [object_1_1 ... object_1_n]" << endl; cerr << "..." << endl; cerr << "(--call:.|-c .)" << endl; cerr << " [--force]" << endl; cerr << " [--ignoreerror|-e]" << endl; cerr << " [--display:|-d ]" << endl; cerr << " [(--where:=|-w =)" << endl; cerr << " ... (--where:=|-w =)]" << endl; cerr << " [(--set:=|-s =)" << endl; cerr << " ... (--set:=|-s =)]" << endl; cerr << " [(--input:|-i )" << endl; cerr << " ... (--input:|-i )]" << endl; cerr << " [(--passinput:|-p )" << endl; cerr << " ... (--passinput:|-p )]" << endl; cerr << " [(--infile:=|-f =)" << endl; cerr << " ... (--infile:=|-f =)]" << endl; cerr << " [(--unset:property_m_1|-u property_m_1]) ... (--unset:property_m_n|-u property_m_n])]" << endl; cerr << " [(--order:[=(asc|desc|a|d)]|-o [=(asc|desc|a|d)])" << endl; cerr << " ..." << endl; cerr << " [--globals|-l]" << endl; cerr << " ..." << endl; cerr << " (--order:[=(asc|desc|a|d)]|-o [=(asc|desc|a|d)]]" << endl; cerr << " [object_m_1 ... object_m_n]" << endl; } int main(int argc, char *argv[]) { if( argc == 1 ) { printUsage(*argv); exit(1); } vector options(argv+1,argv+argc); Transaction transact(options); if( !transact ) { printErrorMessage(transact, options); printUsage(*argv); exit(1); } Logger::log(Logger::DEBUG,"have parsed Parameters"); scoped_ptr cfff(new ConfigFileFinder(transact)); shared_ptr cfg(new ConfigFileParser(cfff.get())); Logger::log(Logger::DEBUG,"have read config File"); transact(cfg); Logger::log(Logger::DEBUG,"have executed Transaction"); //cout << transact.formatOutput(); //exit(transact.errorCode()); return 0; }