- Fixed bug #683, in which the 'config' command sometimes edited comments
  instead of the proper line in .taskrc (thanks to Erlan Sergaziev).
This commit is contained in:
Paul Beckingham 2011-07-11 01:51:14 -04:00
parent 523173e27e
commit 4522877b43
2 changed files with 56 additions and 40 deletions

View file

@ -94,6 +94,8 @@
certain circumstances (thanks to Steve Rader). certain circumstances (thanks to Steve Rader).
+ Fixed bug #645 & #660, which prevented logically combining report filters + Fixed bug #645 & #660, which prevented logically combining report filters
(thanks to Bryce Harrington). (thanks to Bryce Harrington).
+ Fixed bug #683, in which the 'config' command sometimes edited comments
instead of the proper line in .taskrc (thanks to Erlan Sergaziev).
+ Fixed bug #691, which was a mis-reporting of file lock state even when file + Fixed bug #691, which was a mis-reporting of file lock state even when file
locking was turned off (thanks to Tom Duffy). locking was turned off (thanks to Tom Duffy).
+ Fixed bug #696, where the command line parser was confused by a single '-' + Fixed bug #696, where the command line parser was confused by a single '-'

View file

@ -78,22 +78,26 @@ int CmdConfig::execute (std::string& output)
bool change = false; bool change = false;
// Read .taskrc (or equivalent) // Read .taskrc (or equivalent)
std::string contents; std::vector <std::string> contents;
File::read (context.config.original_file, contents); File::read (context.config.original_file, contents);
// task config name value // task config name value
// task config name "" // task config name ""
if (words.size () || if (words.size () > 1)
words.back ()._first == "")
{ {
// Find existing entry & overwrite bool found = false;
std::string::size_type pos = contents.find (name + "="); std::vector <std::string>::iterator line;
if (pos != std::string::npos) for (line = contents.begin (); line != contents.end (); ++line)
{ {
std::string::size_type eol = contents.find_first_of ("\r\f\n", pos); // If there is a comment on the line, it must follow the pattern.
if (eol == std::string::npos) std::string::size_type comment = line->find ("#");
throw std::string ("Cannot find EOL after entry '") + name + "'."; std::string::size_type pos = line->find (name + "=");
if (pos != std::string::npos &&
(comment == std::string::npos ||
comment > pos))
{
found = true;
if (confirm (std::string ("Are you sure you want to change the value of '") if (confirm (std::string ("Are you sure you want to change the value of '")
+ name + name
+ "' from '" + "' from '"
@ -101,45 +105,54 @@ int CmdConfig::execute (std::string& output)
+ "' to '" + "' to '"
+ value + "'?")) + value + "'?"))
{ {
contents = contents.substr (0, pos) if (comment != std::string::npos)
+ name + "=" + value *line = name + "=" + value + " " + line->substr (comment);
+ contents.substr (eol); else
*line = name + "=" + value;
change = true; change = true;
} }
} }
}
// Not found, so append instead. // Not found, so append instead.
else if (!found &&
confirm (std::string ("Are you sure you want to add '") + name + "' with a value of '" + value + "'?"))
{ {
if (confirm (std::string ("Are you sure you want to add '") + name + "' with a value of '" + value + "'?")) contents.push_back (name + "=" + value);
{
contents = contents
+ "\n"
+ name + "=" + value
+ "\n";
change = true; change = true;
} }
} }
}
// task config name // task config name
else else
{ {
bool found = false;
std::vector <std::string>::iterator line;
for (line = contents.begin (); line != contents.end (); ++line)
{
// If there is a comment on the line, it must follow the pattern.
std::string::size_type comment = line->find ("#");
std::string::size_type pos = line->find (name + "=");
if (pos != std::string::npos &&
(comment == std::string::npos ||
comment > pos))
{
found = true;
// Remove name // Remove name
std::string::size_type pos = contents.find (name + "=");
if (pos == std::string::npos)
throw std::string ("No entry named '") + name + "' found.";
std::string::size_type eol = contents.find_first_of ("\r\f\n", pos);
if (eol == std::string::npos)
throw std::string ("Cannot find EOL after entry '") + name + "'.";
if (confirm (std::string ("Are you sure you want to remove '") + name + "'?")) if (confirm (std::string ("Are you sure you want to remove '") + name + "'?"))
{ {
contents = contents.substr (0, pos) + contents.substr (eol + 1); *line = "";
change = true; change = true;
} }
} }
}
if (!found)
throw std::string ("No entry named '") + name + "' found.";
}
// Write .taskrc (or equivalent) // Write .taskrc (or equivalent)
if (change) if (change)
@ -154,6 +167,7 @@ int CmdConfig::execute (std::string& output)
} }
else else
throw std::string ("Specify the name of a config variable to modify."); throw std::string ("Specify the name of a config variable to modify.");
output = out.str (); output = out.str ();
} }
else else