return false if similar command(s) not found
| 1854 | |
| 1855 | // return false if similar command(s) not found |
| 1856 | static bool PromptSimilarCmd(const char* msg) { |
| 1857 | if (msg == NULL) { |
| 1858 | return false; |
| 1859 | } |
| 1860 | bool found = false; |
| 1861 | int64_t len = strlen(msg); |
| 1862 | int64_t threshold = int64_t((len * 0.3 < 3) ? 3 : len * 0.3); |
| 1863 | int count = sizeof(builtin_cmd_list) / sizeof(char*); |
| 1864 | for (int i = 0; i < count; i += 2) { |
| 1865 | if (EditDistance(msg, builtin_cmd_list[i]) <= threshold) { |
| 1866 | if (!found) { |
| 1867 | std::cout << "Did you mean:" << std::endl; |
| 1868 | found = true; |
| 1869 | } |
| 1870 | std::cout << " " << builtin_cmd_list[i] << std::endl; |
| 1871 | } |
| 1872 | } |
| 1873 | return found; |
| 1874 | } |
| 1875 | |
| 1876 | static void PrintUnknownCmdHelpInfo(const char* msg) { |
| 1877 | if (msg != NULL) { |
no test coverage detected