mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
init: Combined initializeData and initializeRules
This commit is contained in:
parent
0403c21002
commit
78ff8b2919
3 changed files with 18 additions and 51 deletions
50
src/init.cpp
50
src/init.cpp
|
@ -53,7 +53,7 @@ bool lightweightVersionCheck (const std::vector <std::string>& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void initializeData (
|
void initializeDataAndRules (
|
||||||
Database& database,
|
Database& database,
|
||||||
Rules& rules,
|
Rules& rules,
|
||||||
Log& log)
|
Log& log)
|
||||||
|
@ -104,10 +104,24 @@ void initializeData (
|
||||||
throw format ("Database is not readable at '{1}'", dbLocation._data);
|
throw format ("Database is not readable at '{1}'", dbLocation._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Load rule grammar.
|
||||||
|
/*
|
||||||
|
File ruleFile ("./rule.grammar");
|
||||||
|
Grammar ruleGrammar;
|
||||||
|
ruleGrammar.debug (debug);
|
||||||
|
ruleGrammar.loadFromFile (ruleFile);
|
||||||
|
|
||||||
|
// Instantiate the parser.
|
||||||
|
LR0 ruleParser;
|
||||||
|
ruleParser.debug (debug);
|
||||||
|
ruleParser.initialize (ruleGrammar);
|
||||||
|
*/
|
||||||
|
|
||||||
// Load the configuration data.
|
// Load the configuration data.
|
||||||
File configFile (dbLocation);
|
File configFile (dbLocation);
|
||||||
configFile += "timewarrior.cfg";
|
configFile += "timewarrior.cfg";
|
||||||
configFile.create (0600);
|
configFile.create (0600);
|
||||||
|
rules.load (configFile._data);
|
||||||
|
|
||||||
// This value is not written out to disk, as there would be no point. Having
|
// This value is not written out to disk, as there would be no point. Having
|
||||||
// located the config file, the 'db' location is already known. This is just
|
// located the config file, the 'db' location is already known. This is just
|
||||||
|
@ -121,42 +135,10 @@ void initializeData (
|
||||||
|
|
||||||
// Initialize the database (no data read), but files are enumerated.
|
// Initialize the database (no data read), but files are enumerated.
|
||||||
database.initialize (data._data);
|
database.initialize (data._data);
|
||||||
|
log.write ("info", database.dump ());
|
||||||
|
|
||||||
// TODO Give the log file a temp fake name. To be removed.
|
// TODO Give the log file a temp fake name. To be removed.
|
||||||
log.file (dbLocation._data + "/timewarrior.log");
|
log.file (dbLocation._data + "/timewarrior.log");
|
||||||
|
|
||||||
/*
|
|
||||||
log.write ("info", "Configuration");
|
|
||||||
for (const auto& name : configuration.all ())
|
|
||||||
log.write ("info", std::string (" ") + name + "=" + configuration[name]);
|
|
||||||
*/
|
|
||||||
|
|
||||||
log.write ("info", database.dump ());
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void initializeRules (
|
|
||||||
Rules& rules,
|
|
||||||
Log& log)
|
|
||||||
{
|
|
||||||
// TODO Load rule grammar.
|
|
||||||
/*
|
|
||||||
File ruleFile ("./rule.grammar");
|
|
||||||
Grammar ruleGrammar;
|
|
||||||
ruleGrammar.debug (debug);
|
|
||||||
ruleGrammar.loadFromFile (ruleFile);
|
|
||||||
*/
|
|
||||||
// Instantiate the parser.
|
|
||||||
/*
|
|
||||||
LR0 ruleParser;
|
|
||||||
ruleParser.debug (debug);
|
|
||||||
ruleParser.initialize (ruleGrammar);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
rules.load (configuration.get ("db") + "/timewarrior.cfg");
|
|
||||||
*/
|
|
||||||
|
|
||||||
log.write ("info", rules.dump ());
|
log.write ("info", rules.dump ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,27 +63,13 @@ int main (int argc, const char** argv)
|
||||||
// Prepare the database, but do not read data.
|
// Prepare the database, but do not read data.
|
||||||
Database database;
|
Database database;
|
||||||
Rules rules;
|
Rules rules;
|
||||||
initializeData (database, rules, log);
|
initializeDataAndRules (database, rules, log);
|
||||||
|
|
||||||
// TODO Arrange the following to minimize memory use.
|
// TODO Arrange the following to minimize memory use.
|
||||||
// TODO Load CLI grammar.
|
// TODO Load CLI grammar.
|
||||||
// TODO Load from string, else file on config override.
|
// TODO Load from string, else file on config override.
|
||||||
// TODO Migrate from loading a grammar from file, to a default string.
|
// TODO Migrate from loading a grammar from file, to a default string.
|
||||||
/*
|
|
||||||
File cliFile ("./cli.grammar");
|
|
||||||
Grammar cliGrammar;
|
|
||||||
cliGrammar.debug (debug);
|
|
||||||
cliGrammar.loadFromFile (cliFile);
|
|
||||||
|
|
||||||
// Instantiate the parser.
|
|
||||||
LR0 cliParser;
|
|
||||||
cliParser.debug (debug);
|
|
||||||
cliParser.initialize (cliGrammar);
|
|
||||||
// TODO Parse CLI.
|
// TODO Parse CLI.
|
||||||
*/
|
|
||||||
|
|
||||||
// Load the rules.
|
|
||||||
initializeRules (rules, log);
|
|
||||||
|
|
||||||
// Load extension script info.
|
// Load extension script info.
|
||||||
Extensions extensions;
|
Extensions extensions;
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
|
|
||||||
// init.cpp
|
// init.cpp
|
||||||
bool lightweightVersionCheck (const std::vector <std::string>&);
|
bool lightweightVersionCheck (const std::vector <std::string>&);
|
||||||
void initializeData (Database&, Rules&, Log&);
|
void initializeDataAndRules (Database&, Rules&, Log&);
|
||||||
void initializeRules (Rules&, Log&);
|
|
||||||
void initializeExtensions (Rules&, Extensions&, Log&);
|
void initializeExtensions (Rules&, Extensions&, Log&);
|
||||||
int dispatchCommand (const std::vector <std::string>&, Database&, Rules&, Extensions&, Log&);
|
int dispatchCommand (const std::vector <std::string>&, Database&, Rules&, Extensions&, Log&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue