mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 13:37:20 +02:00
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.
This commit is contained in:
parent
d49222e8c7
commit
9799fcefed
3 changed files with 20 additions and 22 deletions
20
src/CLI.cpp
20
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 <A>::const_iterator a;
|
std::vector <A>::const_iterator a;
|
||||||
for (a = _args.begin (); a != _args.end (); ++a)
|
for (a = _args.begin (); a != _args.end (); ++a)
|
||||||
|
{
|
||||||
if (a->hasTag ("RC"))
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <File.h>
|
||||||
|
|
||||||
// Represents a single argument.
|
// Represents a single argument.
|
||||||
class A
|
class A
|
||||||
|
@ -69,7 +70,7 @@ public:
|
||||||
void initialize (int, const char**);
|
void initialize (int, const char**);
|
||||||
void add (const std::string&);
|
void add (const std::string&);
|
||||||
void analyze (bool parse = true);
|
void analyze (bool parse = true);
|
||||||
const std::string getOverride ();
|
void getOverride (std::string&, File&);
|
||||||
const std::string getFilter ();
|
const std::string getFilter ();
|
||||||
const std::vector <std::string> getWords ();
|
const std::vector <std::string> getWords ();
|
||||||
const std::vector <std::string> getModifications ();
|
const std::vector <std::string> getModifications ();
|
||||||
|
|
|
@ -139,7 +139,7 @@ int Context::initialize (int argc, const char** argv)
|
||||||
|
|
||||||
// Scan command line for 'rc:<file>' only.
|
// Scan command line for 'rc:<file>' only.
|
||||||
cli.initialize (argc, argv); // task arg0 arg1 ...
|
cli.initialize (argc, argv); // task arg0 arg1 ...
|
||||||
rc_file._data = cli.getOverride ();
|
cli.getOverride (home_dir, rc_file); // <-- <file>
|
||||||
|
|
||||||
// TASKRC environment variable overrides the command line.
|
// TASKRC environment variable overrides the command line.
|
||||||
char* override = getenv ("TASKRC");
|
char* override = getenv ("TASKRC");
|
||||||
|
@ -165,28 +165,11 @@ int Context::initialize (int argc, const char** argv)
|
||||||
|
|
||||||
// Process 'rc:<file>' command line override.
|
// Process 'rc:<file>' command line override.
|
||||||
parser.findOverrides (); // rc:<file> rc.<name>:<value>
|
parser.findOverrides (); // rc:<file> rc.<name>:<value>
|
||||||
parser.getOverrides (home_dir, rc_file); // <-- <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
|
// The data location, Context::data_dir, is determined from the assumed
|
||||||
// location (~/.task), or set by data.location in the config file, or
|
// location (~/.task), or set by data.location in the config file, or
|
||||||
// overridden by rc.data.location on the command line.
|
// overridden by rc.data.location on the command line.
|
||||||
parser.getDataLocation (data_dir); // <-- rc.data.location=<location>
|
parser.getDataLocation (data_dir); // <-- rc.data.location=<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");
|
override = getenv ("TASKDATA");
|
||||||
if (override)
|
if (override)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue