From 1616b02cb6c5c224cf6acfbf4d74d08ada968331 Mon Sep 17 00:00:00 2001 From: Erik Khamitov <e.khamitov@picodata.io> Date: Tue, 3 Dec 2024 12:24:38 +0300 Subject: [PATCH] fix: add missing delimiter for input history browsing in cli --- src/cli/console.rs | 5 +++- test/int/test_cli_ux.py | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/cli/console.rs b/src/cli/console.rs index 339f62af71..e60122567d 100644 --- a/src/cli/console.rs +++ b/src/cli/console.rs @@ -177,7 +177,10 @@ impl<T: Helper> Console<T> { fn update_history(&mut self, command: Command) -> Result<Option<Command>> { // do not save special commands if let Command::Expression(expression) = &command { - if let Err(e) = self.editor.add_history_entry(expression) { + if let Err(e) = self + .editor + .add_history_entry(expression.clone() + &self.delimiter.clone().unwrap_or_default()) + { println!("error while updating history: {e}"); } if let Err(e) = self.editor.save_history(&self.history_file_path) { diff --git a/test/int/test_cli_ux.py b/test/int/test_cli_ux.py index 92005f1dc3..004731b2c2 100644 --- a/test/int/test_cli_ux.py +++ b/test/int/test_cli_ux.py @@ -622,3 +622,64 @@ def test_picodata_tarantool(cluster: Cluster): result = f.read() assert result == "it worked!" + + +def test_command_history_with_delimiter(cluster: Cluster): + i1 = cluster.add_instance(wait_online=False) + i1.start() + i1.wait_online() + i1.create_user(with_name="andy", with_password="Testpa55") + i1.sql('GRANT CREATE TABLE TO "andy"', sudo=True) + + cli = pexpect.spawn( + command=i1.binary_path, + args=["connect", f"{i1.host}:{i1.port}", "-u", "andy"], + encoding="utf-8", + timeout=CLI_TIMEOUT, + ) + cli.logfile = sys.stdout + + cli.expect_exact("Enter password for andy: ") + cli.sendline("Testpa55") + + cli.expect_exact( + f'Connected to interactive console by address "{i1.host}:{i1.port}" under "andy" user' + ) + cli.expect_exact("type '\\help' for interactive help") + cli.expect_exact("picodata> ") + + # Set custom delimiter + cli.sendline("\\set delimiter ?123") + cli.expect_exact("Delimiter changed to '?123'") + + # Enter a command with the custom delimiter + cli.sendline("CREATE TABLE test_table (id INTEGER PRIMARY KEY)?123") + cli.expect_exact("1") + + # Press the up arrow key to access the command history + cli.sendline("\033[A") # \033[A is the escape sequence for the up arrow key + cli.expect_exact("CREATE TABLE test_table (id INTEGER PRIMARY KEY)?123") + + # Press the down arrow key to clean the input + cli.sendline("\033[B") # \033[B is the escape sequence for the down arrow key + cli.expect_exact("picodata> ") + + # Set delimiter back to ; + cli.sendline("\\set delimiter ;") + cli.expect_exact("Delimiter changed to ';'") + + # Set delimiter back to default + cli.sendline("\\set delimiter default") + cli.expect_exact("Delimiter changed to ';'") + + # Enter a command with the default delimiter + cli.sendline("DROP TABLE test_table;") + cli.expect_exact("1") + + # Press the up arrow key to access the command history + cli.sendline("\033[A") # \033[A is the escape sequence for the up arrow key + cli.expect_exact("DROP TABLE test_table;") + + # Press the down arrow key to clean the input + cli.sendline("\033[B") # \033[B is the escape sequence for the down arrow key + cli.expect_exact("picodata> ") -- GitLab