From ebdf8a944dd0496cd9be6ad1b1eb22a49f51ead8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 3 Apr 2016 21:31:59 -0400 Subject: [PATCH] CmdLog: Converted to CLI --- src/commands/CmdLog.cpp | 22 ++++++++++++++-------- src/commands/commands.h | 3 ++- src/init.cpp | 2 +- src/timew.cpp | 3 ++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/commands/CmdLog.cpp b/src/commands/CmdLog.cpp index 2be89b52..4904329b 100644 --- a/src/commands/CmdLog.cpp +++ b/src/commands/CmdLog.cpp @@ -25,23 +25,29 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include +#include #include #include #include +#include //////////////////////////////////////////////////////////////////////////////// // TODO This may be removed, unless it proves useful. -int CmdLog (const std::vector & args, Log& log) +int CmdLog (CLI& cli, Log& log) { - // If no (extra) arguments, simply write a marker. - if (args.size () >= 3 && - args[2] == "mark") - log.write ("debug", "-------- 8< --------"); + auto words = cli.getWords (); + if (words.size ()) + { + // '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 - log.write ("info", join (" ", std::vector (args.begin () + 2, args.end ()))); + std::cout << "No message specified.\n"; return 0; } diff --git a/src/commands/commands.h b/src/commands/commands.h index 57c21d6a..d49d460b 100644 --- a/src/commands/commands.h +++ b/src/commands/commands.h @@ -27,6 +27,7 @@ #ifndef INCLUDED_COMMANDS #define INCLUDED_COMMANDS +#include #include #include #include @@ -45,7 +46,7 @@ int CmdExtensions ( Rules&, Extensi int CmdGaps ( ); int CmdHelpUsage ( ); int CmdHelp (const std::vector &, Log&); -int CmdLog (const std::vector &, Log&); +int CmdLog (CLI&, Log&); int CmdImport ( ); int CmdReport (const std::vector &, Rules&, Database&, Extensions&, Log&); int CmdStart (const std::vector &, Rules&, Database&, Log&); diff --git a/src/init.cpp b/src/init.cpp index 8d83f34b..854e32ca 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -222,7 +222,7 @@ int dispatchCommand ( else if (command == "gaps") status = CmdGaps ( ); else if (command == "help") status = CmdHelp (args, log); 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 == "start") status = CmdStart (args, rules, database, log); else if (command == "stop") status = CmdStop (args, rules, database, log); diff --git a/src/timew.cpp b/src/timew.cpp index 97f79d18..6b1f46c2 100644 --- a/src/timew.cpp +++ b/src/timew.cpp @@ -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 // buffers the messages until it has a file name to write to. 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 // commands.