|
3 | 3 |
|
4 | 4 | #include <Client/ClientBase.h> |
5 | 5 | #include <Client/ClientBaseHelpers.h> |
| 6 | +#include <Client/ClientSlashCommands.h> |
6 | 7 | #include <Client/InternalTextLogs.h> |
7 | 8 | #include <Client/LineReader.h> |
8 | 9 | #include <Client/TerminalKeystrokeInterceptor.h> |
@@ -3686,6 +3687,8 @@ bool ClientBase::processQueryText(const String & text) |
3686 | 3687 | /// Clear the terminal (POSIX `clear`-style), not SQL. Same entry point as `ls` / `\i` meta-commands. |
3687 | 3688 | /// Only in interactive mode, or in clickhouse-local (including `-q`), so `clickhouse-client` batch |
3688 | 3689 | /// mode still parses `clear` as SQL and errors on mistakes (UNKNOWN_IDENTIFIER). |
| 3690 | + /// The `/`-form is also offered by the completion of the line editor - keep the `/`-commands |
| 3691 | + /// dispatched here in sync with `clientSlashCommands`. |
3689 | 3692 | if ((boost::iequals(trimmed_input, "clear") || boost::iequals(trimmed_input, "/clear")) |
3690 | 3693 | && (is_interactive || supportsLocalMetaCommands())) |
3691 | 3694 | { |
@@ -3758,6 +3761,8 @@ bool ClientBase::processQueryText(const String & text) |
3758 | 3761 | /// Interactive `help`/`man` command (in all of the forms `help`, `/help`, `man`, `/man`): render the |
3759 | 3762 | /// embedded documentation for a word from `system.documentation`. Gated like the other meta-commands, |
3760 | 3763 | /// so that batch `clickhouse-client` still parses a query starting with `help`/`man` as SQL. |
| 3764 | + /// The `/`-forms are also offered by the completion of the line editor - keep them in sync with |
| 3765 | + /// `clientSlashCommands`. |
3761 | 3766 | if (is_interactive || supportsLocalMetaCommands()) |
3762 | 3767 | { |
3763 | 3768 | for (const std::string_view prefix : {"help", "/help", "man", "/man"}) |
@@ -3818,6 +3823,15 @@ bool ClientBase::processQueryText(const String & text) |
3818 | 3823 | } |
3819 | 3824 | #endif |
3820 | 3825 |
|
| 3826 | + /// A mistake in the name of a `/`-command would otherwise be parsed as SQL and reported as a |
| 3827 | + /// syntax error at the `/`, which tells the user nothing about the command they meant. Gated |
| 3828 | + /// like the commands themselves, so batch `clickhouse-client` still treats the input as SQL. |
| 3829 | + if (is_interactive || supportsLocalMetaCommands()) |
| 3830 | + { |
| 3831 | + if (auto slash_command_error = diagnoseClientSlashCommand(trimmed_input)) |
| 3832 | + throw Exception(ErrorCodes::BAD_ARGUMENTS, "{}", *slash_command_error); |
| 3833 | + } |
| 3834 | + |
3821 | 3835 | if (query_fuzzer_runs) |
3822 | 3836 | { |
3823 | 3837 | processWithASTFuzzer(text); |
@@ -4365,7 +4379,7 @@ void ClientBase::addCommonOptions(OptionsDescription & options_description) |
4365 | 4379 | ("vertical,E", "Same as --format=Vertical or FORMAT Vertical or \\G at end of command") |
4366 | 4380 |
|
4367 | 4381 | ("highlight,hilite", po::value<bool>()->default_value(true), "Toggle syntax highlighting of the command prompt and the echoed queries (can also use --hilite)") |
4368 | | - ("hints", po::value<bool>()->default_value(true), "Show as-you-type autocompletion hints (ghost text) in interactive mode; navigate with Up/Down or Ctrl-Up/Ctrl-Down. Accept the inline hint with Tab or Right; Enter accepts a hint only after one is explicitly selected, otherwise it runs the query. Requires --highlight and suggestions (disabled by --disable_suggestion). Disable with --hints 0.") |
| 4382 | + ("hints", po::value<bool>()->default_value(true), "Show as-you-type autocompletion hints (ghost text) in interactive mode; navigate with Up/Down or Ctrl-Up/Ctrl-Down. Accept the inline hint with Tab or Right; Enter accepts a hint only after one is explicitly selected, otherwise it runs the query. Requires --highlight (hints need color). The suggestion hints also need the suggestions, so --disable_suggestion turns those off, while the client's /-commands are a static list and stay hinted. Disable with --hints 0.") |
4369 | 4383 |
|
4370 | 4384 | ("ignore-error", "Do not stop processing after an error occurred") |
4371 | 4385 | ("stacktrace", "Print stack traces of exceptions") |
@@ -4806,12 +4820,14 @@ void ClientBase::runInteractive() |
4806 | 4820 | .ignore_shell_suspend = getClientConfiguration().getBool("ignore_shell_suspend", true), |
4807 | 4821 | .embedded_mode = isEmbeeddedClient(), |
4808 | 4822 | .interactive_history_legacy_keymap = getClientConfiguration().getBool("interactive_history_legacy_keymap", false), |
4809 | | - /// Hints need color, so they are enabled only together with highlighting. |
4810 | | - /// Hints need color (highlighting) and the suggestion machinery; `--disable_suggestion` |
4811 | | - /// turns off autocompletion entirely, including the hints. |
| 4823 | + /// Hints need color, so they are enabled only together with highlighting. Client slash |
| 4824 | + /// commands have a static list and can therefore remain hinted when suggestions are off. |
4812 | 4825 | .enable_hints = ConfigHelper::getBool(getClientConfiguration(), "hints", true) |
4813 | | - && ConfigHelper::getBool(getClientConfiguration(), "highlight", true) |
4814 | | - && !getClientConfiguration().getBool("disable_suggestion", false), |
| 4826 | + && ConfigHelper::getBool(getClientConfiguration(), "highlight", true), |
| 4827 | + .enable_suggestion_hints = !getClientConfiguration().getBool("disable_suggestion", false), |
| 4828 | + /// The `/`-commands (`/help`, `/man`, `/clear`) are the client's own; they are dispatched in |
| 4829 | + /// `processQueryText`, so offer them here. |
| 4830 | + .enable_slash_commands = true, |
4815 | 4831 | .extenders = query_extenders, |
4816 | 4832 | .delimiters = query_delimiters, |
4817 | 4833 | .word_break_characters = word_break_characters, |
|
0 commit comments