#9 TI-1: Return early, use return value of delegated CmdShow

This commit is contained in:
Thomas Lauf 2018-07-18 22:32:05 +02:00
parent 36134ca5fc
commit af621a3eef

View file

@ -279,11 +279,19 @@ int CmdConfig (
// timew config name value # set name to value
// timew config name "" # set name to blank
// timew config name # remove name
if (! words.empty ())
if (words.empty ())
{
return CmdShow (rules);
}
bool confirmation = rules.getBoolean ("confirmation");
std::string name = words[0];
std::string value = "";
std::string value;
if (name.empty ())
{
return CmdShow (rules);
}
// Join the remaining words into config variable's value
if (words.size () > 1)
@ -291,14 +299,14 @@ int CmdConfig (
for (unsigned int i = 1; i < words.size (); ++i)
{
if (i > 1)
{
value += " ";
}
value += words[i];
}
}
if (! name.empty ())
{
bool change = false;
// timew config name value
@ -307,9 +315,10 @@ int CmdConfig (
{
change = setConfigVariable (database, rules, name, value, confirmation);
if (!change)
{
rc = 1;
}
}
// timew config name
else
{
@ -321,25 +330,27 @@ int CmdConfig (
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
CmdShow (rules);
}
else
CmdShow (rules);
return rc;
}