mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
#9 TI-1: Return early, use return value of delegated CmdShow
This commit is contained in:
parent
36134ca5fc
commit
af621a3eef
1 changed files with 60 additions and 49 deletions
|
@ -279,67 +279,78 @@ int CmdConfig (
|
||||||
// timew config name value # set name to value
|
// timew config name value # set name to value
|
||||||
// timew config name "" # set name to blank
|
// timew config name "" # set name to blank
|
||||||
// timew config name # remove name
|
// timew config name # remove name
|
||||||
if (! words.empty ())
|
if (words.empty ())
|
||||||
{
|
{
|
||||||
bool confirmation = rules.getBoolean ("confirmation");
|
return CmdShow (rules);
|
||||||
std::string name = words[0];
|
}
|
||||||
std::string value = "";
|
|
||||||
|
|
||||||
// Join the remaining words into config variable's value
|
bool confirmation = rules.getBoolean ("confirmation");
|
||||||
if (words.size () > 1)
|
std::string name = words[0];
|
||||||
|
std::string value;
|
||||||
|
|
||||||
|
if (name.empty ())
|
||||||
|
{
|
||||||
|
return CmdShow (rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join the remaining words into config variable's value
|
||||||
|
if (words.size () > 1)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 1; i < words.size (); ++i)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 1; i < words.size (); ++i)
|
if (i > 1)
|
||||||
{
|
{
|
||||||
if (i > 1)
|
value += " ";
|
||||||
value += " ";
|
|
||||||
|
|
||||||
value += words[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value += words[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool change = false;
|
||||||
|
|
||||||
|
// timew config name value
|
||||||
|
// timew config name ""
|
||||||
|
if (words.size () > 1)
|
||||||
|
{
|
||||||
|
change = setConfigVariable (database, rules, name, value, confirmation);
|
||||||
|
if (!change)
|
||||||
|
{
|
||||||
|
rc = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// timew config name
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
rc = unsetConfigVariable (database, rules, name, confirmation);
|
||||||
|
if (rc == 0)
|
||||||
|
{
|
||||||
|
change = true;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
else if (rc == 1)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! name.empty ())
|
if (!found)
|
||||||
{
|
{
|
||||||
bool change = false;
|
throw format ("No entry named '{1}' found.", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// timew config name value
|
if (rules.getBoolean ("verbose"))
|
||||||
// timew config name ""
|
{
|
||||||
if (words.size () > 1)
|
if (change)
|
||||||
{
|
{
|
||||||
change = setConfigVariable (database, rules, name, value, confirmation);
|
std::cout << "Config file " << rules.file () << " modified.\n";
|
||||||
if (! change)
|
|
||||||
rc = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// timew config name
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
rc = unsetConfigVariable (database, rules, name, confirmation);
|
|
||||||
if (rc == 0)
|
|
||||||
{
|
|
||||||
change = true;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
else if (rc == 1)
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
throw format ("No entry named '{1}' found.", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rules.getBoolean ("verbose"))
|
|
||||||
{
|
|
||||||
if (change)
|
|
||||||
std::cout << "Config file " << rules.file () << " modified.\n";
|
|
||||||
else
|
|
||||||
std::cout << "No changes made.\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CmdShow (rules);
|
{
|
||||||
|
std::cout << "No changes made.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CmdShow (rules);
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue