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
63
src/init.cpp
63
src/init.cpp
|
@ -204,54 +204,31 @@ int dispatchCommand (
|
|||
}
|
||||
log.write ("command", combined);
|
||||
|
||||
if (args.size () > 1)
|
||||
{
|
||||
std::vector <std::string> allCommands =
|
||||
{
|
||||
"clear", "config", "continue", "define", "diagnostics", "export",
|
||||
"extensions", "gaps", "help", "import", "log", "report", "start", "stop",
|
||||
"tags", "track", "undo"
|
||||
};
|
||||
|
||||
std::vector <std::string> matches;
|
||||
autoComplete (args[1], allCommands, matches);
|
||||
if (matches.size () == 1)
|
||||
// Dispatch to the right command function.
|
||||
std::string command = cli.getCommand ();
|
||||
if (command != "")
|
||||
{
|
||||
// These signatures are æxpected to be all different, therefore no
|
||||
// command to fn mapping.
|
||||
if (matches[0] == allCommands[0]) status = CmdClear ( );
|
||||
else if (matches[0] == allCommands[1]) status = CmdConfig ( );
|
||||
else if (matches[0] == allCommands[2]) status = CmdContinue ( rules, database, log);
|
||||
else if (matches[0] == allCommands[3]) status = CmdDefine (args, rules, database, log);
|
||||
else if (matches[0] == allCommands[4]) status = CmdDiagnostics ( rules, database, extensions, log);
|
||||
else if (matches[0] == allCommands[5]) status = CmdExport (args, rules, database, log);
|
||||
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 ();
|
||||
if (command == "clear") status = CmdClear ( );
|
||||
else if (command == "config") status = CmdConfig ( );
|
||||
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);
|
||||
else if (command == "export") status = CmdExport (args, rules, database, log);
|
||||
else if (command == "extensions") status = CmdExtensions ( rules, extensions );
|
||||
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 == "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);
|
||||
else if (command == "tags") status = CmdTags ( rules, database, log);
|
||||
else if (command == "track") status = CmdTrack ( );
|
||||
else if (command == "undo") status = CmdUndo ( );
|
||||
}
|
||||
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)
|
||||
{
|
||||
status = CmdDefault (rules, database);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue