mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdLog: Converted to CLI
This commit is contained in:
parent
63d728af5c
commit
ebdf8a944d
4 changed files with 19 additions and 11 deletions
|
@ -25,23 +25,29 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <Log.h>
|
#include <commands.h>
|
||||||
#include <shared.h>
|
#include <shared.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// TODO This may be removed, unless it proves useful.
|
// TODO This may be removed, unless it proves useful.
|
||||||
int CmdLog (const std::vector <std::string>& args, Log& log)
|
int CmdLog (CLI& cli, Log& log)
|
||||||
{
|
{
|
||||||
// If no (extra) arguments, simply write a marker.
|
auto words = cli.getWords ();
|
||||||
if (args.size () >= 3 &&
|
if (words.size ())
|
||||||
args[2] == "mark")
|
{
|
||||||
log.write ("debug", "-------- 8< --------");
|
// 'timew log mark' writes a marker.
|
||||||
|
if (words[0] == "mark")
|
||||||
|
log.write ("debug", "-------- 8< --------");
|
||||||
|
|
||||||
// Othewise write args to the log.
|
// 'timew log ...' writes '...' to log.
|
||||||
|
else
|
||||||
|
log.write ("info", join (" ", words));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
log.write ("info", join (" ", std::vector <std::string> (args.begin () + 2, args.end ())));
|
std::cout << "No message specified.\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#ifndef INCLUDED_COMMANDS
|
#ifndef INCLUDED_COMMANDS
|
||||||
#define INCLUDED_COMMANDS
|
#define INCLUDED_COMMANDS
|
||||||
|
|
||||||
|
#include <CLI.h>
|
||||||
#include <Rules.h>
|
#include <Rules.h>
|
||||||
#include <Database.h>
|
#include <Database.h>
|
||||||
#include <Extensions.h>
|
#include <Extensions.h>
|
||||||
|
@ -45,7 +46,7 @@ int CmdExtensions ( Rules&, Extensi
|
||||||
int CmdGaps ( );
|
int CmdGaps ( );
|
||||||
int CmdHelpUsage ( );
|
int CmdHelpUsage ( );
|
||||||
int CmdHelp (const std::vector <std::string>&, Log&);
|
int CmdHelp (const std::vector <std::string>&, Log&);
|
||||||
int CmdLog (const std::vector <std::string>&, Log&);
|
int CmdLog (CLI&, Log&);
|
||||||
int CmdImport ( );
|
int CmdImport ( );
|
||||||
int CmdReport (const std::vector <std::string>&, Rules&, Database&, Extensions&, Log&);
|
int CmdReport (const std::vector <std::string>&, Rules&, Database&, Extensions&, Log&);
|
||||||
int CmdStart (const std::vector <std::string>&, Rules&, Database&, Log&);
|
int CmdStart (const std::vector <std::string>&, Rules&, Database&, Log&);
|
||||||
|
|
|
@ -222,7 +222,7 @@ int dispatchCommand (
|
||||||
else if (command == "gaps") status = CmdGaps ( );
|
else if (command == "gaps") status = CmdGaps ( );
|
||||||
else if (command == "help") status = CmdHelp (args, log);
|
else if (command == "help") status = CmdHelp (args, log);
|
||||||
else if (command == "import") status = CmdImport ( );
|
else if (command == "import") status = CmdImport ( );
|
||||||
else if (command == "log") status = CmdLog (args, log);
|
else if (command == "log") status = CmdLog (cli, log);
|
||||||
else if (command == "report") status = CmdReport (args, rules, database, extensions, log);
|
else if (command == "report") status = CmdReport (args, rules, database, extensions, log);
|
||||||
else if (command == "start") status = CmdStart (args, rules, database, log);
|
else if (command == "start") status = CmdStart (args, rules, database, log);
|
||||||
else if (command == "stop") status = CmdStop (args, rules, database, log);
|
else if (command == "stop") status = CmdStop (args, rules, database, log);
|
||||||
|
|
|
@ -48,7 +48,8 @@ int main (int argc, const char** argv)
|
||||||
// only be given a file name once the rules are loaded. The log therefore
|
// only be given a file name once the rules are loaded. The log therefore
|
||||||
// buffers the messages until it has a file name to write to.
|
// buffers the messages until it has a file name to write to.
|
||||||
Log log;
|
Log log;
|
||||||
CmdLog ({"timew", "log", "mark"}, log);
|
// TODO Need a simpler way to call this.
|
||||||
|
// CmdLog ({"timew", "log", "mark"}, log);
|
||||||
|
|
||||||
// Add entities so that command line tokens such as 'help' are recognized as
|
// Add entities so that command line tokens such as 'help' are recognized as
|
||||||
// commands.
|
// commands.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue