Removed "exit" function call from CmdLine code. Now returning out of main.

This commit is contained in:
Matt Hill
2014-05-11 11:51:09 -05:00
parent 5fcfaaaf71
commit ba83f60e21
3 changed files with 19 additions and 9 deletions

View File

@@ -76,7 +76,12 @@ int main( int argc, const char** argv )
cmd.add( fileArg );
cmd.add( countryCodeArg );
cmd.parse( argc, argv );
if (cmd.parse( argc, argv ) == false)
{
// Error occured while parsing. Exit now.
return 1;
}
filename = fileArg.getValue();

View File

@@ -240,14 +240,14 @@ class CmdLine : public CmdLineInterface
* \param argc - Number of arguments.
* \param argv - Array of arguments.
*/
void parse(int argc, const char * const * argv);
bool parse(int argc, const char * const * argv);
/**
* Parses the command line.
* \param args - A vector of strings representing the args.
* args[0] is still the program name.
*/
void parse(std::vector<std::string>& args);
bool parse(std::vector<std::string>& args);
/**
*
@@ -423,17 +423,17 @@ inline void CmdLine::add( Arg* a )
}
inline void CmdLine::parse(int argc, const char * const * argv)
inline bool CmdLine::parse(int argc, const char * const * argv)
{
// this step is necessary so that we have easy access to
// mutable strings.
std::vector<std::string> args;
for (int i = 0; i < argc; i++)
args.push_back(argv[i]);
parse(args);
return parse(args);
}
inline void CmdLine::parse(std::vector<std::string>& args)
inline bool CmdLine::parse(std::vector<std::string>& args)
{
bool shouldExit = false;
int estat = 0;
@@ -497,7 +497,12 @@ inline void CmdLine::parse(std::vector<std::string>& args)
shouldExit = true;
}
if (shouldExit)
exit(estat);
{
//exit(estat);
return false;
}
return true;
}
inline bool CmdLine::_emptyCombined(const std::string& s)

View File

@@ -83,14 +83,14 @@ class CmdLineInterface
* \param argc - Number of arguments.
* \param argv - Array of arguments.
*/
virtual void parse(int argc, const char * const * argv)=0;
virtual bool parse(int argc, const char * const * argv)=0;
/**
* Parses the command line.
* \param args - A vector of strings representing the args.
* args[0] is still the program name.
*/
void parse(std::vector<std::string>& args);
bool parse(std::vector<std::string>& args);
/**
* Returns the CmdLineOutput object.