fix(cli): handle remaining input on EOF

This commit is contained in:
Konstantinos Artopoulos 2025-02-11 00:02:20 +02:00
parent 1da43266e9
commit 839e1ce3e8
No known key found for this signature in database
GPG key ID: 4F1E2C04377D9F60
2 changed files with 21 additions and 0 deletions

View file

@ -865,6 +865,26 @@ impl Limbo {
Ok(())
}
pub fn handle_remaining_input(&mut self) {
if self.input_buff.is_empty() {
return;
}
let buff = self.input_buff.clone();
let echo = self.opts.echo;
if echo {
let _ = self.writeln(&buff);
}
let conn = self.conn.clone();
let runner = conn.query_runner(buff.as_bytes());
for output in runner {
if let Err(e) = self.print_query_result(&buff, output) {
let _ = self.writeln(e.to_string());
}
}
self.reset_input();
}
}
fn get_writer(output: &str) -> Box<dyn Write> {

View file

@ -36,6 +36,7 @@ fn main() -> anyhow::Result<()> {
continue;
}
Err(ReadlineError::Eof) => {
app.handle_remaining_input();
let _ = app.close_conn();
break;
}