|
35 | 35 | #include <vector> |
36 | 36 | #include <memory> |
37 | 37 | #include <functional> |
| 38 | +#include <algorithm> |
38 | 39 | #include <cctype> // std::isspace |
39 | 40 | #include <type_traits> |
40 | 41 | #include <boost/lexical_cast.hpp> |
|
44 | 45 | #include "historystorage.h" |
45 | 46 | #include "localhistorystorage.h" |
46 | 47 |
|
47 | | -#define CLI_DEPRECATED_API |
| 48 | +// #define CLI_DEPRECATED_API |
48 | 49 |
|
49 | 50 | namespace cli |
50 | 51 | { |
@@ -224,7 +225,7 @@ namespace cli |
224 | 225 | { |
225 | 226 | public: |
226 | 227 | CliSession(Cli& _cli, std::ostream& _out, std::size_t historySize = 100); |
227 | | - ~CliSession() { cli.UnRegister(out); } |
| 228 | + virtual ~CliSession() { cli.UnRegister(out); } |
228 | 229 |
|
229 | 230 | // disable value semantics |
230 | 231 | CliSession(const CliSession&) = delete; |
@@ -804,8 +805,8 @@ namespace cli |
804 | 805 | VariadicFunctionCommand( |
805 | 806 | const std::string& _name, |
806 | 807 | F fun, |
807 | | - const std::string& desc = "unknown command", |
808 | | - const std::vector<std::string>& parDesc = {} |
| 808 | + const std::string& desc, |
| 809 | + const std::vector<std::string>& parDesc |
809 | 810 | ) |
810 | 811 | : Command(_name), func(std::move(fun)), description(desc), parameterDesc(parDesc) |
811 | 812 | { |
@@ -898,7 +899,7 @@ namespace cli |
898 | 899 | if (!found) found = current -> ScanCmds(std::move(strs), *this); // last use of strs |
899 | 900 |
|
900 | 901 | if (!found) // error msg if not found |
901 | | - out << "Command unknown: " << cmd << "\n"; |
| 902 | + out << "wrong command: " << cmd << "\n"; |
902 | 903 |
|
903 | 904 | return; |
904 | 905 | } |
@@ -926,6 +927,12 @@ namespace cli |
926 | 927 | auto v1 = globalScopeMenu->GetCompletions(currentLine); |
927 | 928 | auto v3 = current->GetCompletions(currentLine); |
928 | 929 | v1.insert(v1.end(), std::make_move_iterator(v3.begin()), std::make_move_iterator(v3.end())); |
| 930 | + |
| 931 | + // removes duplicates (std::unique requires a sorted container) |
| 932 | + std::sort(v1.begin(), v1.end()); |
| 933 | + auto ip = std::unique(v1.begin(), v1.end()); |
| 934 | + v1.resize(std::distance(v1.begin(), ip)); |
| 935 | + |
929 | 936 | return v1; |
930 | 937 | } |
931 | 938 |
|
|
0 commit comments