From 9799fcefedc96a6b08afefa77fc934c47eceb0ea Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 2 Nov 2014 21:31:25 -0500 Subject: [PATCH] CLI - Updated ::getOverride to scan all args, display the debug feedback, and derive the home dir. - Removed Parser::getOverrides calls from Context. - Cleaned up dead code in Context::initialize. --- src/CLI.cpp | 20 +++++++++++++++++--- src/CLI.h | 3 ++- src/Context.cpp | 19 +------------------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 386208dd4..75dc04ae2 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -355,14 +355,28 @@ void CLI::analyze (bool parse /* = true */) } //////////////////////////////////////////////////////////////////////////////// -const std::string CLI::getOverride () +void CLI::getOverride (std::string& home, File& rc) { std::vector ::const_iterator a; for (a = _args.begin (); a != _args.end (); ++a) + { if (a->hasTag ("RC")) - return a->attribute ("file"); + { + rc = File (a->attribute ("file")); + home = rc; - return ""; + std::string::size_type last_slash = rc._data.rfind ("/"); + if (last_slash != std::string::npos) + home = rc._data.substr (0, last_slash); + else + home = "."; + + context.header (format (STRING_PARSER_ALTERNATE_RC, rc._data)); + + // Keep looping, because if there are multiple rc:file arguments, the last + // one should dominate. + } + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CLI.h b/src/CLI.h index d9469ffcc..ba6f06499 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -29,6 +29,7 @@ #include #include #include +#include // Represents a single argument. class A @@ -69,7 +70,7 @@ public: void initialize (int, const char**); void add (const std::string&); void analyze (bool parse = true); - const std::string getOverride (); + void getOverride (std::string&, File&); const std::string getFilter (); const std::vector getWords (); const std::vector getModifications (); diff --git a/src/Context.cpp b/src/Context.cpp index 32b7dff1a..7f13ea2df 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -139,7 +139,7 @@ int Context::initialize (int argc, const char** argv) // Scan command line for 'rc:' only. cli.initialize (argc, argv); // task arg0 arg1 ... - rc_file._data = cli.getOverride (); + cli.getOverride (home_dir, rc_file); // <-- // TASKRC environment variable overrides the command line. char* override = getenv ("TASKRC"); @@ -165,28 +165,11 @@ int Context::initialize (int argc, const char** argv) // Process 'rc:' command line override. parser.findOverrides (); // rc: rc.: - parser.getOverrides (home_dir, rc_file); // <-- -/* - home_dir = rc_file; - std::string::size_type last_slash = rc._data.rfind ("/"); - if (last_slash != std::string::npos) - home_dir = rc_file.parent (); - else - home_dir = "."; - std::cout << "# home_dir=" << home_dir << "\n"; -*/ // 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= -/* - if (cli._overrides.find ("data.location") != cli._overrides.end ()) - data_dir = cli._overrides["data.location"]; - else - data_dir = config.get ("data.location"); - std::cout << "# data_dir=" << data_dir << "\n"; -*/ override = getenv ("TASKDATA"); if (override)