CLI2: Migrated static methods

- The old CLI object has three static methods that are used for extracting
  information from the command line before parsing takes place. These include
  rc.name:value and rc:value and code that applies those overrides to
  Context::Config. These methods are moved to CLI2 - being static it makes no
  difference where they reside.
- Context::initialize now calls the CLI2 versions only.
This commit is contained in:
Paul Beckingham 2015-06-13 13:44:54 -04:00
parent ca90893216
commit 5602413acd
3 changed files with 0 additions and 88 deletions

View file

@ -213,88 +213,6 @@ const std::string A::dump () const
return output;
}
////////////////////////////////////////////////////////////////////////////////
// Static method.
void CLI::getOverride (int argc, const char** argv, std::string& home, File& rc)
{
for (int i = 0; i < argc; ++i)
{
std::string raw = argv[i];
if (raw == "--")
return;
if (raw.length () > 3 &&
raw.substr (0, 3) == "rc:")
{
rc = raw.substr (3);
home = ".";
auto last_slash = rc._data.rfind ("/");
if (last_slash != std::string::npos)
home = rc.parent ();
context.header (format (STRING_PARSER_ALTERNATE_RC, rc._data));
// Keep looping, because if there are multiple rc:file arguments, the last
// one should dominate.
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Look for CONFIG data.location and initialize a Path object.
// Static method.
void CLI::getDataLocation (int argc, const char** argv, Path& data)
{
std::string location = context.config.get ("data.location");
if (location != "")
data = location;
for (int i = 0; i < argc; ++i)
{
std::string raw = argv[i];
if (raw == "--")
break;
if (raw.length () > 17 &&
raw.substr (0, 16) == "rc.data.location")
{
data = Directory (raw.substr (17));
context.header (format (STRING_PARSER_ALTERNATE_DATA, (std::string) data));
// Keep looping, because if there are multiple rc:file arguments, the last
// one should dominate.
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Static method.
void CLI::applyOverrides (int argc, const char** argv)
{
for (int i = 0; i < argc; ++i)
{
std::string raw = argv[i];
if (raw == "--")
break;
if (raw.length () > 3 &&
raw.substr (0, 3) == "rc.")
{
auto sep = raw.find ('=', 3);
if (sep == std::string::npos)
sep = raw.find (':', 3);
if (sep != std::string::npos)
{
std::string name = raw.substr (3, sep - 3);
std::string value = raw.substr (sep + 1);
context.config.set (name, value);
context.footnote (format (STRING_PARSER_OVERRIDE_RC, name, value));
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
CLI::CLI ()
: _strict (false)

View file

@ -65,9 +65,6 @@ class CLI
{
public:
static int minimumMatchLength;
static void getOverride (int, const char**, std::string&, File&);
static void getDataLocation (int, const char**, Path&);
static void applyOverrides (int, const char**);
public:
CLI ();

View file

@ -110,7 +110,6 @@ int Context::initialize (int argc, const char** argv)
////////////////////////////////////////////////////////////////////////////
CLI2::getOverride (argc, argv, home_dir, rc_file);
CLI::getOverride (argc, argv, home_dir, rc_file);
char* override = getenv ("TASKRC");
if (override)
@ -122,7 +121,6 @@ int Context::initialize (int argc, const char** argv)
config.clear ();
config.load (rc_file);
CLI2::applyOverrides (argc, argv);
CLI::applyOverrides (argc, argv);
////////////////////////////////////////////////////////////////////////////
//
@ -136,7 +134,6 @@ int Context::initialize (int argc, const char** argv)
////////////////////////////////////////////////////////////////////////////
CLI2::getDataLocation (argc, argv, data_dir);
CLI::getDataLocation (argc, argv, data_dir);
override = getenv ("TASKDATA");
if (override)