From c8dfa8f7fd6b8372194eeac0d9a69efbbfdd0f04 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 2 Nov 2014 22:10:47 -0500 Subject: [PATCH] CLI - Implemented ::getDataLocation. - Called ::getDataLocation from Context. --- src/CLI.cpp | 23 +++++++++++++++++++++++ src/CLI.h | 2 ++ src/Context.cpp | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 9f29cc3b9..1d8157fa9 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -379,6 +379,29 @@ void CLI::getOverride (std::string& home, File& rc) } } +//////////////////////////////////////////////////////////////////////////////// +// Look for CONFIG data.location and initialize a Path object. +void CLI::getDataLocation (Path& data) +{ + std::string location = context.config.get ("data.location"); + if (location != "") + data = location; + + std::vector ::const_iterator a; + for (a = _args.begin (); a != _args.end (); ++a) + { + if (a->hasTag ("CONFIG") && + a->attribute ("name") == "data.location") + { + data = Directory (a->attribute ("value")); + context.header (format (STRING_PARSER_ALTERNATE_DATA, (std::string) data)); + } + + // Keep looping, because if there are multiple overrides, the last one + // should dominate. + } +} + //////////////////////////////////////////////////////////////////////////////// // Extract all the FILTER-tagged items. const std::string CLI::getFilter () diff --git a/src/CLI.h b/src/CLI.h index 4c643a3ba..3290bed2e 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -29,6 +29,7 @@ #include #include #include +#include #include // Represents a single argument. @@ -71,6 +72,7 @@ public: void add (const std::string&); void analyze (bool parse = true); void getOverride (std::string&, File&); + void getDataLocation (Path&); const std::string getFilter (); const std::vector getWords (); const std::vector getModifications (); diff --git a/src/Context.cpp b/src/Context.cpp index 86fa08882..ca3d9946d 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -166,7 +166,7 @@ int Context::initialize (int argc, const char** argv) // The data location, Context::data_dir, is determined from the assumed // location (~/.task), or set by data.location in the config file, or // overridden by rc.data.location on the command line. - parser.getDataLocation (data_dir); // <-- rc.data.location= + cli.getDataLocation (data_dir); // <-- rc.data.location= override = getenv ("TASKDATA"); if (override)