HSAdmin Backend Domains, E-Mail, Datenbanken
Purodha
2013-02-20 4a7e12928010374d76e677c8ec3ea4f5e63e9487
commit | author | age
c64ab5 1 /***************************************************************************
CD 2  *   Copyright (C) 2005 by Christof Donat   *
3  *   cdonat@gmx.de   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <iostream>
26 #include <cstdlib>
27 #include <string>
28 #include <vector>
29
30 #include <boost/shared_ptr.hpp>
31 #include <boost/scoped_ptr.hpp>
32 #include <boost/algorithm/string.hpp>
33
34 #include "cmdlineparser.h"
35 #include "configfile.h"
36 #include "logger.h"
37 #include "transaction.h"
38
39 using std::string;
40 using std::vector;
41 using std::cerr;
42 using std::endl;
43 using boost::shared_ptr;
44 using boost::scoped_ptr;
45 using boost::starts_with;
46
47 void printErrorMessage(Transaction& transact, vector<string>& options) {
48     shared_ptr<commandline::parsedParameters> p = transact.getParsed();
49     string FailedOption = options[0];
50     if( starts_with(FailedOption,"--") )
51         FailedOption = FailedOption.substr(2);
52     else if( starts_with(FailedOption,"-") )
53         FailedOption = FailedOption.substr(1,2);
54
55     cerr << "Error on Commandline at Parameter '"<< FailedOption;
56     if( p->m_error == commandline::NeedCall )
57         cerr << ": call specific Parameter before call";
58     cerr << endl;
59 }
60
61 void printUsage(char* cmdname) {
62     cerr << "Usage: " << endl << endl;
63     cerr << cmdname << " [--test|-t]" << endl;
64     cerr << "[--ignoreerrors|-e]" << endl;
65     cerr << "[--verbosity=<level>|-v <level>]" << endl;
66     cerr << "[--quiet|-q]" << endl;
67     cerr << "[--runas=<user>|-r <user>]" << endl;
68     cerr << "[--ticket=<ticketfile>|-T <ticketfile>]" << endl;
69     cerr << "[--config=<configfile>|-C <configfile>]" << endl;
70     cerr << "[--default-display:<displaySpec>|-D <displaySpec>]" << endl;
71     cerr << "[(--only:<property_1>=<expr_1>|-W <property_1>=<expr_1>)" << endl;
72     cerr << " ... (--only:<property_n>=<expr_n>|-W <property_n>=<expr_n>)]" << endl;
73     cerr << "[(--setall:<property_1>=<value_1>|-S <property_1>=<value_1>)" << endl;
74     cerr << " ... (--setall:<property_n>=<value_n>|-S <property_n>=<value_n>)]" << endl;
75     cerr << " [(--unsetall:property_1|-U property_1) ... (--unsetall:property_n|-U property_n)]" << endl;
76     cerr << "[(--global-order:<property_1>[=(asc|desc|a|d)]|-O <property_1>[=(asc|desc|a|d)])" << endl;
77     cerr << "    ..." << endl;
78     cerr << " (--global-order:<property_n>[=(asc|desc|a|d)]|-O <property_n>[=(asc|desc|a|d)]]" << endl;
79     cerr << " [--ignoreerrors|-E]" << endl;
80     cerr << "(--call:<module_1>.<function_1>|-c <module_1>.<function_1>)" << endl;
81     cerr << "  [--force]" << endl;
82     cerr << "  [--ignoreerror|-e]" << endl;
83     cerr << "  [--display:<displaySpec>|-d <displaySpec>]" << endl;
84     cerr << "  [(--where:<property_1_1>=<expr_1_1>|-w <property_1_1>=<expr_1_1>)" << endl;
85     cerr << "   ... (--where:<property_1_n>=<expr_1_n>|-w <property_1_n>=<expr_1_n>)]" << endl;
86     cerr << "  [(--set:<property_1_1>=<value_1_1>|-s <property_1_1>=<value_1_1>)" << endl;
87     cerr << "   ... (--set:<property_1_n>=<value_1_n>|-s <property_1_n>=<value_1_n>)]" << endl;
88     cerr << "  [(--input:<property_1_1>|-i <property_1_1>)" << endl;
89     cerr << "   ... (--input:<property_1_n>|-i <property_1_n>)]" << endl;
90     cerr << "  [(--passinput:<property_1_1>|-p <property_1_1>)" << endl;
91     cerr << "   ... (--passinput:<property_1_n>|-p <property_1_n>)]" << endl;
92     cerr << "  [(--infile:<property_1_1>=<file_1_1>|-f <property_1_1>=<file_1_1>)" << endl;
93     cerr << "    ... (--infile:<property_1_n>=<file_1_n>|-f <property_1_n>=<file_1_n>)]" << endl;
94     cerr << "     [(--unset:property_1_1|-u property_1_1]) ... (--unset:property_1_n|-u property_1_n])]" << endl;
95     cerr << "  [(--order:<property_1_1>[=(asc|desc|a|d)]|-o <property_1_1>[=(asc|desc|a|d)])" << endl;
96     cerr << "      ..." << endl;
97     cerr << "      [--globals|-l]" << endl;
98     cerr << "      ..." << endl;
99     cerr << "   (--order:<property_1_n>[=(asc|desc|a|d)]|-o <property_1_n>[=(asc|desc|a|d)]]" << endl;
100     cerr << "  [object_1_1 ... object_1_n]" << endl;
101     cerr << "..." << endl;
102     cerr << "(--call:<module_m>.<function_m>|-c <module_m>.<function_m>)" << endl;
103     cerr << "  [--force]" << endl;
104     cerr << "  [--ignoreerror|-e]" << endl;
105     cerr << "  [--display:<displaySpec>|-d <displaySpec>]" << endl;
106     cerr << "  [(--where:<property_m_1>=<expr_m_1>|-w <property_m_1>=<expr_m_1>)" << endl;
107     cerr << "   ... (--where:<property_m_n>=<expr_m_n>|-w <property_m_n>=<expr_m_n>)]" << endl;
108     cerr << "  [(--set:<property_m_1>=<value_m_1>|-s <property_m_1>=<value_m_1>)" << endl;
109     cerr << "   ... (--set:<property_m_n>=<value_m_n>|-s <property_m_n>=<value_m_n>)]" << endl;
110     cerr << "  [(--input:<property_m_1>|-i <property_m_1>)" << endl;
111     cerr << "   ... (--input:<property_m_n>|-i <property_m_n>)]" << endl;
112     cerr << "  [(--passinput:<property_m_1>|-p <property_m_1>)" << endl;
113     cerr << "   ... (--passinput:<property_m_n>|-p <property_m_n>)]" << endl;
114     cerr << "  [(--infile:<property_m_1>=<file_m_1>|-f <property_m_1>=<file_m_1>)" << endl;
115     cerr << "   ... (--infile:<property_m_n>=<file_m_n>|-f <property_m_n>=<file_m_n>)]" << endl;
116     cerr << "     [(--unset:property_m_1|-u property_m_1]) ... (--unset:property_m_n|-u property_m_n])]" << endl;
117     cerr << "  [(--order:<property_m_1>[=(asc|desc|a|d)]|-o <property_m_1>[=(asc|desc|a|d)])" << endl;
118     cerr << "      ..." << endl;
119     cerr << "      [--globals|-l]" << endl;
120     cerr << "      ..." << endl;
121     cerr << "   (--order:<property_m_n>[=(asc|desc|a|d)]|-o <property_m_n>[=(asc|desc|a|d)]]" << endl;
122     cerr << "  [object_m_1 ... object_m_n]" << endl;
123 }
124
125 int main(int argc, char *argv[])
126 {
127     if( argc == 1 ) {
128         printUsage(*argv);
129         exit(1);
130     }
131     vector<string> options(argv+1,argv+argc);
132     Transaction transact(options);
133     
134     if( !transact ) {
135         printErrorMessage(transact, options);
136         printUsage(*argv);
137         exit(1);
138     }
139
140     Logger::log(Logger::DEBUG,"have parsed Parameters");
141     
142     scoped_ptr<ConfigFileFinder> cfff(new ConfigFileFinder(transact));
143     shared_ptr<ConfigFileParser> cfg(new ConfigFileParser(cfff.get()));
144
145     Logger::log(Logger::DEBUG,"have read config File");
146
147     transact(cfg);
148
149     Logger::log(Logger::DEBUG,"have executed Transaction");
150
151     //cout << transact.formatOutput();
152     //exit(transact.errorCode());
153
154     return 0;
155 }