]> git.stg.codes - stg.git/blob - projects/sgconf/api_action.cpp
Ticket 12. The 'stopOnError(rval.stopOnError)' property moved in the
[stg.git] / projects / sgconf / api_action.cpp
1 #include "api_action.h"
2
3 #include "actions.h"
4 #include "parser_state.h"
5
6 SGCONF::PARSER_STATE SGCONF::API_ACTION::Parse(int argc, char ** argv, void * /*data*/)
7 {
8 PARSER_STATE state(false, argc, argv);
9 if (!m_argument.empty())
10     {
11     if (argc == 0 ||
12         argv == NULL ||
13         *argv == NULL)
14         throw ERROR("Missing argument.");
15     m_argument = *argv;
16     --state.argc;
17     ++state.argv;
18     }
19 state = m_suboptions.Parse(state.argc, state.argv, &m_params);
20 m_commands.Add(m_funPtr, m_argument, m_params);
21 return state;
22 }
23
24 SGCONF::API_ACTION::API_ACTION(COMMANDS & commands,
25                                const std::string & paramDescription,
26                                bool needArgument,
27                                const std::vector<PARAM> & params,
28                                API_FUNCTION funPtr)
29     : m_commands(commands),
30       m_description(paramDescription),
31       m_argument(needArgument ? "1" : ""), // Hack
32       m_funPtr(funPtr)
33 {
34 std::vector<PARAM>::const_iterator it(params.begin());
35 while (it != params.end())
36     {
37     m_suboptions.Add(it->name, MakeKVAction(it->name, it->shortDescr), it->longDescr);
38     ++it;
39     }
40 }