| 805 | } |
| 806 | |
| 807 | void fdbcliCompCmd(std::string const& text, std::vector<std::string>& lc) { |
| 808 | bool err, partial; |
| 809 | std::string whole_line = text; |
| 810 | auto parsed = parseLine(whole_line, err, partial); |
| 811 | if (err || partial) // If there was an error, or we are partially through a quoted sequence |
| 812 | return; |
| 813 | |
| 814 | auto tokens = parsed.back(); |
| 815 | int count = tokens.size(); |
| 816 | |
| 817 | // for(int i = 0; i < count; i++) { |
| 818 | // printf("Token (%d): `%s'\n", i, tokens[i].toString().c_str()); |
| 819 | // } |
| 820 | |
| 821 | std::string ntext = ""; |
| 822 | std::string base_input = text; |
| 823 | |
| 824 | // If there is a token and the input does not end in a space |
| 825 | if (count && text.size() > 0 && text[text.size() - 1] != ' ') { |
| 826 | count--; // Ignore the last token for purposes of later code |
| 827 | ntext = tokens.back().toString(); |
| 828 | base_input = whole_line.substr(0, whole_line.rfind(ntext)); |
| 829 | } |
| 830 | |
| 831 | // printf("final text (%d tokens): `%s' & `%s'\n", count, base_input.c_str(), ntext.c_str()); |
| 832 | |
| 833 | if (!count) { |
| 834 | cmdGenerator(ntext.c_str(), lc); |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | if (tokencmp(tokens[0], "help") && count == 1) { |
| 839 | helpGenerator(ntext.c_str(), lc); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | if (tokencmp(tokens[0], "option")) { |
| 844 | if (count == 1) |
| 845 | onOffGenerator(ntext.c_str(), base_input.c_str(), lc); |
| 846 | if (count == 2) |
| 847 | optionGenerator(ntext.c_str(), base_input.c_str(), lc); |
| 848 | } |
| 849 | |
| 850 | if (tokencmp(tokens[0], "writemode") && count == 1) { |
| 851 | onOffGenerator(ntext.c_str(), base_input.c_str(), lc); |
| 852 | } |
| 853 | |
| 854 | auto itr = CommandFactory::completionGenerators().find(tokens[0].toString()); |
| 855 | if (itr != CommandFactory::completionGenerators().end()) { |
| 856 | itr->second(ntext.c_str(), base_input.c_str(), lc, tokens); |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | void LogCommand(std::string line, UID randomID, std::string errMsg) { |
| 861 | printf("%s\n", errMsg.c_str()); |
no test coverage detected