mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
init: Eliminating configuration
This commit is contained in:
parent
31cbae7bb4
commit
16cd5a6501
3 changed files with 22 additions and 20 deletions
17
src/init.cpp
17
src/init.cpp
|
@ -25,7 +25,6 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <Configuration.h>
|
|
||||||
#include <Database.h>
|
#include <Database.h>
|
||||||
#include <Rules.h>
|
#include <Rules.h>
|
||||||
#include <Extensions.h>
|
#include <Extensions.h>
|
||||||
|
@ -55,7 +54,6 @@ bool lightweightVersionCheck (const std::vector <std::string>& args)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void initializeData (
|
void initializeData (
|
||||||
Configuration& configuration,
|
|
||||||
Database& database,
|
Database& database,
|
||||||
Log& log)
|
Log& log)
|
||||||
{
|
{
|
||||||
|
@ -109,17 +107,23 @@ void initializeData (
|
||||||
File configFile (dbLocation);
|
File configFile (dbLocation);
|
||||||
configFile += "timewarrior.cfg";
|
configFile += "timewarrior.cfg";
|
||||||
configFile.create (0600);
|
configFile.create (0600);
|
||||||
|
/*
|
||||||
configuration.load (configFile._data);
|
configuration.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
|
||||||
// for subsequent internal use.
|
// for subsequent internal use.
|
||||||
|
/*
|
||||||
configuration.set ("db", dbLocation._data);
|
configuration.set ("db", dbLocation._data);
|
||||||
log.write ("info", std::string (" rc.db=") + configuration.get ("db"));
|
log.write ("info", std::string (" rc.db=") + configuration.get ("db"));
|
||||||
|
*/
|
||||||
|
|
||||||
// Perhaps some subsequent code would like to know this is a new db and
|
// Perhaps some subsequent code would like to know this is a new db and
|
||||||
// possibly a first run.
|
// possibly a first run.
|
||||||
|
/*
|
||||||
configuration.set ("shiny", (shinyNewDatabase ? 1 : 0));
|
configuration.set ("shiny", (shinyNewDatabase ? 1 : 0));
|
||||||
|
*/
|
||||||
|
|
||||||
// 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);
|
||||||
|
@ -127,16 +131,17 @@ void initializeData (
|
||||||
// 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");
|
log.write ("info", "Configuration");
|
||||||
for (const auto& name : configuration.all ())
|
for (const auto& name : configuration.all ())
|
||||||
log.write ("info", std::string (" ") + name + "=" + configuration[name]);
|
log.write ("info", std::string (" ") + name + "=" + configuration[name]);
|
||||||
|
*/
|
||||||
|
|
||||||
log.write ("info", database.dump ());
|
log.write ("info", database.dump ());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void initializeRules (
|
void initializeRules (
|
||||||
Configuration& configuration,
|
|
||||||
Rules& rules,
|
Rules& rules,
|
||||||
Log& log)
|
Log& log)
|
||||||
{
|
{
|
||||||
|
@ -154,22 +159,25 @@ void initializeRules (
|
||||||
ruleParser.initialize (ruleGrammar);
|
ruleParser.initialize (ruleGrammar);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
rules.load (configuration.get ("db") + "/timewarrior.cfg");
|
rules.load (configuration.get ("db") + "/timewarrior.cfg");
|
||||||
|
*/
|
||||||
|
|
||||||
log.write ("info", rules.dump ());
|
log.write ("info", rules.dump ());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void initializeExtensions (
|
void initializeExtensions (
|
||||||
Configuration& configuration,
|
|
||||||
Rules& rules,
|
Rules& rules,
|
||||||
Extensions& extensions,
|
Extensions& extensions,
|
||||||
Log& log)
|
Log& log)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
Directory extDir (configuration.get ("db"));
|
Directory extDir (configuration.get ("db"));
|
||||||
extDir += "extensions";
|
extDir += "extensions";
|
||||||
|
|
||||||
extensions.initialize (extDir._data);
|
extensions.initialize (extDir._data);
|
||||||
|
*/
|
||||||
|
|
||||||
log.write ("info", extensions.dump ());
|
log.write ("info", extensions.dump ());
|
||||||
}
|
}
|
||||||
|
@ -177,7 +185,6 @@ void initializeExtensions (
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int dispatchCommand (
|
int dispatchCommand (
|
||||||
const std::vector <std::string>& args,
|
const std::vector <std::string>& args,
|
||||||
Configuration& configuration,
|
|
||||||
Database& database,
|
Database& database,
|
||||||
Rules& rules,
|
Rules& rules,
|
||||||
Extensions& extensions,
|
Extensions& extensions,
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <Configuration.h>
|
|
||||||
#include <Database.h>
|
#include <Database.h>
|
||||||
#include <Rules.h>
|
#include <Rules.h>
|
||||||
#include <Extensions.h>
|
#include <Extensions.h>
|
||||||
|
@ -44,7 +43,7 @@
|
||||||
int main (int argc, const char** argv)
|
int main (int argc, const char** argv)
|
||||||
{
|
{
|
||||||
// The log is needed early, in order to capture as much as possible, but will
|
// The log is needed early, in order to capture as much as possible, but will
|
||||||
// only be given a file name once configuration is loaded. The log therefore
|
// only be given a file name once the rules is loaded. The log therefore
|
||||||
// buffers the messages until it has a file name to write to.
|
// buffers the messages until it has a file name to write to.
|
||||||
Log log;
|
Log log;
|
||||||
|
|
||||||
|
@ -60,11 +59,9 @@ int main (int argc, const char** argv)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Load the configuration, prepare the database, but do not read data.
|
// Prepare the database, but do not read data.
|
||||||
// TODO Rules will eventually phase out Configuration.
|
|
||||||
Configuration configuration;
|
|
||||||
Database database;
|
Database database;
|
||||||
initializeData (configuration, database, log);
|
initializeData (database, 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.
|
||||||
|
@ -84,16 +81,15 @@ int main (int argc, const char** argv)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Load the rules.
|
// Load the rules.
|
||||||
// TODO Rules will eventually phase out Configuration.
|
|
||||||
Rules rules;
|
Rules rules;
|
||||||
initializeRules (configuration, rules, log);
|
initializeRules (rules, log);
|
||||||
|
|
||||||
// Load extension script info.
|
// Load extension script info.
|
||||||
Extensions extensions;
|
Extensions extensions;
|
||||||
initializeExtensions (configuration, rules, extensions, log);
|
initializeExtensions (rules, extensions, log);
|
||||||
|
|
||||||
// Dispatch to commands.
|
// Dispatch to commands.
|
||||||
status = dispatchCommand (args, configuration, database, rules, extensions, log);
|
status = dispatchCommand (args, database, rules, extensions, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (const std::string& error)
|
catch (const std::string& error)
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#ifndef INCLUDED_TIMEW
|
#ifndef INCLUDED_TIMEW
|
||||||
#define INCLUDED_TIMEW
|
#define INCLUDED_TIMEW
|
||||||
|
|
||||||
#include <Configuration.h>
|
|
||||||
#include <Database.h>
|
#include <Database.h>
|
||||||
#include <Rules.h>
|
#include <Rules.h>
|
||||||
#include <Extensions.h>
|
#include <Extensions.h>
|
||||||
|
@ -35,10 +34,10 @@
|
||||||
|
|
||||||
// init.cpp
|
// init.cpp
|
||||||
bool lightweightVersionCheck (const std::vector <std::string>&);
|
bool lightweightVersionCheck (const std::vector <std::string>&);
|
||||||
void initializeData (Configuration&, Database&, Log&);
|
void initializeData (Database&, Log&);
|
||||||
void initializeRules (Configuration&, Rules&, Log&);
|
void initializeRules (Rules&, Log&);
|
||||||
void initializeExtensions (Configuration&, Rules&, Extensions&, Log&);
|
void initializeExtensions (Rules&, Extensions&, Log&);
|
||||||
int dispatchCommand (const std::vector <std::string>&, Configuration&, Database&, Rules&, Extensions&, Log&);
|
int dispatchCommand (const std::vector <std::string>&, Database&, Rules&, Extensions&, Log&);
|
||||||
|
|
||||||
// utiŀ.cpp
|
// utiŀ.cpp
|
||||||
std::string osName ();
|
std::string osName ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue