init: Uses CLI instead of raw args

This commit is contained in:
Paul Beckingham 2016-04-03 15:26:55 -04:00
parent bca881f19d
commit 9054500b8d

View file

@ -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);
} }