mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
init: Uses CLI instead of raw args
This commit is contained in:
parent
bca881f19d
commit
9054500b8d
1 changed files with 23 additions and 46 deletions
69
src/init.cpp
69
src/init.cpp
|
@ -204,54 +204,31 @@ int dispatchCommand (
|
||||||
}
|
}
|
||||||
log.write ("command", combined);
|
log.write ("command", combined);
|
||||||
|
|
||||||
if (args.size () > 1)
|
// Dispatch to the right command function.
|
||||||
|
std::string command = cli.getCommand ();
|
||||||
|
if (command != "")
|
||||||
{
|
{
|
||||||
std::vector <std::string> allCommands =
|
// These signatures are æxpected to be all different, therefore no
|
||||||
{
|
// command to fn mapping.
|
||||||
"clear", "config", "continue", "define", "diagnostics", "export",
|
if (command == "clear") status = CmdClear ( );
|
||||||
"extensions", "gaps", "help", "import", "log", "report", "start", "stop",
|
else if (command == "config") status = CmdConfig ( );
|
||||||
"tags", "track", "undo"
|
else if (command == "continue") status = CmdContinue ( rules, database, log);
|
||||||
};
|
else if (command == "define") status = CmdDefine (args, rules, database, log);
|
||||||
|
else if (command == "diagnostics") status = CmdDiagnostics ( rules, database, extensions, log);
|
||||||
std::vector <std::string> matches;
|
else if (command == "export") status = CmdExport (args, rules, database, log);
|
||||||
autoComplete (args[1], allCommands, matches);
|
else if (command == "extensions") status = CmdExtensions ( rules, extensions );
|
||||||
if (matches.size () == 1)
|
else if (command == "gaps") status = CmdGaps ( );
|
||||||
{
|
else if (command == "help") status = CmdHelp (args, log);
|
||||||
// These signatures are æxpected to be all different, therefore no
|
else if (command == "import") status = CmdImport ( );
|
||||||
// command to fn mapping.
|
else if (command == "log") status = CmdLog (args, log);
|
||||||
if (matches[0] == allCommands[0]) status = CmdClear ( );
|
else if (command == "report") status = CmdReport (args, rules, database, extensions, log);
|
||||||
else if (matches[0] == allCommands[1]) status = CmdConfig ( );
|
else if (command == "start") status = CmdStart (args, rules, database, log);
|
||||||
else if (matches[0] == allCommands[2]) status = CmdContinue ( rules, database, log);
|
else if (command == "stop") status = CmdStop (args, rules, database, log);
|
||||||
else if (matches[0] == allCommands[3]) status = CmdDefine (args, rules, database, log);
|
else if (command == "tags") status = CmdTags ( rules, database, log);
|
||||||
else if (matches[0] == allCommands[4]) status = CmdDiagnostics ( rules, database, extensions, log);
|
else if (command == "track") status = CmdTrack ( );
|
||||||
else if (matches[0] == allCommands[5]) status = CmdExport (args, rules, database, log);
|
else if (command == "undo") status = CmdUndo ( );
|
||||||
else if (matches[0] == allCommands[6]) status = CmdExtensions ( rules, extensions );
|
|
||||||
else if (matches[0] == allCommands[7]) status = CmdGaps ( );
|
|
||||||
else if (matches[0] == allCommands[8]) status = CmdHelp (args, log);
|
|
||||||
else if (matches[0] == allCommands[9]) status = CmdImport ( );
|
|
||||||
else if (matches[0] == allCommands[10]) status = CmdLog (args, log);
|
|
||||||
else if (matches[0] == allCommands[11]) status = CmdReport (args, rules, database, extensions, log);
|
|
||||||
else if (matches[0] == allCommands[12]) status = CmdStart (args, rules, database, log);
|
|
||||||
else if (matches[0] == allCommands[13]) status = CmdStop (args, rules, database, log);
|
|
||||||
else if (matches[0] == allCommands[14]) status = CmdTags ( rules, database, log);
|
|
||||||
else if (matches[0] == allCommands[15]) status = CmdTrack ( );
|
|
||||||
else if (matches[0] == allCommands[16]) status = CmdUndo ( );
|
|
||||||
}
|
|
||||||
else if (matches.size () == 0)
|
|
||||||
{
|
|
||||||
CmdHelpUsage ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "timew: '" << args[1] << "' is not a command. See 'timew help'.\n"
|
|
||||||
<< "\n"
|
|
||||||
<< "Did you mean one of these?\n";
|
|
||||||
|
|
||||||
for (const auto& command : matches)
|
|
||||||
std::cout << " " << command << "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (args.size () == 1)
|
else
|
||||||
{
|
{
|
||||||
status = CmdDefault (rules, database);
|
status = CmdDefault (rules, database);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue