valkey/utils
Jason Elbaum 1f76bb17dd
Reimplement cli hints based on command arg docs (#10515)
Now that the command argument specs are available at runtime (#9656), this PR addresses
#8084 by implementing a complete solution for command-line hinting in `redis-cli`.

It correctly handles nearly every case in Redis's complex command argument definitions, including
`BLOCK` and `ONEOF` arguments, reordering of optional arguments, and repeated arguments
(even when followed by mandatory arguments). It also validates numerically-typed arguments.
It may not correctly handle all possible combinations of those, but overall it is quite robust.

Arguments are only matched after the space bar is typed, so partial word matching is not
supported - that proved to be more confusing than helpful. When the user's current input
cannot be matched against the argument specs, hinting is disabled.

Partial support has been implemented for legacy (pre-7.0) servers that do not support
`COMMAND DOCS`, by falling back to a statically-compiled command argument table.
On startup, if the server does not support `COMMAND DOCS`, `redis-cli` will now issue
an `INFO SERVER` command to retrieve the server version (unless `HELLO` has already
been sent, in which case the server version will be extracted from the reply to `HELLO`).
The server version will be used to filter the commands and arguments in the command table,
removing those not supported by that version of the server. However, the static table only
includes core Redis commands, so with a legacy server hinting will not be supported for
module commands. The auto generated help.h and the scripts that generates it are gone.

Command and argument tables for the server and CLI use different structs, due primarily
to the need to support different runtime data. In order to generate code for both, macros
have been added to `commands.def` (previously `commands.c`) to make it possible to
configure the code generation differently for different use cases (one linked with redis-server,
and one with redis-cli).

Also adding a basic testing framework for the command hints based on new (undocumented)
command line options to `redis-cli`: `--test_hint 'INPUT'` prints out the command-line hint for
a given input string, and `--test_hint_file <filename>` runs a suite of test cases for the hinting
mechanism. The test suite is in `tests/assets/test_cli_hint_suite.txt`, and it is run from
`tests/integration/redis-cli.tcl`.

Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
2023-03-30 19:03:56 +03:00
..
create-cluster Add appendonlydir-* in utils/create-cluster/.gitignore (#10471) 2022-03-26 09:53:10 +03:00
graphs/commits-over-time
hyperloglog
lru Outdated comments, replace COUNTER_INIT_VAL with LFU_INIT_VAL, fix typo (#10888) 2022-06-21 08:14:31 +03:00
releasetools Fixes to release scripts (#7547) 2020-07-21 14:07:06 +03:00
req-res-validator Add reply_schema to command json files (internal for now) (#10273) 2023-03-11 10:14:16 +02:00
srandmember Fixed some typos, add a spell check ci and others minor fix (#8890) 2021-06-10 15:39:33 +03:00
build-static-symbols.tcl
cluster_fail_time.tcl
corrupt_rdb.c
gen-test-certs.sh Typo fix in gen-test-certs.sh (#8841) 2021-04-25 10:11:16 +03:00
generate-command-code.py Reimplement cli hints based on command arg docs (#10515) 2023-03-30 19:03:56 +03:00
generate-commands-json.py Fix some commands key spec in json files (#10779) 2022-05-27 12:58:00 +03:00
generate-module-api-doc.rb Module API docs corrections (#10890) 2022-06-21 17:00:24 +03:00
install_server.sh
redis_init_script
redis_init_script.tpl
redis-copy.rb
redis-sha1.rb Fixed some typos, add a spell check ci and others minor fix (#8890) 2021-06-10 15:39:33 +03:00
reply_schema_linter.js Add reply_schema to command json files (internal for now) (#10273) 2023-03-11 10:14:16 +02:00
req-res-log-validator.py Add COMMAND COUNT test to cover reply-schemas-validator test (#11971) 2023-03-26 08:39:04 +03:00
speed-regression.tcl Fixed some typos, add a spell check ci and others minor fix (#8890) 2021-06-10 15:39:33 +03:00
systemd-redis_multiple_servers@.service
systemd-redis_server.service Start redis after network is online (#7639) 2020-08-11 12:30:32 +03:00
tracking_collisions.c Fixed some typos, add a spell check ci and others minor fix (#8890) 2021-06-10 15:39:33 +03:00
whatisdoing.sh Changes http to https in texts (#8495) 2021-03-10 19:11:16 +02:00