recognize startup parameters
Usage: winix [options] -c : a path to the config file --config : a path to the config file -h : print usage information --help : print usage information -? : print usage information While here: - let it be possible to parse multiple configs, - fix: some error messages were not printed at startup.
This commit is contained in:
@@ -45,7 +45,6 @@ namespace Winix
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
errors_to_stdout = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,27 +60,19 @@ void Config::SetLogBuffer(pt::WTextStream * log_buffer)
|
||||
}
|
||||
|
||||
|
||||
void Config::ShowError()
|
||||
void Config::ShowError(const std::wstring & config_file)
|
||||
{
|
||||
|
||||
switch( parser.status )
|
||||
{
|
||||
case pt::SpaceParser::ok:
|
||||
log << log2 << "Config: syntax ok" << logend;
|
||||
break;
|
||||
|
||||
|
||||
case pt::SpaceParser::cant_open_file:
|
||||
if( errors_to_stdout )
|
||||
std::wcout << L"Config: I cannot open a config file: " << config_file << std::endl;
|
||||
|
||||
log << log1 << "Config: cant open a config file: " << config_file << logend;
|
||||
log << log1 << "Config: I cannot open a config file: " << config_file << logend;
|
||||
break;
|
||||
|
||||
case pt::SpaceParser::syntax_error:
|
||||
if( errors_to_stdout )
|
||||
std::wcout << "Config: syntax error, line: " << parser.get_last_parsed_line() << std::endl;
|
||||
|
||||
log << log1 << "Config: syntax error, line: " << parser.get_last_parsed_line() << logend;
|
||||
log << log1 << "Config: syntax error in file: " << config_file << ", line: " << parser.get_last_parsed_line() << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -91,28 +82,26 @@ void Config::ShowError()
|
||||
|
||||
|
||||
|
||||
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
bool Config::ReadConfig(const std::wstring & config_file)
|
||||
{
|
||||
errors_to_stdout = errors_to_stdout_;
|
||||
|
||||
if( config_file.empty() )
|
||||
{
|
||||
log << log2 << "Config: name of the config file is empty" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
log << log2 << "Config: reading a config file" << logend;
|
||||
pt::SpaceParser::Status status = parser.parse_space_file(config_file, space);
|
||||
log << log2 << "Config: reading a config file: " << config_file << logend;
|
||||
pt::SpaceParser::Status status = parser.parse_space_file(config_file, space, false);
|
||||
|
||||
if( status == pt::SpaceParser::ok )
|
||||
{
|
||||
AssignValues(stdout_is_closed);
|
||||
AssignValues();
|
||||
SetAdditionalVariables();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowError();
|
||||
ShowError(config_file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -120,7 +109,7 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
|
||||
|
||||
|
||||
|
||||
void Config::AssignValues(bool stdout_is_closed)
|
||||
void Config::AssignValues()
|
||||
{
|
||||
server_mode = Text(L"server_mode");
|
||||
demonize = Bool(L"demonize", true);
|
||||
|
||||
@@ -53,10 +53,6 @@ class Config
|
||||
{
|
||||
public:
|
||||
|
||||
// name of the config file
|
||||
// this is the parameter passed to winix programm
|
||||
std::wstring config_file;
|
||||
|
||||
// server mode
|
||||
// you can assign any string to it such as "production" "dev"
|
||||
// this value is not used by winix itself
|
||||
@@ -857,7 +853,7 @@ public:
|
||||
|
||||
|
||||
Config();
|
||||
bool ReadConfig(bool errors_to_stdout_, bool stdout_is_closed = true);
|
||||
bool ReadConfig(const std::wstring & config_file);
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -902,11 +898,10 @@ public:
|
||||
private:
|
||||
|
||||
pt::SpaceParser parser;
|
||||
bool errors_to_stdout;
|
||||
Log log;
|
||||
|
||||
void ShowError();
|
||||
void AssignValues(bool stdout_is_closed);
|
||||
void ShowError(const std::wstring & config_file);
|
||||
void AssignValues();
|
||||
void SetAdditionalVariables();
|
||||
void CheckPasswd();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user