mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdConfig: Added command handling
This commit is contained in:
parent
8bf0a2a0bc
commit
7f3dce9efd
1 changed files with 103 additions and 0 deletions
|
@ -25,9 +25,51 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
#include <shared.h>
|
||||
#include <format.h>
|
||||
#include <timew.h>
|
||||
#include <stack>
|
||||
#include <iostream>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static bool setConfigVariable (std::string name, std::string value, bool confirmation /* = false */)
|
||||
{
|
||||
bool change = false;
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static int unsetConfigVariable (std::string name, bool confirmation /* = false */)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// a.b.c.d = 1
|
||||
// a.b.d = 2
|
||||
// a.b.e = 3
|
||||
// b.d.e = 4
|
||||
// f = 5
|
||||
//
|
||||
// define a:
|
||||
// b:
|
||||
// c:
|
||||
// d = 1
|
||||
// d = 2
|
||||
// e = 3
|
||||
//
|
||||
// define b:
|
||||
// d:
|
||||
// e = 4
|
||||
//
|
||||
// f = 5
|
||||
static void showAllSettings (const Rules& rules)
|
||||
{
|
||||
for (auto& name : rules.all ())
|
||||
std::cout << name << " = " << rules.get (name) << "\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdConfig (
|
||||
const CLI& cli,
|
||||
|
@ -41,6 +83,67 @@ int CmdConfig (
|
|||
|
||||
int rc = 0;
|
||||
|
||||
// Get the command line args that are not binary, ext or command.
|
||||
auto words = cli.getWords ();
|
||||
|
||||
// Support:
|
||||
// task config name value # set name to value
|
||||
// task config name "" # set name to blank
|
||||
// task config name # remove name
|
||||
if (words.size ())
|
||||
{
|
||||
bool confirmation = rules.getBoolean ("confirmation");
|
||||
std::string name = words[0];
|
||||
std::string value = "";
|
||||
|
||||
// Join the remaining words into config variable's value
|
||||
if (words.size () > 1)
|
||||
{
|
||||
for (unsigned int i = 1; i < words.size (); ++i)
|
||||
{
|
||||
if (i > 1)
|
||||
value += " ";
|
||||
|
||||
value += words[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (name != "")
|
||||
{
|
||||
bool change = false;
|
||||
|
||||
// task config name value
|
||||
// task config name ""
|
||||
if (words.size () > 1)
|
||||
change = setConfigVariable(name, value, confirmation);
|
||||
|
||||
// task config name
|
||||
else
|
||||
{
|
||||
bool found = false;
|
||||
rc = unsetConfigVariable(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 (change)
|
||||
std::cout << "Config file " << rules.file () << " modified.\n";
|
||||
else
|
||||
std::cout << "No changes made.\n";
|
||||
}
|
||||
else
|
||||
showAllSettings (rules);
|
||||
}
|
||||
else
|
||||
showAllSettings (rules);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue