/*************************************************************************** * 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. * ***************************************************************************/ #include #include #include #include #include #include "abstractcmdlineparser.h" #include "configfile.h" //! here comes the commandline-Parser - with help of the abstractcommandlineparser. namespace commandline { #ifndef HSADMIN_CMDLINEPARSER #define HSADMIN_CMDLINEPARSER using std::vector; using std::string; using std::map; using boost::shared_ptr; using boost::scoped_ptr; // Parameter Objects are the resultof each Parser step and used in second step. //! parsed values of a --setall, --set, --input, --passinput or a --infile option class setParameter { public: string m_property; string m_value; string toXML(string &username, shared_ptr< ::ConfigFileParser > cfgfile); }; //! parsed values of a --only or a --where option class whereParameter { public: string m_property; string m_pattern; string toXML(string &username, shared_ptr< ::ConfigFileParser > cfgfile); }; //! parsed values of a --global-order or a --order option class orderParameter { public: string m_property; bool m_ascending; string toXML(string &username, shared_ptr< ::ConfigFileParser > cfgfile); }; //! a whole parsed --call Option which holds all the relevant other options class callParameter { public: callParameter(): m_module(""), m_function(""), m_display(""), m_ignoreerror(false), m_force(false), m_globalOrderIndex(-1) { }; string m_module; string m_function; string m_display; vector > m_set; vector > m_where; vector > m_order; vector m_objects; vector m_unset; bool m_ignoreerror; bool m_force; int m_globalOrderIndex; vector parseDisplayspec(); string evalDisplay(const map &values); string toXML(string &username, shared_ptr< ::ConfigFileParser > cfgfile); }; enum parseError { NOERROR = 0, NeedCall = 1 }; //! all the parsed values class parsedParameters { public: parsedParameters(); parseError m_error; string m_user; string m_ticket; string m_defaultDisplay; string m_addConfigFile; bool m_test; bool m_ignoreerrors; vector > m_only; vector > m_setall; vector > m_globalOrder; vector > m_call; vector m_unsetall; string toXML(string &username, shared_ptr< ::ConfigFileParser > cfgfile); }; // Option classes are used in first Parse step //! --test class TestOption: public abstractcommandlineparser::CmdLineOption { public: TestOption(); protected: virtual bool handle(shared_ptr result); }; //! --ignoreerror class IgnoreErrorOption: public abstractcommandlineparser::CmdLineOption { public: IgnoreErrorOption(); protected: virtual bool handle(shared_ptr result); }; //! --ignoreerrors class IgnoreErrorsOption: public IgnoreErrorOption { public: IgnoreErrorsOption(); protected: virtual bool handle(shared_ptr result); }; //! --verbosity class VerbosityOption: public abstractcommandlineparser::CmdLineOption { public: VerbosityOption(); bool parseThis(vector& options, shared_ptr result); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --quiet class QuietOption: public abstractcommandlineparser::CmdLineOption { public: QuietOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --runas class RunAsOption: public abstractcommandlineparser::CmdLineOption { public: RunAsOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --ticket class TicketOption: public abstractcommandlineparser::CmdLineOption { public: TicketOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --config class ConfigOption: public abstractcommandlineparser::CmdLineOption { public: ConfigOption(); protected: virtual bool handle(string & parameter, shared_ptr result); }; //! --force class ForceOption: public abstractcommandlineparser::CmdLineOption { public: ForceOption(); protected: virtual bool handle(shared_ptr result); }; //! --globals class GlobalsOption: public abstractcommandlineparser::CmdLineOption { public: GlobalsOption(); protected: virtual bool handle(shared_ptr result); }; //! --where class WhereOption: public abstractcommandlineparser::CmdLineOption { public: WhereOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --only class OnlyOption: public WhereOption { public: OnlyOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --set class SetOption: public abstractcommandlineparser::CmdLineOption { public: SetOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --setall class SetAllOption: public SetOption { public: SetAllOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --infile class InfileOption: public abstractcommandlineparser::CmdLineOption { public: InfileOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --order class OrderOption: public abstractcommandlineparser::CmdLineOption { public: OrderOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --global-order class GlobalOrderOption: public OrderOption { public: GlobalOrderOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --input class InputOption: public abstractcommandlineparser::CmdLineOption { public: InputOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --passinput class PassInputOption: public abstractcommandlineparser::CmdLineOption { public: PassInputOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --display class DisplayOption: public abstractcommandlineparser::CmdLineOption { public: DisplayOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --default-display class DefaultDisplayOption: public DisplayOption { public: DefaultDisplayOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --call class CallOption: public abstractcommandlineparser::CmdLineOption { public: CallOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --unset class UnsetOption: public abstractcommandlineparser::CmdLineOption { public: UnsetOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! --unsetall class UnsetAllOption: public abstractcommandlineparser::CmdLineOption { public: UnsetAllOption(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! all other parameters are objectIDs. class ObjectID: public abstractcommandlineparser::CmdLineOption { public: ObjectID(); protected: virtual bool handle(string ¶meter, shared_ptr result); }; //! putting it all together in a typelist typedef Parameterlist24( TestOption, IgnoreErrorsOption, VerbosityOption, RunAsOption, TicketOption, ConfigOption, SetAllOption, UnsetAllOption, OnlyOption, GlobalOrderOption, DefaultDisplayOption, IgnoreErrorOption, ForceOption, GlobalsOption, WhereOption, SetOption, InfileOption, OrderOption, InputOption, PassInputOption, UnsetOption, DisplayOption, ObjectID, CallOption ) allParameters; //! generating a class with parse()-function from the list of Options typedef abstractcommandlineparser::CmdLineOptionList Parameters; #else class parsedParameters; class setParameter; class whereParameter; class orderParameter; class callParameter; class TestOption; class IgnoreErrorOption; class IgnoreErrorsOption; class VerbosityOption; class RunAsOption; class TicketOption; class ConfigOption; class SetAllOption; class OnlyOption; class UnsetAllOption; class GlobalOrderOption; class DefaultDisplayOption; class ForceOption; class GlobalsOption; class WhereOption; class SetOption; class InfileOption; class OrderOption; class InputOption; class PassInputOption; class DisplayOption; class unsetOption; class CallOption; class ObjectID; #endif /* HSADMIN_CMDLINEPARSER */ };